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

Commit

Permalink
Merge branch 'main' into add-blockbuilder-tip
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerLamTd authored Jan 31, 2024
2 parents 6acc22a + 229848d commit d99e91f
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 793 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dc46b27612398dd05e818d7439a8e872a227b603
5fa1331f8a03c3bd3769f273faf7c80339368054
73 changes: 1 addition & 72 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,9 @@ var (
TierGuardianID uint16 = 1000
ProtocolTiers = []uint16{TierOptimisticID, TierSgxID, TierSgxAndPseZkevmID, TierGuardianID}
AnchorTxGasLimit uint64 = 250_000
GoldenTouchPrivKey = "92954368afd3caa1f3ce3ead0069c1af414054aefe1ef9aeacc1bf426222ce38"
)

// BlockHeader represents an Ethereum block header.
type BlockHeader struct {
ParentHash [32]byte
OmmersHash [32]byte
Beneficiary common.Address
StateRoot [32]byte
TransactionsRoot [32]byte
ReceiptsRoot [32]byte
LogsBloom [8][32]byte
Difficulty *big.Int
Height *big.Int
GasLimit uint64
GasUsed uint64
Timestamp uint64
ExtraData []byte
MixHash [32]byte
Nonce uint64
BaseFeePerGas *big.Int
}

// HookCall should be same with TaikoData.HookCall
type HookCall struct {
Hook common.Address
Expand Down Expand Up @@ -88,58 +69,6 @@ type ZKEvmProof struct {
PointProof []byte
}

// FromGethHeader converts a GETH *types.Header to *BlockHeader.
func FromGethHeader(header *types.Header) *BlockHeader {
baseFeePerGas := header.BaseFee
if baseFeePerGas == nil {
baseFeePerGas = common.Big0
}
return &BlockHeader{
ParentHash: header.ParentHash,
OmmersHash: header.UncleHash,
Beneficiary: header.Coinbase,
StateRoot: header.Root,
TransactionsRoot: header.TxHash,
ReceiptsRoot: header.ReceiptHash,
LogsBloom: BloomToBytes(header.Bloom),
Difficulty: header.Difficulty,
Height: header.Number,
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Timestamp: header.Time,
ExtraData: header.Extra,
MixHash: header.MixDigest,
Nonce: header.Nonce.Uint64(),
BaseFeePerGas: baseFeePerGas,
}
}

// ToGethHeader converts a *BlockHeader to GETH *types.Header.
func ToGethHeader(header *BlockHeader) *types.Header {
baseFeePerGas := header.BaseFeePerGas
if baseFeePerGas.Cmp(common.Big0) == 0 {
baseFeePerGas = nil
}
return &types.Header{
ParentHash: header.ParentHash,
UncleHash: header.OmmersHash,
Coinbase: header.Beneficiary,
Root: header.StateRoot,
TxHash: header.TransactionsRoot,
ReceiptHash: header.ReceiptsRoot,
Bloom: BytesToBloom(header.LogsBloom),
Difficulty: header.Difficulty,
Number: header.Height,
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Time: header.Timestamp,
Extra: header.ExtraData,
MixDigest: header.MixHash,
Nonce: types.EncodeNonce(header.Nonce),
BaseFee: baseFeePerGas,
}
}

// ToExecutableData converts a GETH *types.Header to *engine.ExecutableData.
func ToExecutableData(header *types.Header) *engine.ExecutableData {
executableData := &engine.ExecutableData{
Expand Down
47 changes: 0 additions & 47 deletions bindings/encoding/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,53 +35,6 @@ var (
}
)

func TestFromGethHeader(t *testing.T) {
header := FromGethHeader(testHeader)

require.Equal(t, testHeader.ParentHash, common.BytesToHash(header.ParentHash[:]))
require.Equal(t, testHeader.UncleHash, common.BytesToHash(header.OmmersHash[:]))
require.Equal(t, testHeader.Coinbase, header.Beneficiary)
require.Equal(t, testHeader.Root, common.BytesToHash(header.StateRoot[:]))
require.Equal(t, testHeader.TxHash, common.BytesToHash(header.TransactionsRoot[:]))
require.Equal(t, testHeader.ReceiptHash, common.BytesToHash(header.ReceiptsRoot[:]))
require.Equal(t, BloomToBytes(testHeader.Bloom), header.LogsBloom)
require.Equal(t, testHeader.Difficulty, header.Difficulty)
require.Equal(t, testHeader.Number, header.Height)
require.Equal(t, testHeader.GasLimit, header.GasLimit)
require.Equal(t, testHeader.GasUsed, header.GasUsed)
require.Equal(t, testHeader.Time, header.Timestamp)
require.Equal(t, testHeader.Extra, header.ExtraData)
require.Equal(t, testHeader.MixDigest, common.BytesToHash(header.MixHash[:]))
require.Equal(t, testHeader.Nonce.Uint64(), header.Nonce)
require.Equal(t, testHeader.BaseFee.Uint64(), header.BaseFeePerGas.Uint64())
}

func TestFromToGethHeaderLegacyTx(t *testing.T) {
testHeader := testHeader // Copy the original struct
testHeader.BaseFee = nil
header := FromGethHeader(testHeader)

require.Equal(t, testHeader.ParentHash, common.BytesToHash(header.ParentHash[:]))
require.Equal(t, testHeader.UncleHash, common.BytesToHash(header.OmmersHash[:]))
require.Equal(t, testHeader.Coinbase, header.Beneficiary)
require.Equal(t, testHeader.Root, common.BytesToHash(header.StateRoot[:]))
require.Equal(t, testHeader.TxHash, common.BytesToHash(header.TransactionsRoot[:]))
require.Equal(t, testHeader.ReceiptHash, common.BytesToHash(header.ReceiptsRoot[:]))
require.Equal(t, BloomToBytes(testHeader.Bloom), header.LogsBloom)
require.Equal(t, testHeader.Difficulty, header.Difficulty)
require.Equal(t, testHeader.Number, header.Height)
require.Equal(t, testHeader.GasLimit, header.GasLimit)
require.Equal(t, testHeader.GasUsed, header.GasUsed)
require.Equal(t, testHeader.Time, header.Timestamp)
require.Equal(t, testHeader.Extra, header.ExtraData)
require.Equal(t, testHeader.MixDigest, common.BytesToHash(header.MixHash[:]))
require.Equal(t, testHeader.Nonce.Uint64(), header.Nonce)
require.Equal(t, new(big.Int).SetInt64(0).Uint64(), header.BaseFeePerGas.Uint64())

gethHeader := ToGethHeader(header)
require.Equal(t, testHeader, gethHeader)
}

func TestToExecutableData(t *testing.T) {
data := ToExecutableData(testHeader)
require.Equal(t, testHeader.ParentHash, data.ParentHash)
Expand Down
2 changes: 1 addition & 1 deletion bindings/gen_address_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d99e91f

Please sign in to comment.