Skip to content

Commit a1f212a

Browse files
qdm12ARR4N
andcommitted
chore(core/types): remove block.go and import Block and Body from libevm
- `BlockGasCost` getter pure function - New import from libevm's `core/types`: `Block`, `Blocks`, `Body`, `CalcUncleHash`, `NewBlock` and `NewBlockWithHeader` - remove now unneeded `core/types/block.go` See original PR ava-labs/coreth#760 Signed-off-by: Quentin McGaw <[email protected]> Co-authored-by: Arran Schlosberg <[email protected]>
1 parent 5d6e078 commit a1f212a

File tree

11 files changed

+42
-304
lines changed

11 files changed

+42
-304
lines changed

cmd/evm/internal/t8ntool/block.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ func (i *bbInput) ToBlock() *types.Block {
166166
if i.Header.Difficulty != nil {
167167
header.Difficulty = i.Header.Difficulty
168168
}
169-
return types.NewBlockWithHeader(header).WithBody(i.Txs, i.Ommers)
169+
return types.NewBlockWithHeader(header).WithBody(types.Body{
170+
Transactions: i.Txs,
171+
Uncles: i.Ommers,
172+
})
170173
}
171174

172175
// SealBlock seals the given block using the configured engine.

consensus/dummy/consensus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
337337
return err
338338
}
339339
// Verify the BlockGasCost set in the header matches the expected value.
340-
blockGasCost := block.BlockGasCost()
340+
blockGasCost := types.BlockGasCost(block)
341341
expectedBlockGasCost := customheader.BlockGasCost(
342342
config,
343343
feeConfig,

core/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
14421442
"parentHash", block.ParentHash(),
14431443
"uncles", len(block.Uncles()), "txs", len(block.Transactions()), "gas", block.GasUsed(),
14441444
"elapsed", common.PrettyDuration(time.Since(start)),
1445-
"root", block.Root(), "baseFeePerGas", block.BaseFee(), "blockGasCost", block.BlockGasCost(),
1445+
"root", block.Root(), "baseFeePerGas", block.BaseFee(), "blockGasCost", types.BlockGasCost(block),
14461446
)
14471447

14481448
processedBlockGasUsedCounter.Inc(int64(block.GasUsed()))

core/rawdb/accessors_chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
522522
if body == nil {
523523
return nil
524524
}
525-
return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
525+
return types.NewBlockWithHeader(header).WithBody(*body)
526526
}
527527

528528
// WriteBlock serializes a block into the database, header and body separately.

core/types/block.go

Lines changed: 0 additions & 291 deletions
This file was deleted.

core/types/block_ext.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// (c) 2024, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package types
5+
6+
import (
7+
"math/big"
8+
)
9+
10+
func BlockGasCost(b *Block) *big.Int {
11+
cost := GetHeaderExtra(b.Header()).BlockGasCost
12+
if cost == nil {
13+
return nil
14+
}
15+
return new(big.Int).Set(cost)
16+
}

core/types/block_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestBlockEncoding(t *testing.T) {
6868
check("MixDigest", block.MixDigest(), common.HexToHash("0xbd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498"))
6969
check("Nonce", block.Nonce(), uint64(11617697748499542468))
7070
check("BaseFee", block.BaseFee(), (*big.Int)(nil))
71-
check("BlockGasCost", block.BlockGasCost(), (*big.Int)(nil))
71+
check("BlockGasCost", BlockGasCost(&block), (*big.Int)(nil))
7272

7373
check("Size", block.Size(), uint64(len(blockEnc)))
7474
check("BlockHash", block.Hash(), common.HexToHash("0x0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"))
@@ -109,7 +109,7 @@ func TestEIP1559BlockEncoding(t *testing.T) {
109109
check("Time", block.Time(), uint64(1426516743))
110110
check("Size", block.Size(), uint64(len(blockEnc)))
111111
check("BaseFee", block.BaseFee(), new(big.Int).SetUint64(1000000000))
112-
check("BlockGasCost", block.BlockGasCost(), (*big.Int)(nil))
112+
check("BlockGasCost", BlockGasCost(&block), (*big.Int)(nil))
113113

114114
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
115115
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))
@@ -173,7 +173,7 @@ func TestEIP2718BlockEncoding(t *testing.T) {
173173
check("Time", block.Time(), uint64(1426516743))
174174
check("Size", block.Size(), uint64(len(blockEnc)))
175175
check("BaseFee", block.BaseFee(), (*big.Int)(nil))
176-
check("BlockGasCost", block.BlockGasCost(), (*big.Int)(nil))
176+
check("BlockGasCost", BlockGasCost(&block), (*big.Int)(nil))
177177

178178
// Create legacy tx.
179179
to := common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87")
@@ -303,7 +303,7 @@ func TestSubnetEVMBlockEncoding(t *testing.T) {
303303
check("Time", block.Time(), uint64(1426516743))
304304
check("Size", block.Size(), uint64(len(blockEnc)))
305305
check("BaseFee", block.BaseFee(), big.NewInt(1_000_000_000))
306-
check("BlockGasCost", block.BlockGasCost(), big.NewInt(100_000))
306+
check("BlockGasCost", BlockGasCost(&block), big.NewInt(100_000))
307307

308308
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
309309
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))

0 commit comments

Comments
 (0)