Skip to content

Commit bd1aabe

Browse files
qdm12ARR4N
andauthored
chore(core/types): remove block.go and import Block and Body from libevm (#760)
- `BlockBodyExtra` extra payload defined for both `Block` and `Body` - hook `Copy` to be used in `Block` methods `Body`, `WithSeal`, `WithBody` and `WithWithdrawals` - hooks `BlockRLPFieldsForEncoding` and `BlockRLPFieldsForDecoding` for RLP codec of `Block` - hooks `BodyRLPFieldsForEncoding` and `BodyRLPFieldsForDecoding` for RLP codec of `Body` - `SetBlockExtra` to set an extra payload `BlockBodyExtra` on a `Block` - `SetBodyExtra` to set an extra payload `BlockBodyExtra` on a `Body` - Block getter pure functions for extra fields: `BlockExtDataGasUsed`, `BlockGasCost`, `BlockExtData`, `BlockVersion`, `BlockExtDataGasUsed`, `BlockGasCost` - New import from libevm's `core/types`: `Block`, `Blocks`, `Body`, `CalcUncleHash`, `NewBlock` and `NewBlockWithHeader` - remove now unneeded `core/types/block.go` - add test dependency github.com/google/go-cmp v0.7.0 Signed-off-by: Quentin McGaw <[email protected]> Co-authored-by: Arran Schlosberg <[email protected]>
1 parent 44a2447 commit bd1aabe

File tree

20 files changed

+593
-391
lines changed

20 files changed

+593
-391
lines changed

consensus/dummy/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,12 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
377377
if extDataGasUsed == nil {
378378
extDataGasUsed = new(big.Int).Set(common.Big0)
379379
}
380-
if blockExtDataGasUsed := block.ExtDataGasUsed(); blockExtDataGasUsed == nil || !blockExtDataGasUsed.IsUint64() || blockExtDataGasUsed.Cmp(extDataGasUsed) != 0 {
380+
if blockExtDataGasUsed := types.BlockExtDataGasUsed(block); blockExtDataGasUsed == nil || !blockExtDataGasUsed.IsUint64() || blockExtDataGasUsed.Cmp(extDataGasUsed) != 0 {
381381
return fmt.Errorf("invalid extDataGasUsed: have %d, want %d", blockExtDataGasUsed, extDataGasUsed)
382382
}
383383

384384
// Verify the BlockGasCost set in the header matches the expected value.
385-
blockGasCost := block.BlockGasCost()
385+
blockGasCost := types.BlockGasCost(block)
386386
expectedBlockGasCost := customheader.BlockGasCost(
387387
configExtra,
388388
parent,

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/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).WithExtData(body.Version, body.ExtData)
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 & 301 deletions
This file was deleted.

0 commit comments

Comments
 (0)