Skip to content

Commit cf054c0

Browse files
committed
add BlockTime to chain config
1 parent 38ad2ad commit cf054c0

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserve txpool.Addres
415415
p.recheck(addr, nil)
416416
}
417417
var (
418-
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head, p.head.Time+1))
418+
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head, p.chain.Config().NextBlockTime(p.head.Time)))
419419
blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice)
420420
)
421421
if p.head.ExcessBlobGas != nil {
@@ -835,7 +835,7 @@ func (p *BlobPool) Reset(oldHead, newHead *types.Header) {
835835
}
836836
// Reset the price heap for the new set of basefee/blobfee pairs
837837
var (
838-
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), newHead, newHead.Time+1))
838+
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), newHead, p.chain.Config().NextBlockTime(newHead.Time)))
839839
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice))
840840
)
841841
if newHead.ExcessBlobGas != nil {

core/txpool/legacypool/legacypool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest,
13201320
pool.demoteUnexecutables()
13211321
if reset.newHead != nil {
13221322
if pool.chainconfig.IsLondon(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
1323-
pendingBaseFee := eip1559.CalcBaseFee(pool.chainconfig, reset.newHead, reset.newHead.Time+1)
1323+
pendingBaseFee := eip1559.CalcBaseFee(pool.chainconfig, reset.newHead, pool.chainconfig.NextBlockTime(reset.newHead.Time))
13241324
pool.priced.SetBaseFee(pendingBaseFee)
13251325
} else {
13261326
pool.priced.Reheap()

eth/gasprice/feehistory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
9090
bf.results.baseFee = new(big.Int)
9191
}
9292
if config.IsLondon(big.NewInt(int64(bf.blockNumber + 1))) {
93-
bf.results.nextBaseFee = eip1559.CalcBaseFee(config, bf.header, bf.header.Time+1)
93+
bf.results.nextBaseFee = eip1559.CalcBaseFee(config, bf.header, config.NextBlockTime(bf.header.Time))
9494
} else {
9595
bf.results.nextBaseFee = new(big.Int)
9696
}

graphql/graphql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ func (b *Block) NextBaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
780780
return nil, nil
781781
}
782782
}
783-
nextBaseFee := eip1559.CalcBaseFee(chaincfg, header, header.Time+1)
783+
nextBaseFee := eip1559.CalcBaseFee(chaincfg, header, chaincfg.NextBlockTime(header.Time))
784784
return (*hexutil.Big)(nextBaseFee), nil
785785
}
786786

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ func NewRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
12291229
blockTime = uint64(0)
12301230
)
12311231
if current != nil {
1232-
baseFee = eip1559.CalcBaseFee(config, current, current.Time+1)
1232+
baseFee = eip1559.CalcBaseFee(config, current, config.NextBlockTime(current.Time))
12331233
blockNumber = current.Number.Uint64()
12341234
blockTime = current.Time
12351235
}

params/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ type ChainConfig struct {
451451

452452
// Optimism config, nil if not active
453453
Optimism *OptimismConfig `json:"optimism,omitempty"`
454+
455+
// Seconds per L2 block
456+
BlockTime uint64 `json:"blockTime,omitempty"`
454457
}
455458

456459
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
@@ -1349,3 +1352,12 @@ func ptrValueString[T any](t *T) string {
13491352
}
13501353
return fmt.Sprintf("%v", *t)
13511354
}
1355+
1356+
func (c *ChainConfig) NextBlockTime(currentBlockTime uint64) uint64 {
1357+
if c.BlockTime != 0 {
1358+
return currentBlockTime + c.BlockTime
1359+
}
1360+
1361+
// to be compatible with existing call sites
1362+
return currentBlockTime + 1
1363+
}

0 commit comments

Comments
 (0)