From af596f7ac2bb571837a978f60adf68f9d75c3162 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 5 Dec 2025 16:29:15 -0500 Subject: [PATCH 1/2] Replace full blocks with headers in hook.Points --- hook/hook.go | 15 +++++++++++---- hook/hookstest/stub.go | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hook/hook.go b/hook/hook.go index aca21d89..d392bea8 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -23,9 +23,16 @@ import ( // Points define user-injected hook points. type Points interface { - GasTarget(parent *types.Block) gas.Gas - SubSecondBlockTime(*types.Block) gas.Gas + GasTarget(parent *types.Header) gas.Gas + // SubSecondBlockTime returns the sub-second portion of the block time based + // on the provided gas rate. + // + // For example, if the block timestamp is 10.75 seconds and the gas rate is + // 100 gas/second, then this method should return 75 gas. + SubSecondBlockTime(*types.Header) gas.Gas + // BeforeBlock is called immediately prior to executing the block. BeforeBlock(params.Rules, *state.StateDB, *types.Block) error + // AfterBlock is called immediately after executing the block. AfterBlock(*state.StateDB, *types.Block, types.Receipts) } @@ -34,9 +41,9 @@ type Points interface { func BeforeBlock(pts Points, rules params.Rules, sdb *state.StateDB, b *blocks.Block, clock *gastime.Time) error { clock.FastForwardTo( b.BuildTime(), - pts.SubSecondBlockTime(b.EthBlock()), + pts.SubSecondBlockTime(b.Header()), ) - target := pts.GasTarget(b.ParentBlock().EthBlock()) + target := pts.GasTarget(b.ParentBlock().Header()) if err := clock.SetTarget(target); err != nil { return fmt.Errorf("%T.SetTarget() before block: %w", clock, err) } diff --git a/hook/hookstest/stub.go b/hook/hookstest/stub.go index 611c70f7..668e66ce 100644 --- a/hook/hookstest/stub.go +++ b/hook/hookstest/stub.go @@ -21,12 +21,12 @@ type Stub struct { var _ hook.Points = (*Stub)(nil) // GasTarget ignores its argument and always returns [Stub.Target]. -func (s *Stub) GasTarget(parent *types.Block) gas.Gas { +func (s *Stub) GasTarget(*types.Header) gas.Gas { return s.Target } // SubSecondBlockTime time ignores its argument and always returns 0. -func (*Stub) SubSecondBlockTime(*types.Block) gas.Gas { +func (*Stub) SubSecondBlockTime(*types.Header) gas.Gas { return 0 } From 5b555f9fc5eca8d65a189c04de0ab4455c464aac Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 8 Dec 2025 10:36:46 -0500 Subject: [PATCH 2/2] Address comments --- hook/hook.go | 14 +++++++------- hook/hookstest/stub.go | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hook/hook.go b/hook/hook.go index d392bea8..3db23486 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -25,15 +25,15 @@ import ( type Points interface { GasTarget(parent *types.Header) gas.Gas // SubSecondBlockTime returns the sub-second portion of the block time based - // on the provided gas rate. + // on the gas rate. // // For example, if the block timestamp is 10.75 seconds and the gas rate is // 100 gas/second, then this method should return 75 gas. SubSecondBlockTime(*types.Header) gas.Gas - // BeforeBlock is called immediately prior to executing the block. - BeforeBlock(params.Rules, *state.StateDB, *types.Block) error - // AfterBlock is called immediately after executing the block. - AfterBlock(*state.StateDB, *types.Block, types.Receipts) + // BeforeExecutingBlock is called immediately prior to executing the block. + BeforeExecutingBlock(params.Rules, *state.StateDB, *types.Block) error + // AfterExecutingBlock is called immediately after executing the block. + AfterExecutingBlock(*state.StateDB, *types.Block, types.Receipts) } // BeforeBlock is intended to be called before processing a block, with the gas @@ -47,14 +47,14 @@ func BeforeBlock(pts Points, rules params.Rules, sdb *state.StateDB, b *blocks.B if err := clock.SetTarget(target); err != nil { return fmt.Errorf("%T.SetTarget() before block: %w", clock, err) } - return pts.BeforeBlock(rules, sdb, b.EthBlock()) + return pts.BeforeExecutingBlock(rules, sdb, b.EthBlock()) } // AfterBlock is intended to be called after processing a block, with the gas // sourced from [types.Block.GasUsed] or equivalent. func AfterBlock(pts Points, sdb *state.StateDB, b *types.Block, clock *gastime.Time, used gas.Gas, rs types.Receipts) { clock.Tick(used) - pts.AfterBlock(sdb, b, rs) + pts.AfterExecutingBlock(sdb, b, rs) } // MinimumGasConsumption MUST be used as the implementation for the respective diff --git a/hook/hookstest/stub.go b/hook/hookstest/stub.go index 668e66ce..296830b0 100644 --- a/hook/hookstest/stub.go +++ b/hook/hookstest/stub.go @@ -30,10 +30,10 @@ func (*Stub) SubSecondBlockTime(*types.Header) gas.Gas { return 0 } -// BeforeBlock is a no-op that always returns nil. -func (*Stub) BeforeBlock(params.Rules, *state.StateDB, *types.Block) error { +// BeforeExecutingBlock is a no-op that always returns nil. +func (*Stub) BeforeExecutingBlock(params.Rules, *state.StateDB, *types.Block) error { return nil } -// AfterBlock is a no-op. -func (*Stub) AfterBlock(*state.StateDB, *types.Block, types.Receipts) {} +// AfterExecutingBlock is a no-op. +func (*Stub) AfterExecutingBlock(*state.StateDB, *types.Block, types.Receipts) {}