Skip to content

Commit 4ed3eb8

Browse files
committed
consensus/misc/eip4844: use head's target blobs, not parent
1 parent 59d2eec commit 4ed3eb8

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
194194
ExcessBlobGas: pre.Env.ParentExcessBlobGas,
195195
BlobGasUsed: pre.Env.ParentBlobGasUsed,
196196
}
197-
excessBlobGas = eip4844.CalcExcessBlobGas(chainConfig, parent)
198197
header := &types.Header{
199198
Time: pre.Env.Timestamp,
200199
ExcessBlobGas: &excessBlobGas,
201200
}
201+
excessBlobGas = eip4844.CalcExcessBlobGas(chainConfig, parent, header)
202202
vmContext.BlobBaseFee = eip4844.CalcBlobFee(chainConfig, header)
203203
}
204204
}

consensus/misc/eip4844/eip4844.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func VerifyEIP4844Header(config *params.ChainConfig, parent, header *types.Heade
5050
return fmt.Errorf("blob gas used %d not a multiple of blob gas per blob %d", header.BlobGasUsed, params.BlobTxBlobGasPerBlob)
5151
}
5252
// Verify the excessBlobGas is correct based on the parent header
53-
expectedExcessBlobGas := CalcExcessBlobGas(config, parent)
53+
expectedExcessBlobGas := CalcExcessBlobGas(config, parent, header)
5454
if *header.ExcessBlobGas != expectedExcessBlobGas {
5555
return fmt.Errorf("invalid excessBlobGas: have %d, want %d", *header.ExcessBlobGas, expectedExcessBlobGas)
5656
}
@@ -59,9 +59,9 @@ func VerifyEIP4844Header(config *params.ChainConfig, parent, header *types.Heade
5959

6060
// CalcExcessBlobGas calculates the excess blob gas after applying the set of
6161
// blobs on top of the excess blob gas.
62-
func CalcExcessBlobGas(config *params.ChainConfig, parent *types.Header) uint64 {
62+
func CalcExcessBlobGas(config *params.ChainConfig, parent, header *types.Header) uint64 {
6363
var (
64-
targetGas = uint64(targetBlobsPerBlock(config, parent.Time)) * params.BlobTxBlobGasPerBlob
64+
targetGas = uint64(targetBlobsPerBlock(config, header.Time)) * params.BlobTxBlobGasPerBlob
6565
parentExcessBlobGas uint64
6666
parentBlobGasUsed uint64
6767
)

consensus/misc/eip4844/eip4844_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ func TestCalcExcessBlobGas(t *testing.T) {
5757
}
5858
for i, tt := range tests {
5959
blobGasUsed := uint64(tt.blobs) * params.BlobTxBlobGasPerBlob
60+
head := &types.Header{
61+
Time: *config.CancunTime,
62+
}
6063
parent := &types.Header{
61-
Time: *config.CancunTime,
64+
Time: *config.CancunTime + 12,
6265
ExcessBlobGas: &tt.excess,
6366
BlobGasUsed: &blobGasUsed,
6467
}
65-
result := CalcExcessBlobGas(config, parent)
68+
result := CalcExcessBlobGas(config, parent, head)
6669
if result != tt.want {
6770
t.Errorf("test %d: excess blob gas mismatch: have %v, want %v", i, result, tt.want)
6871
}

core/chain_makers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
600600
}
601601
}
602602
if cm.config.IsCancun(header.Number, header.Time) {
603-
excessBlobGas := eip4844.CalcExcessBlobGas(cm.config, parent.Header())
603+
excessBlobGas := eip4844.CalcExcessBlobGas(cm.config, parent.Header(), header)
604604
header.ExcessBlobGas = &excessBlobGas
605605
header.BlobGasUsed = new(uint64)
606606
header.ParentBeaconRoot = new(common.Hash)

core/state_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
407407
}
408408
header.Root = common.BytesToHash(hasher.Sum(nil))
409409
if config.IsCancun(header.Number, header.Time) {
410-
excess := eip4844.CalcExcessBlobGas(config, parent.Header())
410+
excess := eip4844.CalcExcessBlobGas(config, parent.Header(), header)
411411
used := uint64(nBlobs * params.BlobTxBlobGasPerBlob)
412412
header.ExcessBlobGas = &excess
413413
header.BlobGasUsed = &used

eth/gasprice/feehistory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
9797
// Fill in blob base fee and next blob base fee.
9898
if excessBlobGas := bf.header.ExcessBlobGas; excessBlobGas != nil {
9999
bf.results.blobBaseFee = eip4844.CalcBlobFee(config, bf.header)
100-
excess := eip4844.CalcExcessBlobGas(config, bf.header)
100+
excess := eip4844.CalcExcessBlobGas(config, bf.header, bf.header)
101101
next := &types.Header{Number: bf.header.Number, Time: bf.header.Time, ExcessBlobGas: &excess}
102102
bf.results.nextBlobBaseFee = eip4844.CalcBlobFee(config, next)
103103
} else {

eth/tracers/internal/tracetest/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
5454
}
5555

5656
if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil {
57-
excess := eip4844.CalcExcessBlobGas(genesis.Config, genesis.ToBlock().Header())
57+
excess := eip4844.CalcExcessBlobGas(genesis.Config, genesis.ToBlock().Header(), genesis.ToBlock().Header())
5858
header := &types.Header{ExcessBlobGas: &excess, Number: genesis.Config.LondonBlock, Time: *genesis.Config.CancunTime}
5959
context.BlobBaseFee = eip4844.CalcBlobFee(genesis.Config, header)
6060
}

internal/ethapi/simulate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
159159
if sim.chainConfig.IsCancun(header.Number, header.Time) {
160160
var excess uint64
161161
if sim.chainConfig.IsCancun(parent.Number, parent.Time) {
162-
excess = eip4844.CalcExcessBlobGas(sim.chainConfig, parent)
162+
excess = eip4844.CalcExcessBlobGas(sim.chainConfig, parent, header)
163163
}
164164
header.ExcessBlobGas = &excess
165165
}

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (miner *Miner) prepareWork(genParams *generateParams, witness bool) (*envir
210210
if miner.chainConfig.IsCancun(header.Number, header.Time) {
211211
var excessBlobGas uint64
212212
if miner.chainConfig.IsCancun(parent.Number, parent.Time) {
213-
excessBlobGas = eip4844.CalcExcessBlobGas(miner.chainConfig, parent)
213+
excessBlobGas = eip4844.CalcExcessBlobGas(miner.chainConfig, parent, header)
214214
}
215215
header.BlobGasUsed = new(uint64)
216216
header.ExcessBlobGas = &excessBlobGas

0 commit comments

Comments
 (0)