From 54eea818c51d5f80b5aa44466dbda8bc862042ec Mon Sep 17 00:00:00 2001 From: maximo santoro Date: Wed, 17 Jan 2024 19:07:12 -0300 Subject: [PATCH 1/3] fix eth_getStorage non existing key response --- .../co/rsk/rpc/netty/JsonRpcWeb3ServerHandler.java | 2 ++ .../src/main/java/org/ethereum/rpc/Web3Impl.java | 3 ++- .../test/java/org/ethereum/rpc/Web3ImplTest.java | 14 +++++++------- .../java/org/ethereum/rpc/Web3ImplUnitTest.java | 3 +-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/rpc/netty/JsonRpcWeb3ServerHandler.java b/rskj-core/src/main/java/co/rsk/rpc/netty/JsonRpcWeb3ServerHandler.java index dbb8029ed5e..d15decdc701 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/netty/JsonRpcWeb3ServerHandler.java +++ b/rskj-core/src/main/java/co/rsk/rpc/netty/JsonRpcWeb3ServerHandler.java @@ -107,6 +107,8 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder request) th int errorCode = ErrorResolver.JsonError.CUSTOM_SERVER_ERROR_LOWER; responseContent = buildErrorContent(errorCode, unexpectedErrorMsg); responseCode = errorCode; + } finally { + ReflectionUtil.clearCache(); } ctx.fireChannelRead(new Web3Result( diff --git a/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java b/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java index 1c224f659d3..f9057787f13 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java @@ -86,6 +86,7 @@ public class Web3Impl implements Web3 { private static final Logger logger = LoggerFactory.getLogger("web3"); private static final String CLIENT_VERSION_PREFIX = "RskJ"; + private static final String NON_EXISTING_KEY_RESPONSE = "0x0000000000000000000000000000000000000000000000000000000000000000"; private final MinerClient minerClient; private final MinerServer minerServer; @@ -487,7 +488,7 @@ private String eth_getStorageAt(HexAddressParam address, HexNumberParam storageI .getStorageValue(addr, DataWord.valueOf(HexUtils.strHexOrStrNumberToByteArray(storageIdx.getHexNumber()))); if (sv == null) { - s = "0x0"; + s = NON_EXISTING_KEY_RESPONSE; } else { s = HexUtils.toUnformattedJsonHex(sv.getData()); } diff --git a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java index f8ac098dfff..1ac91726598 100644 --- a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java +++ b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java @@ -107,9 +107,9 @@ * Created by Ruben Altman on 09/06/2016. */ class Web3ImplTest { - private static final String BALANCE_10K_HEX = "0x2710"; //10.000 private static final String CALL_RESPOND = "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000"; + private static final String NON_EXISTING_KEY_RESPONSE = "0x0000000000000000000000000000000000000000000000000000000000000000"; private final TestSystemProperties config = new TestSystemProperties(); private final BlockFactory blockFactory = new BlockFactory(config.getActivationConfig()); @@ -367,7 +367,7 @@ void getBalanceWithAccountAndBlockWithTransaction() { //[ "0x
", { "blockNumber": "0x0" } -> return storage at given address in genesis block void getStorageAtAccountAndBlockNumber() { final ChainParams chain = chainWithAccount10kBalance(false); - assertByBlockNumber("0x0", blockRef -> chain.web3.eth_getStorageAt( + assertByBlockNumber(NON_EXISTING_KEY_RESPONSE, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); @@ -377,7 +377,7 @@ void getStorageAtAccountAndBlockNumber() { //[ "0x
", { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" } -> return storage at given address in genesis block void getStorageAtAccountAndBlockHash() { final ChainParams chain = chainWithAccount10kBalance(false); - assertByBlockHash("0x0", chain.block, blockRef -> chain.web3.eth_getStorageAt( + assertByBlockHash(NON_EXISTING_KEY_RESPONSE, chain.block, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); @@ -428,7 +428,7 @@ void getStorageAtAccountAndNonCanonicalBlockHashWhenCanonicalIsRequired() { //[ "0x
", { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", "requireCanonical": true } -> return storage at given address in genesis block void getStorageAtAccountAndCanonicalBlockHashWhenCanonicalIsRequired() { final ChainParams chain = chainWithAccount10kBalance(false); - assertCanonicalBlockHashWhenCanonical("0x0", chain.block, blockRef -> chain.web3.eth_getStorageAt( + assertCanonicalBlockHashWhenCanonical(NON_EXISTING_KEY_RESPONSE, chain.block, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); @@ -438,7 +438,7 @@ void getStorageAtAccountAndCanonicalBlockHashWhenCanonicalIsRequired() { //[ "0x
", { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", "requireCanonical": false } -> return storage at given address in genesis block void getStorageAtAccountAndCanonicalBlockHashWhenCanonicalIsNotRequired() { final ChainParams chain = chainWithAccount10kBalance(false); - assertCanonicalBlockHashWhenNotCanonical("0x0", chain.block, blockRef -> chain.web3.eth_getStorageAt( + assertCanonicalBlockHashWhenNotCanonical(NON_EXISTING_KEY_RESPONSE, chain.block, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); @@ -448,7 +448,7 @@ void getStorageAtAccountAndCanonicalBlockHashWhenCanonicalIsNotRequired() { // [ "0x
", { "blockHash": "0x", "requireCanonical": false } -> return storage at given address in specified block void getStorageAtAccountAndNonCanonicalBlockHashWhenCanonicalIsNotRequired() { final ChainParams chain = chainWithAccount10kBalance(true); - assertNonCanonicalBlockHashWhenNotCanonical("0x0", chain.block, blockRef -> chain.web3.eth_getStorageAt( + assertNonCanonicalBlockHashWhenNotCanonical(NON_EXISTING_KEY_RESPONSE, chain.block, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); @@ -458,7 +458,7 @@ void getStorageAtAccountAndNonCanonicalBlockHashWhenCanonicalIsNotRequired() { // [ "0x
", { "blockHash": "0x" } -> return storage at given address in specified bloc void getStorageAtAccountAndNonCanonicalBlockHash() { final ChainParams chain = chainWithAccount10kBalance(true); - assertNonCanonicalBlockHash("0x0", chain.block, blockRef -> chain.web3.eth_getStorageAt( + assertNonCanonicalBlockHash(NON_EXISTING_KEY_RESPONSE, chain.block, blockRef -> chain.web3.eth_getStorageAt( new HexAddressParam(chain.accountAddress), new HexNumberParam("0x0"), new BlockRefParam(blockRef))); diff --git a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplUnitTest.java b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplUnitTest.java index 6dfe17b61fd..5c1d7db144c 100644 --- a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplUnitTest.java +++ b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplUnitTest.java @@ -222,8 +222,7 @@ void eth_getStorageAtEmptyCell() { .thenReturn(null); String result = target.eth_getStorageAt(hexAddressParam, hexNumberParam, blockRefParam); - assertEquals("0x0", - result); + assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000", result); } @Test From 34938e181025cc580f547268d2cc451e98be3e61 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Thu, 25 Jan 2024 14:00:49 +0200 Subject: [PATCH 2/3] Changed version to v5.4.0 --- rskj-core/src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rskj-core/src/main/resources/version.properties b/rskj-core/src/main/resources/version.properties index f093fc930f4..08b5b7f5e05 100644 --- a/rskj-core/src/main/resources/version.properties +++ b/rskj-core/src/main/resources/version.properties @@ -1,2 +1,2 @@ -versionNumber='6.0.0' +versionNumber='5.4.0' modifier="RC" From 37c8b14bd5b43604dce95ebe27f8d55df26d9a1a Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Thu, 25 Jan 2024 14:58:16 +0200 Subject: [PATCH 3/3] Changed modifier to FINGERROOT for v5.4.0 --- rskj-core/src/main/resources/version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rskj-core/src/main/resources/version.properties b/rskj-core/src/main/resources/version.properties index 08b5b7f5e05..fc17b52d272 100644 --- a/rskj-core/src/main/resources/version.properties +++ b/rskj-core/src/main/resources/version.properties @@ -1,2 +1,2 @@ versionNumber='5.4.0' -modifier="RC" +modifier="FINGERROOT"