diff --git a/blockchain/system/multicall.go b/blockchain/system/multicall.go index 041b8d2cf..90d61f5ae 100644 --- a/blockchain/system/multicall.go +++ b/blockchain/system/multicall.go @@ -76,6 +76,6 @@ func (caller *ContractCallerForMultiCall) CallContract(ctx context.Context, call // NewMultiCallContractCaller creates a new instance of ContractCaller for MultiCall contract. func NewMultiCallContractCaller(state *state.StateDB, chain backends.BlockChainForCaller, header *types.Header) (*multicall.MultiCallContractCaller, error) { - c := &ContractCallerForMultiCall{state, chain, header} + c := &ContractCallerForMultiCall{state.Copy(), chain, header} // Copy the state to prevent the original state from being modified. return multicall.NewMultiCallContractCaller(MultiCallAddr, c) } diff --git a/blockchain/system/multicall_test.go b/blockchain/system/multicall_test.go index 922319f7b..08994a8b6 100644 --- a/blockchain/system/multicall_test.go +++ b/blockchain/system/multicall_test.go @@ -42,13 +42,12 @@ func TestContractCallerForMultiCall(t *testing.T) { header := backend.BlockChain().CurrentHeader() chain := backend.BlockChain() - tempState, _ := backend.BlockChain().StateAt(header.Root) - caller, _ := NewMultiCallContractCaller(tempState, chain, header) + state, _ := backend.BlockChain().StateAt(header.Root) + caller, _ := NewMultiCallContractCaller(state, chain, header) ret, err := caller.MultiCallStakingInfo(&bind.CallOpts{BlockNumber: header.Number}) assert.Nil(t, err) // Does not affect the original state - state, _ := backend.BlockChain().StateAt(header.Root) assert.Equal(t, []byte(nil), state.GetCode(MultiCallAddr)) // Mock data diff --git a/reward/staking_manager.go b/reward/staking_manager.go index 5bee9c43a..3211863e7 100644 --- a/reward/staking_manager.go +++ b/reward/staking_manager.go @@ -259,7 +259,7 @@ func PreloadStakingInfoWithState(header *types.Header, statedb *state.StateDB) e } num := header.Number.Uint64() - info, err := getStakingInfoFromMultiCallAtState(num, statedb.Copy(), header) + info, err := getStakingInfoFromMultiCallAtState(num, statedb, header) if err != nil { return fmt.Errorf("staking info preload failed. root err: %v", err) } @@ -334,17 +334,17 @@ func getStakingInfoFromMultiCall(blockNum uint64) (*StakingInfo, error) { return nil, fmt.Errorf("failed to get header by number %d", blockNum) } - tempState, err := stakingManager.blockchain.StateAt(header.Root) + statedb, err := stakingManager.blockchain.StateAt(header.Root) if err != nil { return nil, fmt.Errorf("failed to get state at number %d. root err: %s", blockNum, err) } - return getStakingInfoFromMultiCallAtState(blockNum, tempState, header) + return getStakingInfoFromMultiCallAtState(blockNum, statedb, header) } -func getStakingInfoFromMultiCallAtState(blockNum uint64, tempState *state.StateDB, header *types.Header) (*StakingInfo, error) { +func getStakingInfoFromMultiCallAtState(blockNum uint64, statedb *state.StateDB, header *types.Header) (*StakingInfo, error) { // Get staking info from multicall contract - caller, err := system.NewMultiCallContractCaller(tempState, stakingManager.blockchain, header) + caller, err := system.NewMultiCallContractCaller(statedb, stakingManager.blockchain, header) if err != nil { return nil, fmt.Errorf("failed to create multicall contract caller. root err: %s", err) }