diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index 735ac1abede..7f5788f8a70 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -87,13 +87,9 @@ func (f eip1559Calculator) CurrentFees(chainConfig *chain.Config, db kv.Getter) } if currentHeader.ExcessBlobGas != nil { - var nextHeaderTime = currentHeader.Time + 1 // Speculative - Next header must be at least 1 second ahead - parentHeader := rawdb.ReadHeaderByNumber(db, currentHeader.Number.Uint64()-1) - if parentHeader != nil { - nextHeaderTime = currentHeader.Time + (currentHeader.Time - parentHeader.Time) // This difference should be close enough to seconds per slot - } - excessBlobGas := CalcExcessBlobGas(chainConfig, currentHeader, nextHeaderTime) - b, err := GetBlobGasPrice(chainConfig, excessBlobGas, nextHeaderTime) + nextBlockTime := currentHeader.Time + chainConfig.SecondsPerSlot() + excessBlobGas := CalcExcessBlobGas(chainConfig, currentHeader, nextBlockTime) + b, err := GetBlobGasPrice(chainConfig, excessBlobGas, nextBlockTime) if err != nil { return 0, 0, 0, 0, err } diff --git a/erigon-lib/chain/chain_config.go b/erigon-lib/chain/chain_config.go index 27f8b5803a8..206f71adee4 100644 --- a/erigon-lib/chain/chain_config.go +++ b/erigon-lib/chain/chain_config.go @@ -316,6 +316,16 @@ func (c *Config) GetMaxBlobsPerBlock(time uint64) uint64 { return c.GetMaxBlobGasPerBlock(time) / fixedgas.BlobGasPerBlob } +func (c *Config) SecondsPerSlot() uint64 { + if c.Bor != nil { + return 2 // Polygon + } + if c.Aura != nil { + return 5 // Gnosis + } + return 12 // Ethereum +} + // CheckCompatible checks whether scheduled fork transitions have been imported // with a mismatching chain configuration. func (c *Config) CheckCompatible(newcfg *Config, height uint64) *ConfigCompatError { diff --git a/eth/gasprice/feehistory.go b/eth/gasprice/feehistory.go index b18ea28b717..16f10cf1ee2 100644 --- a/eth/gasprice/feehistory.go +++ b/eth/gasprice/feehistory.go @@ -61,7 +61,6 @@ type blockFees struct { blobBaseFee, nextBlobBaseFee *big.Int gasUsedRatio float64 blobGasUsedRatio float64 - secondsPerSlot uint64 err error } @@ -103,7 +102,8 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) { bf.err = err return } - nextBlobBaseFee256, err := misc.GetBlobGasPrice(chainconfig, misc.CalcExcessBlobGas(chainconfig, bf.header, bf.header.Time+bf.secondsPerSlot), bf.header.Time+bf.secondsPerSlot) + nextBlockTime := bf.header.Time + chainconfig.SecondsPerSlot() + nextBlobBaseFee256, err := misc.GetBlobGasPrice(chainconfig, misc.CalcExcessBlobGas(chainconfig, bf.header, nextBlockTime), nextBlockTime) if err != nil { bf.err = err return @@ -169,26 +169,23 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) { // also returned if requested and available. // Note: an error is only returned if retrieving the head header has failed. If there are no // retrievable blocks in the specified range then zero block count is returned with no error. -func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlock rpc.BlockNumber, blocks, maxHistory int) (*types.Block, []*types.Receipt, uint64, int, uint64, error) { +func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlock rpc.BlockNumber, blocks, maxHistory int) (*types.Block, []*types.Receipt, uint64, int, error) { var ( headBlock rpc.BlockNumber pendingBlock *types.Block pendingReceipts types.Receipts - secondsPerSlot uint64 // Time diff from parent block as an approx - lastBlockTime uint64 ) // query either pending block or head header and set headBlock if lastBlock == rpc.PendingBlockNumber { if pendingBlock, pendingReceipts = oracle.backend.PendingBlockAndReceipts(); pendingBlock != nil { lastBlock = rpc.BlockNumber(pendingBlock.NumberU64()) headBlock = lastBlock - 1 - lastBlockTime = pendingBlock.Time() } else { // pending block not supported by backend, process until latest block lastBlock = rpc.LatestBlockNumber blocks-- if blocks == 0 { - return nil, nil, 0, 0, 0, nil + return nil, nil, 0, 0, nil } } } @@ -196,24 +193,14 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlock rpc.Block // if pending block is not fetched then we retrieve the head header to get the head block number if latestHeader, err := oracle.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber); err == nil { headBlock = rpc.BlockNumber(latestHeader.Number.Uint64()) - lastBlockTime = latestHeader.Time } else { - return nil, nil, 0, 0, 0, err + return nil, nil, 0, 0, err } } if lastBlock == rpc.LatestBlockNumber { lastBlock = headBlock } else if pendingBlock == nil && lastBlock > headBlock { - return nil, nil, 0, 0, 0, fmt.Errorf("%w: requested %d, head %d", ErrRequestBeyondHead, lastBlock, headBlock) - } - if lastBlock > 0 { - parentHeader, err := oracle.backend.HeaderByNumber(ctx, lastBlock-1) - if err != nil { - return nil, nil, 0, 0, 0, err - } - if parentHeader != nil { - secondsPerSlot = parentHeader.Time - lastBlockTime - } + return nil, nil, 0, 0, fmt.Errorf("%w: requested %d, head %d", ErrRequestBeyondHead, lastBlock, headBlock) } if maxHistory != 0 { // limit retrieval to the given number of latest blocks @@ -222,7 +209,7 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlock rpc.Block if int64(blocks) > tooOldCount { blocks -= int(tooOldCount) } else { - return nil, nil, 0, 0, 0, nil + return nil, nil, 0, 0, nil } } } @@ -230,7 +217,7 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, lastBlock rpc.Block if rpc.BlockNumber(blocks) > lastBlock+1 { blocks = int(lastBlock + 1) } - return pendingBlock, pendingReceipts, uint64(lastBlock), blocks, secondsPerSlot, nil + return pendingBlock, pendingReceipts, uint64(lastBlock), blocks, nil } // FeeHistory returns data relevant for fee estimation based on the specified range of blocks. @@ -276,7 +263,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast pendingReceipts []*types.Receipt err error ) - pendingBlock, pendingReceipts, lastBlock, blocks, secondsPerSlot, err := oracle.resolveBlockRange(ctx, unresolvedLastBlock, blocks, maxHistory) + pendingBlock, pendingReceipts, lastBlock, blocks, err := oracle.resolveBlockRange(ctx, unresolvedLastBlock, blocks, maxHistory) if err != nil || blocks == 0 { return libcommon.Big0, nil, nil, nil, nil, nil, err } @@ -303,7 +290,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast continue } - fees := &blockFees{blockNumber: blockNumber, secondsPerSlot: secondsPerSlot} + fees := &blockFees{blockNumber: blockNumber} if pendingBlock != nil && blockNumber >= pendingBlock.NumberU64() { fees.block, fees.receipts = pendingBlock, pendingReceipts } else { diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index 46952cd7dc4..67fb105343d 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -30,9 +30,7 @@ import ( "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/kv/rawdbv3" "github.com/erigontech/erigon-lib/log/v3" - "github.com/erigontech/erigon-lib/rlp" - "github.com/erigontech/erigon/cl/clparams" "github.com/erigontech/erigon/core" "github.com/erigontech/erigon/core/rawdb" "github.com/erigontech/erigon/core/state" @@ -122,7 +120,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat blockNumber := stateBlockNumber + 1 - timestamp := parent.Time + clparams.MainnetBeaconConfig.SecondsPerSlot + timestamp := parent.Time + chainConfig.SecondsPerSlot() coinbase := parent.Coinbase header := &types.Header{ diff --git a/turbo/jsonrpc/eth_system.go b/turbo/jsonrpc/eth_system.go index a52467a0747..6bca6d17414 100644 --- a/turbo/jsonrpc/eth_system.go +++ b/turbo/jsonrpc/eth_system.go @@ -215,11 +215,7 @@ func (api *APIImpl) BlobBaseFee(ctx context.Context) (*hexutil.Big, error) { if config == nil { return (*hexutil.Big)(common.Big0), nil } - nextBlockTime := header.Time + 1 // At least 1 second ahead - parent := rawdb.ReadHeaderByNumber(tx, header.Number.Uint64()-1) - if parent != nil { - nextBlockTime = header.Time + (header.Time - parent.Time) // Close enough to seconds per slot - } + nextBlockTime := header.Time + config.SecondsPerSlot() ret256, err := misc.GetBlobGasPrice(config, misc.CalcExcessBlobGas(config, header, nextBlockTime), nextBlockTime) if err != nil { return nil, err diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index da260170720..79934ad14f9 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -483,11 +483,7 @@ func (h *Hook) sendNotifications(tx kv.Tx, finishStageBeforeSync uint64) error { pendingBaseFee := misc.CalcBaseFee(h.chainConfig, currentHeader) pendingBlobFee := h.chainConfig.GetMinBlobGasPrice() if currentHeader.ExcessBlobGas != nil { - nextBlockTime := currentHeader.Time + 1 - parentHeader := rawdb.ReadHeaderByNumber(tx, currentHeader.Number.Uint64()) - if parentHeader != nil { - nextBlockTime = currentHeader.Time + (currentHeader.Time - parentHeader.Time) // Approximately next block time - } + nextBlockTime := currentHeader.Time + h.chainConfig.SecondsPerSlot() excessBlobGas := misc.CalcExcessBlobGas(h.chainConfig, currentHeader, nextBlockTime) f, err := misc.GetBlobGasPrice(h.chainConfig, excessBlobGas, nextBlockTime) if err != nil {