From f577553604907c6d5c4983e368e47b8ec95ad201 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 5 Sep 2024 18:59:08 +0530 Subject: [PATCH 1/2] consensus/bor: use CallWithState to fetch last state id --- consensus/bor/api/caller.go | 2 ++ consensus/bor/contract/client.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 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 } From 1900ddf7232b907bf0f164a112b3a75865ea98e5 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 5 Sep 2024 19:34:56 +0530 Subject: [PATCH 2/2] fix --- internal/ethapi/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 }