@@ -217,18 +217,17 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms
217217 }
218218
219219 ctx := sdk .UnwrapSDKContext (c )
220- if len (req .ChainId ) > 0 {
221- ctx = ctx .WithChainID (req .ChainId )
222- k .WithChainID (ctx )
223- }
224220
225221 var args types.TransactionArgs
226222 err := json .Unmarshal (req .Args , & args )
227223 if err != nil {
228224 return nil , status .Error (codes .InvalidArgument , err .Error ())
229225 }
230-
231- cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ))
226+ chainID , err := getChainID (ctx , req .ChainId .BigInt ())
227+ if err != nil {
228+ return nil , status .Error (codes .InvalidArgument , err .Error ())
229+ }
230+ cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ), chainID )
232231 if err != nil {
233232 return nil , status .Error (codes .Internal , err .Error ())
234233 }
@@ -260,17 +259,17 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
260259 }
261260
262261 ctx := sdk .UnwrapSDKContext (c )
263- if len ( req .ChainId ) > 0 {
264- ctx = ctx . WithChainID ( req . ChainId )
265- k . WithChainID ( ctx )
262+ chainID , err := getChainID ( ctx , req .ChainId . BigInt ())
263+ if err != nil {
264+ return nil , status . Error ( codes . InvalidArgument , err . Error () )
266265 }
267266
268267 if req .GasCap < ethparams .TxGas {
269268 return nil , status .Error (codes .InvalidArgument , "gas cap cannot be lower than 21,000" )
270269 }
271270
272271 var args types.TransactionArgs
273- err : = json .Unmarshal (req .Args , & args )
272+ err = json .Unmarshal (req .Args , & args )
274273 if err != nil {
275274 return nil , status .Error (codes .InvalidArgument , err .Error ())
276275 }
@@ -302,7 +301,7 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
302301 hi = req .GasCap
303302 }
304303 cap = hi
305- cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ))
304+ cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ), chainID )
306305 if err != nil {
307306 return nil , status .Error (codes .Internal , "failed to load evm config" )
308307 }
@@ -382,12 +381,11 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ
382381 ctx = ctx .WithBlockHeight (contextHeight )
383382 ctx = ctx .WithBlockTime (req .BlockTime )
384383 ctx = ctx .WithHeaderHash (common .Hex2Bytes (req .BlockHash ))
385- if len ( req .ChainId ) > 0 {
386- ctx = ctx . WithChainID ( req . ChainId )
387- k . WithChainID ( ctx )
384+ chainID , err := getChainID ( ctx , req .ChainId . BigInt ())
385+ if err != nil {
386+ return nil , status . Error ( codes . InvalidArgument , err . Error () )
388387 }
389-
390- cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ))
388+ cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ), chainID )
391389 if err != nil {
392390 return nil , status .Errorf (codes .Internal , "failed to load evm config: %s" , err .Error ())
393391 }
@@ -454,12 +452,12 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
454452 ctx = ctx .WithBlockHeight (contextHeight )
455453 ctx = ctx .WithBlockTime (req .BlockTime )
456454 ctx = ctx .WithHeaderHash (common .Hex2Bytes (req .BlockHash ))
457- if len ( req .ChainId ) > 0 {
458- ctx = ctx . WithChainID ( req . ChainId )
459- k . WithChainID ( ctx )
455+ chainID , err := getChainID ( ctx , req .ChainId . BigInt ())
456+ if err != nil {
457+ return nil , status . Error ( codes . InvalidArgument , err . Error () )
460458 }
461459
462- cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ))
460+ cfg , err := k .EVMConfig (ctx , GetProposerAddress (ctx , req .ProposerAddress ), chainID )
463461 if err != nil {
464462 return nil , status .Error (codes .Internal , "failed to load evm config" )
465463 }
@@ -584,7 +582,8 @@ func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types
584582 ctx := sdk .UnwrapSDKContext (c )
585583
586584 params := k .GetParams (ctx )
587- ethCfg := params .ChainConfig .EthereumConfig (k .eip155ChainID )
585+ // the chainID parameter is not used in this case, just set to nil
586+ ethCfg := params .ChainConfig .EthereumConfig (nil )
588587 baseFee := k .GetBaseFee (ctx , ethCfg )
589588
590589 res := & types.QueryBaseFeeResponse {}
@@ -595,3 +594,11 @@ func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types
595594
596595 return res , nil
597596}
597+
598+ // getChainID parse chainID from current context if not provided
599+ func getChainID (ctx sdk.Context , chainID * big.Int ) (* big.Int , error ) {
600+ if chainID == nil {
601+ return ethermint .ParseChainID (ctx .ChainID ())
602+ }
603+ return chainID , nil
604+ }
0 commit comments