diff --git a/jsonrpc/endpoints_eth.go b/jsonrpc/endpoints_eth.go index 5639e842e3..ddf914f6a3 100644 --- a/jsonrpc/endpoints_eth.go +++ b/jsonrpc/endpoints_eth.go @@ -111,13 +111,13 @@ func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash // X Layer LRU if lru_xlayer.GetConfig().Enable { - ret, errValue, ok := getCallResultFromLRU(blockToProcess, tx.To(), tx.Data()) + ret, errValue, ok := getCallResultFromLRU(blockToProcess, sender, tx) if ok { log.Infof("Call result from LRU cache: %v, %v", ret, errValue) return ret, errValue } defer func() { - setCallResultToLRU(blockToProcess, tx.To(), tx.Data(), respRet, errRet) + setCallResultToLRU(blockToProcess, sender, tx, respRet, errRet) }() } diff --git a/jsonrpc/endpoints_eth_lru_xlayer.go b/jsonrpc/endpoints_eth_lru_xlayer.go index 7f8951f819..87206386e4 100644 --- a/jsonrpc/endpoints_eth_lru_xlayer.go +++ b/jsonrpc/endpoints_eth_lru_xlayer.go @@ -1,22 +1,23 @@ package jsonrpc import ( - "crypto/md5" "fmt" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/lru_xlayer" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" + "github.com/0xPolygonHermez/zkevm-node/log" "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" ) -func getCallKey(blockNumber *uint64, to *common.Address, input []byte) (string, string) { - baseKey := fmt.Sprintf("%d-%s-%s", blockNumber, to.Hex(), md5.Sum(input)) +func getCallKey(blockNumber *uint64, sender common.Address, tx *ethtypes.Transaction) (string, string) { + baseKey := fmt.Sprintf("%d-%s-%s", blockNumber, sender.String(), tx.Hash().String()) return baseKey + "ret", baseKey + "err" } -func getCallResultFromLRU(blockNumber *uint64, to *common.Address, input []byte) (interface{}, types.Error, bool) { - retKey, errKey := getCallKey(blockNumber, to, input) +func getCallResultFromLRU(blockNumber *uint64, sender common.Address, tx *ethtypes.Transaction) (interface{}, types.Error, bool) { + retKey, errKey := getCallKey(blockNumber, sender, tx) value, ok := lru_xlayer.GetLRU().Get(retKey) if !ok { return nil, nil, false @@ -33,8 +34,8 @@ func getCallResultFromLRU(blockNumber *uint64, to *common.Address, input []byte) return value, v, true } -func setCallResultToLRU(blockNumber *uint64, to *common.Address, input []byte, value interface{}, errValue types.Error) { - retKey, errKey := getCallKey(blockNumber, to, input) +func setCallResultToLRU(blockNumber *uint64, sender common.Address, tx *ethtypes.Transaction, value interface{}, errValue types.Error) { + retKey, errKey := getCallKey(blockNumber, sender, tx) err := lru_xlayer.GetLRU().Set(retKey, value) if err != nil { log.Debugf("Failed to set value to LRU cache call ret: %v", err)