From 8262eae9e3f5ad726697e2d3a7da8d1f12977277 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 5 Sep 2024 21:11:44 +0530 Subject: [PATCH] consensus/bor: use CallWithState to fetch last state id (#1323) * consensus/bor: use CallWithState to fetch last state id * fix --- consensus/bor/api/caller.go | 2 ++ consensus/bor/contract/client.go | 8 ++++---- internal/ethapi/api.go | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/consensus/bor/api/caller.go b/consensus/bor/api/caller.go index 78f1b50a8a..684892740b 100644 --- a/consensus/bor/api/caller.go +++ b/consensus/bor/api/caller.go @@ -4,6 +4,7 @@ import ( "context" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/rpc" ) @@ -11,4 +12,5 @@ import ( //go:generate mockgen -destination=./caller_mock.go -package=api . Caller type Caller interface { Call(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *ethapi.StateOverride, blockOverrides *ethapi.BlockOverrides) (hexutil.Bytes, error) + CallWithState(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, state *state.StateDB, overrides *ethapi.StateOverride, blockOverrides *ethapi.BlockOverrides) (hexutil.Bytes, error) } diff --git a/consensus/bor/contract/client.go b/consensus/bor/contract/client.go index a39dc75044..1cfc2fd8e9 100644 --- a/consensus/bor/contract/client.go +++ b/consensus/bor/contract/client.go @@ -119,13 +119,13 @@ func (gc *GenesisContractsClient) LastStateId(state *state.StateDB, number uint6 toAddress := common.HexToAddress(gc.StateReceiverContract) gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2)) - // Do a call with state so that we can fetch the last state ID from a given (incoming) - // state instead of local(canonical) chain. - result, err := gc.ethAPI.Call(context.Background(), ethapi.TransactionArgs{ + // BOR: Do a 'CallWithState' so that we can fetch the last state ID from a given (incoming) + // state instead of local(canonical) chain's state. + result, err := gc.ethAPI.CallWithState(context.Background(), ethapi.TransactionArgs{ Gas: &gas, To: &toAddress, Data: &msgData, - }, &rpc.BlockNumberOrHash{BlockNumber: &blockNr, BlockHash: &hash}, nil, nil) + }, &rpc.BlockNumberOrHash{BlockNumber: &blockNr, BlockHash: &hash}, state, nil, nil) if err != nil { return nil, err } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 03f13af417..2d9c1b8fb4 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1377,7 +1377,7 @@ func (e *revertError) ErrorData() interface{} { // Note, this function doesn't make and changes in the state/blockchain and is // useful to execute and retrieve values. func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { - return s.CallWithState(ctx, args, *blockNrOrHash, nil, overrides, blockOverrides) + return s.CallWithState(ctx, args, blockNrOrHash, nil, overrides, blockOverrides) } // CallWithState executes the given transaction on the given state for @@ -1389,8 +1389,8 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO // // Note, this function doesn't make and changes in the state/blockchain and is // useful to execute and retrieve values. -func (s *BlockChainAPI) CallWithState(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, state *state.StateDB, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { - result, err := DoCall(ctx, s.b, args, blockNrOrHash, state, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) +func (s *BlockChainAPI) CallWithState(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, state *state.StateDB, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { + result, err := DoCall(ctx, s.b, args, *blockNrOrHash, state, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) if err != nil { return nil, err }