@@ -23,6 +23,7 @@ import (
2323
2424 sdk "github.com/cosmos/cosmos-sdk/types"
2525 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
26+ "github.com/pkg/errors"
2627 "google.golang.org/grpc/codes"
2728 "google.golang.org/grpc/status"
2829
@@ -118,16 +119,18 @@ func (b *Backend) getAccountNonce(accAddr common.Address, pending bool, height i
118119}
119120
120121// CalcBaseFee calculates the basefee of the header.
121- func CalcBaseFee (config * params.ChainConfig , parent * ethtypes.Header , p feemarkettypes.Params ) * big.Int {
122+ func CalcBaseFee (config * params.ChainConfig , parent * ethtypes.Header , p feemarkettypes.Params ) ( * big.Int , error ) {
122123 // If the current block is the first EIP-1559 block, return the InitialBaseFee.
123124 if ! config .IsLondon (parent .Number ) {
124- return new (big.Int ).SetUint64 (params .InitialBaseFee )
125+ return new (big.Int ).SetUint64 (params .InitialBaseFee ), nil
126+ }
127+ if p .ElasticityMultiplier == 0 {
128+ return nil , errors .New ("ElasticityMultiplier cannot be 0 as it's checked in the params validation" )
125129 }
126-
127130 parentGasTarget := parent .GasLimit / uint64 (p .ElasticityMultiplier )
128131 // If the parent gasUsed is the same as the target, the baseFee remains unchanged.
129132 if parent .GasUsed == parentGasTarget {
130- return new (big.Int ).Set (parent .BaseFee )
133+ return new (big.Int ).Set (parent .BaseFee ), nil
131134 }
132135
133136 var (
@@ -144,7 +147,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, p feemarke
144147 num .Div (num , denom .SetUint64 (uint64 (p .BaseFeeChangeDenominator )))
145148 baseFeeDelta := math .BigMax (num , common .Big1 )
146149
147- return num .Add (parent .BaseFee , baseFeeDelta )
150+ return num .Add (parent .BaseFee , baseFeeDelta ), nil
148151 }
149152
150153 // Otherwise if the parent block used less gas than its target, the baseFee should decrease.
@@ -155,7 +158,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, p feemarke
155158 num .Div (num , denom .SetUint64 (uint64 (p .BaseFeeChangeDenominator )))
156159 baseFee := num .Sub (parent .BaseFee , num )
157160 minGasPrice := p .MinGasPrice .TruncateInt ().BigInt ()
158- return math .BigMax (baseFee , minGasPrice )
161+ return math .BigMax (baseFee , minGasPrice ), nil
159162}
160163
161164// output: targetOneFeeHistory
@@ -201,7 +204,11 @@ func (b *Backend) processBlock(
201204 if err != nil {
202205 return err
203206 }
204- targetOneFeeHistory .NextBaseFee = CalcBaseFee (cfg , & header , params .Params )
207+ nextBaseFee , err := CalcBaseFee (cfg , & header , params .Params )
208+ if err != nil {
209+ return err
210+ }
211+ targetOneFeeHistory .NextBaseFee = nextBaseFee
205212 } else {
206213 targetOneFeeHistory .NextBaseFee = new (big.Int )
207214 }
0 commit comments