From 11c780f117f8970eb025ef1ad3679dc5c02e9eae Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Wed, 22 Jan 2025 10:21:41 +0100 Subject: [PATCH] Block `Body` hook --- core/types/block.go | 5 +++-- core/types/block.libevm.go | 11 +++++++++++ core/types/block.libevm_test.go | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 64007c3a93b8..ad4dfbe7cb71 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -339,9 +339,10 @@ func (b *Block) encodeRLP(w io.Writer) error { }) } -// Body returns the non-header content of the block. +// EthBody returns the non-header content of an Ethereum block. // Note the returned data is not an independent copy. -func (b *Block) Body() *Body { +// Use [Block.Body] instead if your block has any registered extra. +func (b *Block) EthBody() *Body { return &Body{ Transactions: b.transactions, Uncles: b.uncles, diff --git a/core/types/block.libevm.go b/core/types/block.libevm.go index e287839b596e..bf39f84ed698 100644 --- a/core/types/block.libevm.go +++ b/core/types/block.libevm.go @@ -187,6 +187,7 @@ func (*NOOPBodyHooks) DecodeRLP(b *Body, s *rlp.Stream) error { type BlockHooks interface { EncodeRLP(*Block, io.Writer) error DecodeRLP(*Block, *rlp.Stream) error + Body(*Block) *Body } // hooks returns the Block's registered BlockHooks, if any, otherwise a @@ -243,6 +244,10 @@ func (*NOOPBlockHooks) DecodeRLP(b *Block, s *rlp.Stream) error { return b.decodeRLP(s) } +func (*NOOPBlockHooks) Body(b *Block) *Body { + return b.EthBody() +} + func (b *Block) SetHeader(header *Header) { b.header = header } @@ -254,3 +259,9 @@ func (b *Block) SetUncles(uncles []*Header) { func (b *Block) SetTransactions(transactions Transactions) { b.transactions = transactions } + +// Body returns the non-header content of the block. +// Note the returned data is not an independent copy. +func (b *Block) Body() *Body { + return b.hooks().Body(b) +} diff --git a/core/types/block.libevm_test.go b/core/types/block.libevm_test.go index 06cd0cef5416..6999a91cb563 100644 --- a/core/types/block.libevm_test.go +++ b/core/types/block.libevm_test.go @@ -133,6 +133,10 @@ func (bh *stubBlockHooks) DecodeRLP(b *Block, s *rlp.Stream) error { return bh.errDecode } +func (bh *stubBlockHooks) Body(b *Block) *Body { + return b.EthBody() +} + func TestHeaderHooks(t *testing.T) { TestOnlyClearRegisteredExtras() defer TestOnlyClearRegisteredExtras()