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

Commit

Permalink
remove parentblockinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed May 16, 2023
1 parent 83fb81a commit 2d3c747
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
36 changes: 12 additions & 24 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ import (
txListValidator "github.com/taikoxyz/taiko-client/pkg/tx_list_validator"
)

// ParentBlockInfo is an abstraction between *types.Header and our code, to allow passing in
// a zero hash and other zero-value fields.
type ParentBlockInfo struct {
Hash common.Hash
Number *big.Int
GasUsed uint64
}

// Syncer responsible for letting the L2 execution engine catching up with protocol's latest
// pending block through deriving L1 calldata.
type Syncer struct {
Expand Down Expand Up @@ -196,11 +188,7 @@ func (s *Syncer) onBlockProposed(
payloadData, rpcError, payloadError := s.insertNewHead(
ctx,
event,
&ParentBlockInfo{
Hash: parent.Hash(),
Number: parent.Number,
GasUsed: parent.GasUsed,
},
parent,
s.state.GetHeadBlockID(),
txListBytes,
l1Origin,
Expand Down Expand Up @@ -346,15 +334,15 @@ func (s *Syncer) handleReorg(ctx context.Context, event *bindings.TaikoL1ClientB
func (s *Syncer) insertNewHead(
ctx context.Context,
event *bindings.TaikoL1ClientBlockProposed,
parentBlockInfo *ParentBlockInfo,
parent *types.Header,
headBlockID *big.Int,
txListBytes []byte,
l1Origin *rawdb.L1Origin,
) (*engine.ExecutableData, error, error) {
log.Debug(
"Try to insert a new L2 head block",
"parentNumber", parentBlockInfo.Number,
"parentHash", parentBlockInfo.Hash,
"parentNumber", parent.Number,
"parentHash", parent.Hash(),
"headBlockID", headBlockID,
"l1Origin", l1Origin,
)
Expand All @@ -368,17 +356,17 @@ func (s *Syncer) insertNewHead(
}
}

parentTimestamp, err := s.rpc.TaikoL2.ParentTimestamp(&bind.CallOpts{BlockNumber: parentBlockInfo.Number})
parentTimestamp, err := s.rpc.TaikoL2.ParentTimestamp(&bind.CallOpts{BlockNumber: parent.Number})
if err != nil {
return nil, nil, err
}

// Get L2 baseFee
baseFee, err := s.rpc.TaikoL2.GetBasefee(
&bind.CallOpts{BlockNumber: parentBlockInfo.Number},
&bind.CallOpts{BlockNumber: parent.Number},
uint32(event.Meta.Timestamp-parentTimestamp),
uint64(event.Meta.GasLimit+uint32(s.anchorConstructor.GasLimit())),
parentBlockInfo.GasUsed,
parent.GasUsed,
)
if err != nil {
return nil, nil, fmt.Errorf("failed to get L2 baseFee: %w", encoding.TryParsingCustomError(err))
Expand All @@ -389,7 +377,7 @@ func (s *Syncer) insertNewHead(
"baseFee", baseFee,
"timeSinceParent", uint32(event.Meta.Timestamp-parentTimestamp),
"gasLimit", uint64(event.Meta.GasLimit+uint32(s.anchorConstructor.GasLimit())),
"parentGasUsed", parentBlockInfo.GasUsed,
"parentGasUsed", parent.GasUsed,
)

// Get withdrawals
Expand All @@ -403,9 +391,9 @@ func (s *Syncer) insertNewHead(
ctx,
new(big.Int).SetUint64(event.Meta.L1Height),
event.Meta.L1Hash,
new(big.Int).Add(parentBlockInfo.Number, common.Big1),
new(big.Int).Add(parent.Number, common.Big1),
baseFee,
parentBlockInfo.GasUsed,
parent.GasUsed,
)
if err != nil {
return nil, nil, fmt.Errorf("failed to create TaikoL2.anchor transaction: %w", err)
Expand All @@ -421,7 +409,7 @@ func (s *Syncer) insertNewHead(
payload, rpcErr, payloadErr := s.createExecutionPayloads(
ctx,
event,
parentBlockInfo.Hash,
parent.Hash(),
l1Origin,
headBlockID,
txListBytes,
Expand All @@ -433,7 +421,7 @@ func (s *Syncer) insertNewHead(
return nil, rpcErr, payloadErr
}

fc := &engine.ForkchoiceStateV1{HeadBlockHash: parentBlockInfo.Hash}
fc := &engine.ForkchoiceStateV1{HeadBlockHash: parent.Hash()}

// Update the fork choice
fc.HeadBlockHash = payload.BlockHash
Expand Down
6 changes: 1 addition & 5 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
Timestamp: uint64(time.Now().Unix()),
},
},
&ParentBlockInfo{
Hash: parent.Hash(),
Number: parent.Number,
GasUsed: parent.GasUsed,
},
parent,
common.Big2,
[]byte{},
&rawdb.L1Origin{
Expand Down

0 comments on commit 2d3c747

Please sign in to comment.