Skip to content

Commit

Permalink
return default fee if not subnet-evm
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur committed Feb 28, 2025
1 parent 3073c3c commit 098c255
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,15 @@ func (bc *BlockChain) SubscribeAcceptedTransactionEvent(ch chan<- NewTxsEvent) e
}

// GetFeeConfigAt returns the fee configuration and the last changed block number at [parent].
// If Subnet-EVM is not activated, returns default fee config and nil block number.
// If FeeManager is activated at [parent], returns the fee config in the precompile contract state.
// Otherwise returns the fee config in the chain config.
// Assumes that a valid configuration is stored when the precompile is activated.
func (bc *BlockChain) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error) {
config := bc.Config()
if !config.IsSubnetEVM(parent.Time) {
return params.DefaultFeeConfig, nil, nil
}
if !config.IsPrecompileEnabled(feemanager.ContractAddress, parent.Time) {
return config.FeeConfig, common.Big0, nil
}
Expand Down
3 changes: 3 additions & 0 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,8 @@ func (pool *LegacyPool) periodicBaseFeeUpdate() {
}
}

// updateBaseFee updates the base fee in the tx pool based on the current head block.
// should only be called when the chain is in Subnet EVM.
func (pool *LegacyPool) updateBaseFee() {
pool.mu.Lock()
defer pool.mu.Unlock()
Expand All @@ -1829,6 +1831,7 @@ func (pool *LegacyPool) updateBaseFee() {
}

// assumes lock is already held
// should only be called when the chain is in Subnet EVM.
func (pool *LegacyPool) updateBaseFeeAt(head *types.Header) error {
feeConfig, _, err := pool.chain.GetFeeConfigAt(head)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,8 @@ func NewOracle(backend OracleBackend, config Config) (*Oracle, error) {
}
}()
feeConfig, _, err := backend.GetFeeConfigAt(backend.LastAcceptedBlock().Header())
var minBaseFee *big.Int
if err != nil {
// resort back to chain config
return nil, fmt.Errorf("failed getting fee config in the oracle: %w", err)
} else {
minBaseFee = feeConfig.MinBaseFee
}
feeInfoProvider, err := newFeeInfoProvider(backend, minGasUsed.Uint64(), config.Blocks)
if err != nil {
Expand All @@ -206,7 +202,7 @@ func NewOracle(backend OracleBackend, config Config) (*Oracle, error) {
return &Oracle{
backend: backend,
lastPrice: minPrice,
lastBaseFee: new(big.Int).Set(minBaseFee),
lastBaseFee: new(big.Int).Set(feeConfig.MinBaseFee),
minPrice: minPrice,
maxPrice: maxPrice,
checkBlocks: blocks,
Expand Down

0 comments on commit 098c255

Please sign in to comment.