diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0255608d..88d95350a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -122,7 +122,6 @@ jobs: ccache --show-stats - name: Build dependencies run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" export CC=gcc-9 export CXX=g++-9 @@ -134,6 +133,7 @@ jobs: rm -f ./libwebsockets-from-git.tar.gz ./build.sh DEBUG=1 PARALLEL_COUNT=$(nproc) cd .. + - name: Configure all run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -282,7 +282,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.info - + - name: Configure all as historic run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -310,3 +310,9 @@ jobs: - name: Print ccache stats after full historic build run : | ccache --show-stats + - name: Testeth historic + run : | + cd build/test + export NO_NTP_CHECK=1 + export NO_ULIMIT_CHECK=1 + ./testeth -t JsonRpcSuite -- --express --verbosity 4 diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 849664172..63d4a8ff3 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -66,6 +66,12 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn, _readLock.unlock(); _writeLock.lock(); + unsigned realBn = _bn; + if ( _bn == LatestBlock ) + realBn = client.number(); + else if ( _bn == PendingBlock ) + realBn = client.number() + 1; // TODO test this case and decide + assert( real2gappedCache.size() <= cacheSize ); if ( real2gappedCache.size() >= cacheSize ) { real2gappedCache.erase( real2gappedCache.begin() ); @@ -89,7 +95,7 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn, pair< h256, unsigned > loc = client.transactionLocation( th ); // ignore transactions with 0 gas usage OR different location! - if ( diff == 0 || client.numberFromHash( loc.first ) != _bn || loc.second != realIndex ) + if ( diff == 0 || client.numberFromHash( loc.first ) != realBn || loc.second != realIndex ) continue; // cache it diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 0f683f344..fcb0596dd 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3099,15 +3099,36 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { #ifdef HISTORIC_STATE // 3 check that historic node sees only 3 txns + string explicitNumberStr = to_string(fixture.client->number()); + // 1 Block Json::Value block = fixture.rpcClient->eth_getBlockByNumber("latest", "false"); + string bh = block["hash"].asString(); + + // 2 transaction count + Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest"); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber(explicitNumberStr); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + + + BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3); + BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0"); + BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1"); + BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2"); + + // same with explicit number + block = fixture.rpcClient->eth_getBlockByNumber(explicitNumberStr, "false"); + BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3); BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0"); BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1"); BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2"); - // 2 receipts + // 3 receipts Json::Value r1,r3,r4; BOOST_REQUIRE_NO_THROW(r1 = fixture.rpcClient->eth_getTransactionReceipt(toJS(h1))); BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionReceipt(toJS(h2)), jsonrpc::JsonRpcException); @@ -3118,16 +3139,24 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { BOOST_REQUIRE_EQUAL(r3["transactionIndex"], "0x1"); BOOST_REQUIRE_EQUAL(r4["transactionIndex"], "0x2"); - // 3 transaction by index + // 4 transaction by index Json::Value t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "0"); Json::Value t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "1"); Json::Value t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "2"); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); + // same with explicit block number + + t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "0"); + t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "1"); + t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "2"); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); - string bh = r1["blockHash"].asString(); + BOOST_REQUIRE_EQUAL(bh, r1["blockHash"].asString()); t0 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "0"); t1 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "1"); @@ -3137,15 +3166,9 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); - // 4 transaction by hash + // 5 transaction by hash BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionByHash(toJS(h2)), jsonrpc::JsonRpcException); - // 5 transaction count - Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest"); - BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); - cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh); - BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); - // send it successfully // make money