Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): use fixed pre-state for throwaway blocks (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Dec 16, 2022
1 parent 3e15287 commit 50ff10c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
55 changes: 29 additions & 26 deletions driver/block_inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,29 @@ func (s *L2ChainSyncer) onBlockProposed(
"BlockID", event.Id,
)

// Get the original TaikoL1.proposeBlock transaction.
tx, err := s.rpc.L1.TransactionInBlock(ctx, event.Raw.BlockHash, event.Raw.TxIndex)
if err != nil {
return fmt.Errorf("failed to fetch original TaikoL1.proposeBlock transaction: %w", err)
}

// Check whether the transactions list is valid.
txListBytes, hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.Id, tx.Data())
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}

log.Info(
"Validate transactions list",
"blockID", event.Id,
"hint", hint,
"invalidTxIndex", invalidTxIndex,
)

// Fetch the L2 parent block.
var (
parent *types.Header
err error
parent *types.Header
throwaway = hint != txListValidator.HintOK
)
if s.syncProgressTracker.Triggered() {
// Already synced through beacon sync, just skip this event.
Expand All @@ -53,7 +72,12 @@ func (s *L2ChainSyncer) onBlockProposed(

parent, err = s.rpc.L2.HeaderByHash(ctx, s.syncProgressTracker.LastSyncedVerifiedBlockHash())
} else {
parent, err = s.rpc.L2ParentByBlockId(ctx, event.Id)
if throwaway {
// NOTE: for throwaway blocks, use genesis block as the pre-state now, which may change in future.
parent, err = s.rpc.L2.HeaderByNumber(s.ctx, common.Big0)
} else {
parent, err = s.rpc.L2ParentByBlockId(ctx, event.Id)
}
}

if err != nil {
Expand All @@ -62,34 +86,12 @@ func (s *L2ChainSyncer) onBlockProposed(

log.Debug("Parent block", "height", parent.Number, "hash", parent.Hash())

tx, err := s.rpc.L1.TransactionInBlock(
ctx,
event.Raw.BlockHash,
event.Raw.TxIndex,
)
if err != nil {
return fmt.Errorf("failed to fetch original TaikoL1.proposeBlock transaction: %w", err)
}

// Check whether the transactions list is valid.
txListBytes, hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.Id, tx.Data())
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}

log.Info(
"Validate transactions list",
"blockID", event.Id,
"hint", hint,
"invalidTxIndex", invalidTxIndex,
)

l1Origin := &rawdb.L1Origin{
BlockID: event.Id,
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
L1BlockHeight: new(big.Int).SetUint64(event.Raw.BlockNumber),
L1BlockHash: event.Raw.BlockHash,
Throwaway: hint != txListValidator.HintOK,
Throwaway: throwaway,
}

if event.Meta.Timestamp > uint64(time.Now().Unix()) {
Expand Down Expand Up @@ -361,6 +363,7 @@ func (s *L2ChainSyncer) getInvalidateBlockTxOpts(ctx context.Context, height *bi
return nil, err
}

opts.GasPrice = common.Big0
opts.Nonce = new(big.Int).SetUint64(nonce)
opts.NoSend = true

Expand Down
2 changes: 1 addition & 1 deletion version/verison.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package version

// Version info.
var (
Version = "0.1.9"
Version = "0.1.10"
Meta = "dev"
)

Expand Down

0 comments on commit 50ff10c

Please sign in to comment.