Skip to content

Commit

Permalink
Add retrievePreGingerbreadGasLimit to resolve broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kourin1996 committed Dec 21, 2024
1 parent 9abb2fb commit a9bc96f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions internal/ethapi/celo_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,12 @@ func PopulatePreGingerbreadHeaderFields(ctx context.Context, backend CeloBackend
}

// If the record is not found, get the values and store them
retrievedBaseFee, err := retrievePreGingerbreadBlockBaseFee(ctx, backend, header.Number)
baseFee, err = retrievePreGingerbreadBlockBaseFee(ctx, backend, header.Number)
if err != nil {
log.Debug("Not adding baseFeePerGas to RPC response, failed to retrieve gas price minimum", "block", header.Number.Uint64(), "err", err)
} else {
baseFee = retrievedBaseFee
}

limits, ok := params.PreGingerbreadNetworkGasLimits[backend.ChainConfig().ChainID.Uint64()]
if !ok {
log.Debug("Not adding gasLimit to RPC response, unknown network", "chainID", backend.ChainConfig().ChainID)
} else {
gasLimit = new(big.Int).SetUint64(limits.Limit(header.Number))
}
gasLimit = retrievePreGingerbreadGasLimit(backend, header.Number)

if baseFee != nil || gasLimit != nil {
err = rawdb.WritePreGingerbreadAdditionalFields(backend.ChainDb(), header.Hash(), &rawdb.PreGingerbreadAdditionalFields{
Expand All @@ -90,6 +83,22 @@ func PopulatePreGingerbreadHeaderFields(ctx context.Context, backend CeloBackend
return header
}

// retrievePreGingerbreadGasLimit retrieves a gas limit at given height from hardcoded values
func retrievePreGingerbreadGasLimit(backend CeloBackend, height *big.Int) *big.Int {
if backend.ChainConfig().ChainID == nil {
log.Debug("Not adding gasLimit to RPC response, unknown network")
return nil
}

limits, ok := params.PreGingerbreadNetworkGasLimits[backend.ChainConfig().ChainID.Uint64()]
if !ok {
log.Debug("Not adding gasLimit to RPC response, unknown network", "chainID", backend.ChainConfig().ChainID)
return nil
}

return new(big.Int).SetUint64(limits.Limit(height))
}

// retrievePreGingerbreadBlockBaseFee retrieves a base fee at given height from the previous block
func retrievePreGingerbreadBlockBaseFee(ctx context.Context, backend CeloBackend, height *big.Int) (*big.Int, error) {
if height.Cmp(common.Big0) <= 0 {
Expand Down

0 comments on commit a9bc96f

Please sign in to comment.