Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 3922e9e

Browse files
committed
feat(core/types): Block hooks for RLP encoding
1 parent f133755 commit 3922e9e

32 files changed

+238
-400
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) {
21792179
if out, err := replacer.CombinedOutput(); err != nil {
21802180
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
21812181
}
2182-
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/libevm@v0.0.0", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/libevm@v0.0.0-20250113230013-d10c4a3d1ff2")
2182+
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/libevm@v0.0.0", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/libevm@v0.0.0-20250121164716-463996dc7ec1")
21832183
replacer.Dir = pkg
21842184
if out, err := replacer.CombinedOutput(); err != nil {
21852185
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)

consensus/dummy/consensus.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
404404
if extDataGasUsed == nil {
405405
extDataGasUsed = new(big.Int).Set(common.Big0)
406406
}
407-
if blockExtDataGasUsed := block.ExtDataGasUsed(); blockExtDataGasUsed == nil || !blockExtDataGasUsed.IsUint64() || blockExtDataGasUsed.Cmp(extDataGasUsed) != 0 {
407+
if blockExtDataGasUsed := types.BlockExtDataGasUsed(block); blockExtDataGasUsed == nil || !blockExtDataGasUsed.IsUint64() || blockExtDataGasUsed.Cmp(extDataGasUsed) != 0 {
408408
return fmt.Errorf("invalid extDataGasUsed: have %d, want %d", blockExtDataGasUsed, extDataGasUsed)
409409
}
410410
blockGasCostStep := ApricotPhase4BlockGasCostStep
@@ -422,13 +422,13 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
422422
parent.Time, block.Time(),
423423
)
424424
// Verify the BlockGasCost set in the header matches the calculated value.
425-
if blockBlockGasCost := block.BlockGasCost(); blockBlockGasCost == nil || !blockBlockGasCost.IsUint64() || blockBlockGasCost.Cmp(blockGasCost) != 0 {
425+
if blockBlockGasCost := types.BlockGasCost(block); blockBlockGasCost == nil || !blockBlockGasCost.IsUint64() || blockBlockGasCost.Cmp(blockGasCost) != 0 {
426426
return fmt.Errorf("invalid blockGasCost: have %d, want %d", blockBlockGasCost, blockGasCost)
427427
}
428428
// Verify the block fee was paid.
429429
if err := eng.verifyBlockFee(
430430
block.BaseFee(),
431-
block.BlockGasCost(),
431+
types.BlockGasCost(block),
432432
block.Transactions(),
433433
receipts,
434434
contribution,

core/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func makeChainForBench(db ethdb.Database, genesis *Genesis, full bool, count uin
256256

257257
if full || n == 0 {
258258
block := types.NewBlockWithHeader(header)
259-
rawdb.WriteBody(db, hash, n, block.Body())
259+
rawdb.WriteBody(db, hash, n, types.BlockBody(block))
260260
rawdb.WriteReceipts(db, hash, n, nil)
261261
}
262262
}

core/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
13671367
"parentHash", block.ParentHash(),
13681368
"uncles", len(block.Uncles()), "txs", len(block.Transactions()), "gas", block.GasUsed(),
13691369
"elapsed", common.PrettyDuration(time.Since(start)),
1370-
"root", block.Root(), "baseFeePerGas", block.BaseFee(), "blockGasCost", block.BlockGasCost(),
1370+
"root", block.Root(), "baseFeePerGas", block.BaseFee(), "blockGasCost", types.BlockGasCost(block),
13711371
)
13721372

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

core/genesis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
246246
}
247247

248248
// Configure any stateful precompiles that should be enabled in the genesis.
249-
err = ApplyPrecompileActivations(g.Config, nil, types.NewBlockWithHeader(head), statedb)
249+
block := types.NewBlockWithHeader(head)
250+
err = ApplyPrecompileActivations(g.Config, nil, types.WrapWithTimestamp(block), statedb)
250251
if err != nil {
251252
panic(fmt.Sprintf("unable to configure precompiles in genesis block: %v", err))
252253
}

core/rawdb/accessors_chain.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,14 @@ 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).WithExtData(body.Version, body.ExtData)
525+
block := types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
526+
block = types.BlockWithExtData(block, body.Version, body.ExtData)
527+
return block
526528
}
527529

528530
// WriteBlock serializes a block into the database, header and body separately.
529531
func WriteBlock(db ethdb.KeyValueWriter, block *types.Block) {
530-
WriteBody(db, block.Hash(), block.NumberU64(), block.Body())
532+
WriteBody(db, block.Hash(), block.NumberU64(), types.BlockBody(block))
531533
WriteHeader(db, block.Header())
532534
}
533535

core/rawdb/accessors_chain_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestBlockStorage(t *testing.T) {
138138
if entry := ReadBody(db, block.Hash(), block.NumberU64()); entry == nil {
139139
t.Fatalf("Stored body not found")
140140
} else if types.DeriveSha(types.Transactions(entry.Transactions), newTestHasher()) != types.DeriveSha(block.Transactions(), newTestHasher()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
141-
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
141+
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, types.BlockBody(block))
142142
}
143143
// Delete the block and verify the execution
144144
DeleteBlock(db, block.Hash(), block.NumberU64())
@@ -170,15 +170,15 @@ func TestPartialBlockStorage(t *testing.T) {
170170
DeleteHeader(db, block.Hash(), block.NumberU64())
171171

172172
// Store a body and check that it's not recognized as a block
173-
WriteBody(db, block.Hash(), block.NumberU64(), block.Body())
173+
WriteBody(db, block.Hash(), block.NumberU64(), types.BlockBody(block))
174174
if entry := ReadBlock(db, block.Hash(), block.NumberU64()); entry != nil {
175175
t.Fatalf("Non existent block returned: %v", entry)
176176
}
177177
DeleteBody(db, block.Hash(), block.NumberU64())
178178

179179
// Store a header and a body separately and check reassembly
180180
WriteHeader(db, block.Header())
181-
WriteBody(db, block.Hash(), block.NumberU64(), block.Body())
181+
WriteBody(db, block.Hash(), block.NumberU64(), types.BlockBody(block))
182182

183183
if entry := ReadBlock(db, block.Hash(), block.NumberU64()); entry == nil {
184184
t.Fatalf("Stored block not found")

core/rlp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func BenchmarkHashing(b *testing.B) {
161161
)
162162
{
163163
block := getBlock(200, 2, 50)
164-
bodyRlp, _ = rlp.EncodeToBytes(block.Body())
164+
bodyRlp, _ = rlp.EncodeToBytes(types.BlockBody(block))
165165
blockRlp, _ = rlp.EncodeToBytes(block)
166166
}
167167
var got common.Hash

core/state_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state
8282
)
8383

8484
// Configure any upgrades that should go into effect during this block.
85-
err := ApplyUpgrades(p.config, &parent.Time, block, statedb)
85+
err := ApplyUpgrades(p.config, &parent.Time, types.WrapWithTimestamp(block), statedb)
8686
if err != nil {
8787
log.Error("failed to configure precompiles processing block", "hash", block.Hash(), "number", block.NumberU64(), "timestamp", block.Time(), "err", err)
8888
return nil, nil, 0, err

0 commit comments

Comments
 (0)