@@ -31,123 +31,12 @@ import (
3131 "encoding/binary"
3232 "io"
3333 "math/big"
34- "reflect"
3534 "sync/atomic"
3635
3736 "github.com/ava-labs/libevm/common"
38- "github.com/ava-labs/libevm/common/hexutil"
3937 "github.com/ava-labs/libevm/rlp"
4038)
4139
42- // A BlockNonce is a 64-bit hash which proves (combined with the
43- // mix-hash) that a sufficient amount of computation has been carried
44- // out on a block.
45- type BlockNonce [8 ]byte
46-
47- // EncodeNonce converts the given integer to a block nonce.
48- func EncodeNonce (i uint64 ) BlockNonce {
49- var n BlockNonce
50- binary .BigEndian .PutUint64 (n [:], i )
51- return n
52- }
53-
54- // Uint64 returns the integer value of a block nonce.
55- func (n BlockNonce ) Uint64 () uint64 {
56- return binary .BigEndian .Uint64 (n [:])
57- }
58-
59- // MarshalText encodes n as a hex string with 0x prefix.
60- func (n BlockNonce ) MarshalText () ([]byte , error ) {
61- return hexutil .Bytes (n [:]).MarshalText ()
62- }
63-
64- // UnmarshalText implements encoding.TextUnmarshaler.
65- func (n * BlockNonce ) UnmarshalText (input []byte ) error {
66- return hexutil .UnmarshalFixedText ("BlockNonce" , input , n [:])
67- }
68-
69- //go:generate go run github.com/fjl/gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
70- //go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type Header -out gen_header_rlp.go
71-
72- // Header represents a block header in the Ethereum blockchain.
73- type Header struct {
74- ParentHash common.Hash `json:"parentHash" gencodec:"required"`
75- UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
76- Coinbase common.Address `json:"miner" gencodec:"required"`
77- Root common.Hash `json:"stateRoot" gencodec:"required"`
78- TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
79- ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
80- Bloom Bloom `json:"logsBloom" gencodec:"required"`
81- Difficulty * big.Int `json:"difficulty" gencodec:"required"`
82- Number * big.Int `json:"number" gencodec:"required"`
83- GasLimit uint64 `json:"gasLimit" gencodec:"required"`
84- GasUsed uint64 `json:"gasUsed" gencodec:"required"`
85- Time uint64 `json:"timestamp" gencodec:"required"`
86- Extra []byte `json:"extraData" gencodec:"required"`
87- MixDigest common.Hash `json:"mixHash"`
88- Nonce BlockNonce `json:"nonce"`
89-
90- // BaseFee was added by EIP-1559 and is ignored in legacy headers.
91- BaseFee * big.Int `json:"baseFeePerGas" rlp:"optional"`
92-
93- // BlockGasCost was added by SubnetEVM and is ignored in legacy
94- // headers.
95- BlockGasCost * big.Int `json:"blockGasCost" rlp:"optional"`
96-
97- // BlobGasUsed was added by EIP-4844 and is ignored in legacy headers.
98- BlobGasUsed * uint64 `json:"blobGasUsed" rlp:"optional"`
99-
100- // ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers.
101- ExcessBlobGas * uint64 `json:"excessBlobGas" rlp:"optional"`
102-
103- // ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers.
104- ParentBeaconRoot * common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
105- }
106-
107- // field type overrides for gencodec
108- type headerMarshaling struct {
109- Difficulty * hexutil.Big
110- Number * hexutil.Big
111- GasLimit hexutil.Uint64
112- GasUsed hexutil.Uint64
113- Time hexutil.Uint64
114- Extra hexutil.Bytes
115- BaseFee * hexutil.Big
116- BlockGasCost * hexutil.Big
117- Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
118- BlobGasUsed * hexutil.Uint64
119- ExcessBlobGas * hexutil.Uint64
120- }
121-
122- // Hash returns the block hash of the header, which is simply the keccak256 hash of its
123- // RLP encoding.
124- func (h * Header ) Hash () common.Hash {
125- return rlpHash (h )
126- }
127-
128- var headerSize = common .StorageSize (reflect .TypeOf (Header {}).Size ())
129-
130- // Size returns the approximate memory used by all internal contents. It is used
131- // to approximate and limit the memory consumption of various caches.
132- func (h * Header ) Size () common.StorageSize {
133- var baseFeeBits int
134- if h .BaseFee != nil {
135- baseFeeBits = h .BaseFee .BitLen ()
136- }
137- return headerSize + common .StorageSize (len (h .Extra )+ (h .Difficulty .BitLen ()+ h .Number .BitLen ()+ baseFeeBits )/ 8 )
138- }
139-
140- // EmptyBody returns true if there is no additional 'body' to complete the header
141- // that is: no transactions and no uncles.
142- func (h * Header ) EmptyBody () bool {
143- return h .TxHash == EmptyTxsHash && h .UncleHash == EmptyUncleHash
144- }
145-
146- // EmptyReceipts returns true if there are no receipts for this header/block.
147- func (h * Header ) EmptyReceipts () bool {
148- return h .ReceiptHash == EmptyReceiptsHash
149- }
150-
15140// Body is a simple (mutable, non-safe) data container for storing and moving
15241// a block's data contents (transactions and uncles) together.
15342type Body struct {
@@ -232,6 +121,10 @@ func NewBlock(
232121// CopyHeader creates a deep copy of a block header.
233122func CopyHeader (h * Header ) * Header {
234123 cpy := * h
124+ hExtra := GetHeaderExtra (h )
125+ cpyExtra := & HeaderExtra {}
126+ SetHeaderExtra (& cpy , cpyExtra )
127+
235128 if cpy .Difficulty = new (big.Int ); h .Difficulty != nil {
236129 cpy .Difficulty .Set (h .Difficulty )
237130 }
@@ -241,13 +134,17 @@ func CopyHeader(h *Header) *Header {
241134 if h .BaseFee != nil {
242135 cpy .BaseFee = new (big.Int ).Set (h .BaseFee )
243136 }
244- if h .BlockGasCost != nil {
245- cpy .BlockGasCost = new (big.Int ).Set (h .BlockGasCost )
137+ if hExtra .BlockGasCost != nil {
138+ cpyExtra .BlockGasCost = new (big.Int ).Set (hExtra .BlockGasCost )
246139 }
247140 if len (h .Extra ) > 0 {
248141 cpy .Extra = make ([]byte , len (h .Extra ))
249142 copy (cpy .Extra , h .Extra )
250143 }
144+ if h .WithdrawalsHash != nil {
145+ cpy .WithdrawalsHash = new (common.Hash )
146+ * cpy .WithdrawalsHash = * h .WithdrawalsHash
147+ }
251148 if h .ExcessBlobGas != nil {
252149 cpy .ExcessBlobGas = new (uint64 )
253150 * cpy .ExcessBlobGas = * h .ExcessBlobGas
@@ -358,10 +255,11 @@ func (b *Block) BlobGasUsed() *uint64 {
358255}
359256
360257func (b * Block ) BlockGasCost () * big.Int {
361- if b .header .BlockGasCost == nil {
258+ cost := GetHeaderExtra (b .header ).BlockGasCost
259+ if cost == nil {
362260 return nil
363261 }
364- return new (big.Int ).Set (b . header . BlockGasCost )
262+ return new (big.Int ).Set (cost )
365263}
366264
367265// Size returns the true RLP encoded storage size of the block, either by encoding
0 commit comments