From ca0813a7b7ffb3faa6a4c47b9e7dfe1ee2ceb47c Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 28 Jun 2024 20:46:15 +0800 Subject: [PATCH 1/2] avoid use map point --- ethclient/gethclient/gethclient.go | 4 ++-- ethclient/gethclient/gethclient_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index b1678b67664e..ab0059e88dcf 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -135,7 +135,7 @@ func (ec *Client) GetProof(ctx context.Context, account common.Address, keys []s // overrides specifies a map of contract states that should be overwritten before executing // the message call. // Please use ethclient.CallContract instead if you don't need the override functionality. -func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides *map[common.Address]OverrideAccount) ([]byte, error) { +func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides map[common.Address]OverrideAccount) ([]byte, error) { var hex hexutil.Bytes err := ec.c.CallContext( ctx, &hex, "eth_call", toCallArg(msg), @@ -157,7 +157,7 @@ func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockN // blockOverrides specifies block fields exposed to the EVM that can be overridden for the call. // // Please use ethclient.CallContract instead if you don't need the override functionality. -func (ec *Client) CallContractWithBlockOverrides(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides *map[common.Address]OverrideAccount, blockOverrides BlockOverrides) ([]byte, error) { +func (ec *Client) CallContractWithBlockOverrides(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides map[common.Address]OverrideAccount, blockOverrides BlockOverrides) ([]byte, error) { var hex hexutil.Bytes err := ec.c.CallContext( ctx, &hex, "eth_call", toCallArg(msg), diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 59ad370146bb..32de74e3e754 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -442,7 +442,7 @@ func testCallContract(t *testing.T, client *rpc.Client) { } mapAcc := make(map[common.Address]OverrideAccount) mapAcc[testAddr] = override - if _, err := ec.CallContract(context.Background(), msg, big.NewInt(0), &mapAcc); err != nil { + if _, err := ec.CallContract(context.Background(), msg, big.NewInt(0), mapAcc); err != nil { t.Fatalf("unexpected error: %v", err) } } @@ -548,7 +548,7 @@ func testCallContractWithBlockOverrides(t *testing.T, client *rpc.Client) { } mapAcc := make(map[common.Address]OverrideAccount) mapAcc[common.Address{}] = override - res, err := ec.CallContract(context.Background(), msg, big.NewInt(0), &mapAcc) + res, err := ec.CallContract(context.Background(), msg, big.NewInt(0), mapAcc) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -560,7 +560,7 @@ func testCallContractWithBlockOverrides(t *testing.T, client *rpc.Client) { bo := BlockOverrides{ Coinbase: common.HexToAddress("0x1111111111111111111111111111111111111111"), } - res, err = ec.CallContractWithBlockOverrides(context.Background(), msg, big.NewInt(0), &mapAcc, bo) + res, err = ec.CallContractWithBlockOverrides(context.Background(), msg, big.NewInt(0), mapAcc, bo) if err != nil { t.Fatalf("unexpected error: %v", err) } From 419f55d8d49172471b6144a02d43a96f24571c3b Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 28 Jun 2024 21:00:02 +0800 Subject: [PATCH 2/2] avoid use map point --- eth/tracers/api_test.go | 6 +++--- eth/tracers/logger/logger.go | 24 ++++++++++++------------ internal/ethapi/api.go | 14 +++++++------- internal/ethapi/api_test.go | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 6fbb50848d63..e7183ba36e6a 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -843,7 +843,7 @@ func TestTracingWithOverrides(t *testing.T) { byte(vm.PUSH1), 00, byte(vm.RETURN), }), - StateDiff: &map[common.Hash]common.Hash{ + StateDiff: map[common.Hash]common.Hash{ common.HexToHash("0x03"): common.HexToHash("0x11"), }, }, @@ -908,7 +908,7 @@ func newRPCBytes(bytes []byte) *hexutil.Bytes { return &rpcBytes } -func newStates(keys []common.Hash, vals []common.Hash) *map[common.Hash]common.Hash { +func newStates(keys []common.Hash, vals []common.Hash) map[common.Hash]common.Hash { if len(keys) != len(vals) { panic("invalid input") } @@ -916,7 +916,7 @@ func newStates(keys []common.Hash, vals []common.Hash) *map[common.Hash]common.H for i := 0; i < len(keys); i++ { m[keys[i]] = vals[i] } - return &m + return m } func TestTraceChain(t *testing.T) { diff --git a/eth/tracers/logger/logger.go b/eth/tracers/logger/logger.go index ef1d47146682..b0424d6ea8a7 100644 --- a/eth/tracers/logger/logger.go +++ b/eth/tracers/logger/logger.go @@ -423,17 +423,17 @@ type ExecutionResult struct { // StructLogRes stores a structured log emitted by the EVM while replaying a // transaction in debug mode type StructLogRes struct { - Pc uint64 `json:"pc"` - Op string `json:"op"` - Gas uint64 `json:"gas"` - GasCost uint64 `json:"gasCost"` - Depth int `json:"depth"` - Error string `json:"error,omitempty"` - Stack *[]string `json:"stack,omitempty"` - ReturnData string `json:"returnData,omitempty"` - Memory *[]string `json:"memory,omitempty"` - Storage *map[string]string `json:"storage,omitempty"` - RefundCounter uint64 `json:"refund,omitempty"` + Pc uint64 `json:"pc"` + Op string `json:"op"` + Gas uint64 `json:"gas"` + GasCost uint64 `json:"gasCost"` + Depth int `json:"depth"` + Error string `json:"error,omitempty"` + Stack *[]string `json:"stack,omitempty"` + ReturnData string `json:"returnData,omitempty"` + Memory *[]string `json:"memory,omitempty"` + Storage map[string]string `json:"storage,omitempty"` + RefundCounter uint64 `json:"refund,omitempty"` } // formatLogs formats EVM returned structured logs for json output @@ -471,7 +471,7 @@ func formatLogs(logs []StructLog) []StructLogRes { for i, storageValue := range trace.Storage { storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue) } - formatted[index].Storage = &storage + formatted[index].Storage = storage } } return formatted diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0ecedf113038..31b5159cb7be 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -968,11 +968,11 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp // if stateDiff is set, all diff will be applied first and then execute the call // message. type OverrideAccount struct { - Nonce *hexutil.Uint64 `json:"nonce"` - Code *hexutil.Bytes `json:"code"` - Balance **hexutil.Big `json:"balance"` - State *map[common.Hash]common.Hash `json:"state"` - StateDiff *map[common.Hash]common.Hash `json:"stateDiff"` + Nonce *hexutil.Uint64 `json:"nonce"` + Code *hexutil.Bytes `json:"code"` + Balance **hexutil.Big `json:"balance"` + State map[common.Hash]common.Hash `json:"state"` + StateDiff map[common.Hash]common.Hash `json:"stateDiff"` } // StateOverride is the collection of overridden accounts. @@ -1002,11 +1002,11 @@ func (diff *StateOverride) Apply(statedb *state.StateDB) error { } // Replace entire state if caller requires. if account.State != nil { - statedb.SetStorage(addr, *account.State) + statedb.SetStorage(addr, account.State) } // Apply state diff into specified accounts. if account.StateDiff != nil { - for key, value := range *account.StateDiff { + for key, value := range account.StateDiff { statedb.SetState(addr, key, value) } } diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index cf5160caf778..7d4289d7f907 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -904,7 +904,7 @@ func TestCall(t *testing.T) { overrides: StateOverride{ randomAccounts[2].addr: OverrideAccount{ Code: hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80638381f58a14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea2646970667358221220eab35ffa6ab2adfe380772a48b8ba78e82a1b820a18fcb6f59aa4efb20a5f60064736f6c63430007040033"), - StateDiff: &map[common.Hash]common.Hash{{}: common.BigToHash(big.NewInt(123))}, + StateDiff: map[common.Hash]common.Hash{{}: common.BigToHash(big.NewInt(123))}, }, }, want: "0x000000000000000000000000000000000000000000000000000000000000007b",