From 3ecac21748341904c3d5591652051dcbec843455 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Sun, 28 Apr 2024 13:47:36 +0100 Subject: [PATCH 01/16] SKALED-1878 Colorful logs --- libethcore/Exceptions.h | 3 +++ libethereum/ChainParams.cpp | 2 ++ libethereum/ClientBase.cpp | 15 +++------------ libethereum/ClientBase.h | 1 - libethereum/Interface.h | 9 --------- libskutils/include/skutils/console_colors.h | 9 +++++---- libskutils/src/console_colors.cpp | 8 ++++---- libweb3jsonrpc/Eth.cpp | 16 +++++++++++----- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 8 ++++---- 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index 60a76954c..a39c33a00 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -107,5 +107,8 @@ DEV_SIMPLE_EXCEPTION( FailedToDownloadDaoForkBlockHeader ); DEV_SIMPLE_EXCEPTION( AccountLocked ); DEV_SIMPLE_EXCEPTION( TransactionRefused ); DEV_SIMPLE_EXCEPTION( UnknownAccount ); + +DEV_SIMPLE_EXCEPTION( TooBigResponse ); + } // namespace eth } // namespace dev diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 23134a877..fa7c4d1cc 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -104,6 +104,8 @@ ChainParams ChainParams::loadConfig( cp.skaleDisableChainIdCheck = params.count( c_skaleDisableChainIdCheck ) ? params[c_skaleDisableChainIdCheck].get_bool() : false; + cp.getLogsBlocksLimit = + params.count( "getLogsBlocksLimit" ) ? params.at( "getLogsBlocksLimit" ).get_int() : -1; if ( obj.count( c_skaleConfig ) ) { diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 6b6d530b4..cf1f564ae 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -212,6 +212,9 @@ LocalisedLogEntries ClientBase::logs( LogFilter const& _f ) const { unsigned begin = min( bc().number() + 1, ( unsigned ) _f.latest() ); unsigned end = min( bc().number(), min( begin, ( unsigned ) _f.earliest() ) ); + if ( begin >= end && begin - end > bc().chainParams().getLogsBlocksLimit ) + BOOST_THROW_EXCEPTION( TooBigResponse() ); + // Handle pending transactions differently as they're not on the block chain. if ( begin > bc().number() ) { Block temp = postSeal(); @@ -343,18 +346,6 @@ bool ClientBase::uninstallWatch( unsigned _i ) { return true; } -LocalisedLogEntries ClientBase::peekWatch( unsigned _watchId ) const { - Guard l( x_filtersWatches ); - - // LOG(m_loggerWatch) << "peekWatch" << _watchId; - auto& w = m_watches.at( _watchId ); - // LOG(m_loggerWatch) << "lastPoll updated to " << - // chrono::duration_cast(chrono::system_clock::now().time_since_epoch()).count(); - if ( w.lastPoll != chrono::system_clock::time_point::max() ) - w.lastPoll = chrono::system_clock::now(); - return w.get_changes(); -} - LocalisedLogEntries ClientBase::checkWatch( unsigned _watchId ) { Guard l( x_filtersWatches ); LocalisedLogEntries ret; diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index ab4b7a812..338bc0e71 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -114,7 +114,6 @@ class ClientBase : public Interface { fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(), bool isWS = false ) override; bool uninstallWatch( unsigned _watchId ) override; - LocalisedLogEntries peekWatch( unsigned _watchId ) const override; LocalisedLogEntries checkWatch( unsigned _watchId ) override; h256 hashFromNumber( BlockNumber _number ) const override; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index a6c1c874f..7ee5d0e26 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -154,13 +154,6 @@ class Interface { fnClientWatchHandlerMulti_t fnOnNewChanges = fnClientWatchHandlerMulti_t(), bool isWS = false ) = 0; virtual bool uninstallWatch( unsigned _watchId ) = 0; - LocalisedLogEntries peekWatchSafe( unsigned _watchId ) const { - try { - return peekWatch( _watchId ); - } catch ( ... ) { - return LocalisedLogEntries(); - } - } LocalisedLogEntries checkWatchSafe( unsigned _watchId ) { try { return checkWatch( _watchId ); @@ -168,7 +161,6 @@ class Interface { return LocalisedLogEntries(); } } - virtual LocalisedLogEntries peekWatch( unsigned _watchId ) const = 0; virtual LocalisedLogEntries checkWatch( unsigned _watchId ) = 0; // [BLOCK QUERY API] @@ -328,7 +320,6 @@ class Watch : public boost::noncopyable { } LocalisedLogEntries check() { return m_c ? m_c->checkWatch( m_id ) : LocalisedLogEntries(); } - LocalisedLogEntries peek() { return m_c ? m_c->peekWatch( m_id ) : LocalisedLogEntries(); } LocalisedLogEntries logs() const { return m_c->logs( m_id ); } private: diff --git a/libskutils/include/skutils/console_colors.h b/libskutils/include/skutils/console_colors.h index 36808e1ed..fdce082ff 100644 --- a/libskutils/include/skutils/console_colors.h +++ b/libskutils/include/skutils/console_colors.h @@ -438,12 +438,13 @@ extern bool string2duration( const std::string& s, std::chrono::duration< uint64 const std::chrono::seconds& seconds = std::chrono::seconds::zero() ); extern std::string duration2string( std::chrono::nanoseconds time ); extern std::string time2string( - std::time_t tt, uint64_t nMicroSeconds, bool isUTC = false, bool isColored = true ); -extern std::string time2string( const std::tm& aTm, uint64_t nMicroSeconds, bool isColored = true ); + std::time_t tt, uint64_t nMicroSeconds, bool isUTC = false, bool isColored = false ); +extern std::string time2string( + const std::tm& aTm, uint64_t nMicroSeconds, bool isColored = false ); extern std::string time2string( const default_clock_t::time_point& ptTime, bool isUTC = false, - bool isDaysInsteadOfYMD = false, bool isColored = true ); + bool isDaysInsteadOfYMD = false, bool isColored = false ); extern std::string now2string( - bool isUTC = false, bool isDaysInsteadOfYMD = false, bool isColored = true ); + bool isUTC = false, bool isDaysInsteadOfYMD = false, bool isColored = false ); extern std::string jsNow2string( bool isUTC = true ); inline std::string c() { diff --git a/libskutils/src/console_colors.cpp b/libskutils/src/console_colors.cpp index 042d4be3e..27969977d 100644 --- a/libskutils/src/console_colors.cpp +++ b/libskutils/src/console_colors.cpp @@ -1185,12 +1185,12 @@ std::string duration2string( std::chrono::nanoseconds time ) { } std::string time2string( - std::time_t tt, uint64_t nMicroSeconds, bool isUTC, bool isColored /*= true*/ ) { + std::time_t tt, uint64_t nMicroSeconds, bool isUTC, bool isColored /*= false*/ ) { std::lock_guard< std::mutex > lock( g_libcall_mutex ); struct std::tm aTm = isUTC ? ( *std::gmtime( &tt ) ) : ( *std::localtime( &tt ) ); return time2string( aTm, nMicroSeconds, isColored ); } -std::string time2string( const std::tm& aTm, uint64_t nMicroSeconds, bool isColored /*= true*/ ) { +std::string time2string( const std::tm& aTm, uint64_t nMicroSeconds, bool isColored /*= false*/ ) { const std::tm& effective_tm = aTm; std::stringstream ss; ss << std::setfill( '0' ); @@ -1255,7 +1255,7 @@ inline time_t clock_2_time_t( const typename clock_type_t::time_point& ptTime ) } std::string time2string( const default_clock_t::time_point& ptTime, bool isUTC, - bool isDaysInsteadOfYMD, bool isColored /*= true*/ ) { + bool isDaysInsteadOfYMD, bool isColored /*= false*/ ) { std::stringstream ss; typedef std::chrono::duration< int, std::ratio_multiply< std::chrono::hours::period, std::ratio< 24 > >::type > @@ -1363,7 +1363,7 @@ std::string time2string( const default_clock_t::time_point& ptTime, bool isUTC, std::string s = ss.str(); return s; } -std::string now2string( bool isUTC, bool isDaysInsteadOfYMD, bool isColored /*= true*/ ) { +std::string now2string( bool isUTC, bool isDaysInsteadOfYMD, bool isColored /*= false*/ ) { default_clock_t::time_point ptTimeNow = default_clock_t::now(); std::string s = time2string( ptTimeNow, isUTC, isDaysInsteadOfYMD, isColored ); return s; diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index dad59ce88..bfdf04017 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -505,11 +505,9 @@ string Eth::eth_call( TransactionSkeleton& t, string const& if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; std::string strTx = t.toString(); - std::string strOut = cc::fatal( "Error message from eth_call():" ) + cc::error( " " ) + - cc::warn( strRevertReason ) + cc::error( ", with call arguments: " ) + - cc::j( strTx ) + cc::error( ", and using " ) + - cc::info( "blockNumber" ) + cc::error( "=" ) + - cc::bright( blockNumber ); + std::string strOut = "Error message from eth_call(): " + strRevertReason + + ", with call arguments: " + strTx + + ", and using blockNumber=" + blockNumber; cerror << strOut; throw std::logic_error( strRevertReason ); } @@ -833,6 +831,10 @@ Json::Value Eth::eth_getFilterChangesEx( string const& _filterId ) { Json::Value Eth::eth_getFilterLogs( string const& _filterId ) { try { return toJson( client()->logs( static_cast< unsigned int >( jsToInt( _filterId ) ) ) ); + } catch ( const TooBigResponse& ) { + BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, + "Log response size exceeded. Maximum allowed number of requested blocks is " + + to_string( this->client()->chainParams().getLogsBlocksLimit ) ) ); } catch ( ... ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); } @@ -850,6 +852,10 @@ Json::Value Eth::eth_getFilterLogs( string const& _filterId ) { Json::Value Eth::eth_getLogs( Json::Value const& _json ) { try { return toJson( client()->logs( toLogFilter( _json ) ) ); + } catch ( const TooBigResponse& ) { + BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, + "Log response size exceeded. Maximum allowed number of requested blocks is " + + to_string( this->client()->chainParams().getLogsBlocksLimit ) ) ); } catch ( ... ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 7673c9282..fff9ddf3a 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -830,7 +830,7 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { // function f(uint a) returns(uint d) { return a * 7; } // } - string compiled = + string compiled = "6080604052341561000f57600080fd5b60b98061001d6000396000f300" "608060405260043610603f576000357c01000000000000000000000000" "00000000000000000000000000000000900463ffffffff168063b3de64" @@ -2012,8 +2012,8 @@ contract TestEstimateGas { dev::bytes data = dev::jsToBytes( estimateGasCall["data"].asString() ); BOOST_REQUIRE( dev::jsToU256( estimatedGas ) > dev::eth::TransactionBase::baseGasRequired( - false, &data, fixture.client->chainParams().scheduleForBlockNumber( - fixture.client->number() ) ) ); + false, &data, fixture.client->chainParams().makeEvmSchedule( + fixture.client->latestBlock().info().timestamp(), fixture.client->number() ) ) ); // try to send with this gas estimateGasCall["gas"] = toJS( jsToInt( estimatedGas ) ); @@ -3354,7 +3354,7 @@ BOOST_AUTO_TEST_CASE( cached_filestorage ) { auto _config = c_genesisConfigString; Json::Value ret; Json::Reader().parse( _config, ret ); - ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; + ret["skaleConfig"]["sChain"]["revertableFSPatchTimestamp"] = 1; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); RestrictedAddressFixture fixture( config ); From 850eed87795b8ed1a1d26910a910842c26914ffe Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 2 May 2024 21:09:41 +0100 Subject: [PATCH 02/16] SKALED-1877 Add blockHash support --- libweb3jsonrpc/Eth.cpp | 15 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 164 ++++++++++++++++++++-- 2 files changed, 167 insertions(+), 12 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index bfdf04017..b32e3205c 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -851,11 +851,24 @@ Json::Value Eth::eth_getFilterLogs( string const& _filterId ) { Json::Value Eth::eth_getLogs( Json::Value const& _json ) { try { - return toJson( client()->logs( toLogFilter( _json ) ) ); + LogFilter filter = toLogFilter( _json ); + if ( !_json["blockHash"].isNull() ) { + if ( !_json["fromBlock"].isNull() || !_json["toBlock"].isNull() ) + BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, + "fromBlock and toBlock are not allowed if blockHash is present" ) ); + string strHash = _json["blockHash"].asString(); + uint64_t number = m_eth.numberFromHash( jsToFixed< 32 >( strHash ) ); + if ( number == PendingBlock ) + return toJson( LocalisedLogEntries() ); + filter.withEarliest( number ).withLatest( number ); + } + return toJson( client()->logs( filter ) ); } catch ( const TooBigResponse& ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, "Log response size exceeded. Maximum allowed number of requested blocks is " + to_string( this->client()->chainParams().getLogsBlocksLimit ) ) ); + } catch ( const JsonRpcException& ) { + throw; } catch ( ... ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index fff9ddf3a..2f8311731 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -254,7 +254,8 @@ ChainParams chainParams; JsonRpcFixture( const std::string& _config = "", bool _owner = true, bool _deploymentControl = true, bool _generation2 = false, - bool _mtmEnabled = false, bool _isSyncNode = false, int _emptyBlockIntervalMs = -1 ) { + bool _mtmEnabled = false, bool _isSyncNode = false, int _emptyBlockIntervalMs = -1, + const std::map& params = std::map() ) { if ( _config != "" ) { @@ -303,6 +304,10 @@ JsonRpcFixture( const std::string& _config = "", bool _owner = true, chainParams.extraData = h256::random().asBytes(); chainParams.nodeInfo.port = chainParams.nodeInfo.port6 = rand_port; chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port; + chainParams.skaleDisableChainIdCheck = true; + + if( params.count("getLogsBlocksLimit") && stoi( params.at( "getLogsBlocksLimit" ) ) ) + chainParams.getLogsBlocksLimit = stoi( params.at( "getLogsBlocksLimit" ) ); } chainParams.sChain.multiTransactionMode = _mtmEnabled; chainParams.nodeInfo.syncNode = _isSyncNode; @@ -825,20 +830,38 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); - + // pragma solidity 0.8.4; // contract test { - // function f(uint a) returns(uint d) { return a * 7; } + // uint value; + // function f(uint a) public pure returns(uint d) { + // return a * 7; + // } + // function setValue(uint _value) external { + // value = _value; + // } // } string compiled = - "6080604052341561000f57600080fd5b60b98061001d6000396000f300" - "608060405260043610603f576000357c01000000000000000000000000" - "00000000000000000000000000000000900463ffffffff168063b3de64" - "8b146044575b600080fd5b3415604e57600080fd5b606a600480360381" - "019080803590602001909291905050506080565b604051808281526020" - "0191505060405180910390f35b60006007820290509190505600a16562" - "7a7a72305820f294e834212334e2978c6dd090355312a3f0f9476b8eb9" - "8fb480406fc2728a960029"; + "608060405234801561001057600080fd5b506101ef8061002060003" + "96000f3fe608060405234801561001057600080fd5b506004361061" + "00365760003560e01c8063552410771461003b578063b3de648b146" + "10057575b600080fd5b610055600480360381019061005091906100" + "bc565b610087565b005b610071600480360381019061006c9190610" + "0bc565b610091565b60405161007e91906100f4565b604051809103" + "90f35b8060008190555050565b60006007826100a0919061010f565" + "b9050919050565b6000813590506100b6816101a2565b9291505056" + "5b6000602082840312156100ce57600080fd5b60006100dc8482850" + "16100a7565b91505092915050565b6100ee81610169565b82525050" + "565b600060208201905061010960008301846100e5565b929150505" + "65b600061011a82610169565b915061012583610169565b9250817f" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffff048311821515161561015e5761015d610173565b5b8282" + "02905092915050565b6000819050919050565b7f4e487b710000000" + "0000000000000000000000000000000000000000000000000600052" + "601160045260246000fd5b6101ab81610169565b81146101b657600" + "080fd5b5056fea26469706673582212200be8156151b5ef7c250fa7" + "b8c8ed4e2a1c32cd526f9c868223f6838fa1193c9e64736f6c63430" + "008040033"; Json::Value create; create["code"] = compiled; @@ -865,6 +888,31 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { string result = fixture.rpcClient->eth_call( call, "latest" ); BOOST_CHECK_EQUAL( result, "0x0000000000000000000000000000000000000000000000000000000000000007" ); + + Json::Value inputCall; + inputCall["to"] = contractAddress; + inputCall["input"] = "0xb3de648b0000000000000000000000000000000000000000000000000000000000000001"; + inputCall["gas"] = "1000000"; + inputCall["gasPrice"] = "0"; + result = fixture.rpcClient->eth_call( inputCall, "latest" ); + BOOST_CHECK_EQUAL( + result, "0x0000000000000000000000000000000000000000000000000000000000000007" ); + + Json::Value transact; + transact["to"] = contractAddress; + transact["data"] = "0x552410770000000000000000000000000000000000000000000000000000000000000001"; + txHash = fixture.rpcClient->eth_sendTransaction( transact ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + auto res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); + + Json::Value inputTx; + inputTx["to"] = contractAddress; + inputTx["input"] = "0x552410770000000000000000000000000000000000000000000000000000000000000002"; + txHash = fixture.rpcClient->eth_sendTransaction( inputTx ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); } /* @@ -1958,6 +2006,100 @@ contract Logger{ BOOST_REQUIRE_EQUAL(logs.size(), 24); } +// limit on getLogs output +BOOST_AUTO_TEST_CASE( getLogs_limit ) { + JsonRpcFixture fixture( "", true, true, false, false, false, -1, + {{"getLogsBlocksLimit", "10"}} ); + + dev::eth::simulateMining( *( fixture.client ), 1 ); + + /* + // SPDX-License-Identifier: None +pragma solidity ^0.8; +contract Logger{ + event DummyEvent(uint256, uint256); + fallback() external payable { + for(uint i=0; i<100; ++i) + emit DummyEvent(block.number, i); + } +} +*/ + + string bytecode = "6080604052348015600e575f80fd5b5060c080601a5f395ff3fe60806040525f5b6064811015604f577f90778767414a5c844b9d35a8745f67697ee3b8c2c3f4feafe5d9a3e234a5a3654382604051603d9291906067565b60405180910390a18060010190506006565b005b5f819050919050565b6061816051565b82525050565b5f60408201905060785f830185605a565b60836020830184605a565b939250505056fea264697066735822122040208e35f2706dd92c17579466ab671c308efec51f558a755ea2cf81105ab22964736f6c63430008190033"; + + Json::Value create; + create["code"] = bytecode; + create["gas"] = "180000"; // TODO or change global default of 90000? + + string deployHash = fixture.rpcClient->eth_sendTransaction( create ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value deployReceipt = fixture.rpcClient->eth_getTransactionReceipt( deployHash ); + string contractAddress = deployReceipt["contractAddress"].asString(); + + // generate 10 blocks 10 logs each + + Json::Value t; + t["from"] = toJS( fixture.coinbase.address() ); + t["value"] = jsToDecimal( "0" ); + t["to"] = contractAddress; + t["gas"] = "99000"; + + for(int i=0; i<11; ++i){ + + std::string txHash = fixture.rpcClient->eth_sendTransaction( t ); + BOOST_REQUIRE( !txHash.empty() ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); + } + + // ask for logs + Json::Value req; + req["fromBlock"] = 1; + req["toBlock"] = 11; + req["topics"] = Json::Value(Json::arrayValue); + + // 1 10 blocks + BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); + + // 2 with topics + req["address"] = contractAddress; + BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); + + // 3 11 blocks + req["toBlock"] = 12; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + + // 4 filter + string filterId = fixture.rpcClient->eth_newFilter( req ); + BOOST_REQUIRE_THROW( Json::Value res = fixture.rpcClient->eth_getFilterLogs(filterId), std::exception ); + BOOST_REQUIRE_NO_THROW( Json::Value res = fixture.rpcClient->eth_getFilterChanges(filterId) ); +} + +// test blockHash parameter +BOOST_AUTO_TEST_CASE( getLogs_blockHash ) { + JsonRpcFixture fixture; + dev::eth::simulateMining( *( fixture.client ), 1 ); + + Json::Value req; + req["blockHash"] = "xyz"; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + + req["fromBlock"] = 1; + req["toBlock"] = 1; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + + req.removeMember("fromBlock"); + req.removeMember("toBlock"); + req["blockHash"] = "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"; + BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); + + string hash = fixture.rpcClient->eth_getBlockByNumber("latest", false)["hash"].asString(); + req["blockHash"] = hash; + BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); +} + BOOST_AUTO_TEST_CASE( estimate_gas_low_gas_txn ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 10 ); From 31be37f16f728ce8a182b46956cf518877218a4a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 3 May 2024 15:13:47 +0100 Subject: [PATCH 03/16] SKALED-1877 Fix wrong filter range --- libweb3jsonrpc/Eth.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index b32e3205c..5fb1b7516 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -860,7 +860,8 @@ Json::Value Eth::eth_getLogs( Json::Value const& _json ) { uint64_t number = m_eth.numberFromHash( jsToFixed< 32 >( strHash ) ); if ( number == PendingBlock ) return toJson( LocalisedLogEntries() ); - filter.withEarliest( number ).withLatest( number ); + filter.withEarliest( number ); + filter.withLatest( number ); } return toJson( client()->logs( filter ) ); } catch ( const TooBigResponse& ) { From d8edbd255abdadb5afdebaa4ec8d466deb627511 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 3 May 2024 18:39:23 +0100 Subject: [PATCH 04/16] SKALED-1877 Throw if blockHash doesn't exist or empty --- libweb3jsonrpc/Eth.cpp | 6 +++++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 5fb1b7516..55ed1a2c4 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -857,9 +857,13 @@ Json::Value Eth::eth_getLogs( Json::Value const& _json ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, "fromBlock and toBlock are not allowed if blockHash is present" ) ); string strHash = _json["blockHash"].asString(); + if ( strHash.empty() ) + throw std::invalid_argument( "blockHash cannot be an empty string" ); uint64_t number = m_eth.numberFromHash( jsToFixed< 32 >( strHash ) ); if ( number == PendingBlock ) - return toJson( LocalisedLogEntries() ); + BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS, + "A block with this hash does not exist in the database. If this is an old " + "block, try connecting to an archive node" ) ); filter.withEarliest( number ); filter.withLatest( number ); } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 2f8311731..b8b61ff62 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2082,22 +2082,31 @@ BOOST_AUTO_TEST_CASE( getLogs_blockHash ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); + string latestHash = fixture.rpcClient->eth_getBlockByNumber("latest", false)["hash"].asString(); + Json::Value req; req["blockHash"] = "xyz"; BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + req["blockHash"] = Json::Value(Json::arrayValue); + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + req["fromBlock"] = 1; req["toBlock"] = 1; BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + req["blockHash"] = latestHash; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + req.removeMember("fromBlock"); req.removeMember("toBlock"); - req["blockHash"] = "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"; BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); - string hash = fixture.rpcClient->eth_getBlockByNumber("latest", false)["hash"].asString(); - req["blockHash"] = hash; - BOOST_REQUIRE_NO_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req) ); + req["blockHash"] = "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); + + req["blockHash"] = ""; + BOOST_REQUIRE_THROW( Json::Value logs = fixture.rpcClient->eth_getLogs(req), std::exception ); } BOOST_AUTO_TEST_CASE( estimate_gas_low_gas_txn ) { From 5c6e5fca92ff825a27441788c57595493daab4ed Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 22 May 2024 15:57:44 +0100 Subject: [PATCH 05/16] Cherry-pick commits --- libethcore/ChainOperationParams.h | 1 + libethereum/ChainParams.cpp | 1 - libethereum/ClientBase.h | 4 +- libweb3jsonrpc/Eth.cpp | 2 +- libweb3jsonrpc/Eth.h | 8 +-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 64 ++++++----------------- 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index b6e182d65..032e9cbc2 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -257,6 +257,7 @@ struct ChainOperationParams { u256 externalGasDifficulty = ~u256( 0 ); typedef std::vector< std::string > vecAdminOrigins_t; vecAdminOrigins_t vecAdminOrigins; // wildcard based folters for IP addresses + int getLogsBlocksLimit = -1; }; } // namespace eth diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index fa7c4d1cc..a7051c5a8 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -107,7 +107,6 @@ ChainParams ChainParams::loadConfig( cp.getLogsBlocksLimit = params.count( "getLogsBlocksLimit" ) ? params.at( "getLogsBlocksLimit" ).get_int() : -1; - if ( obj.count( c_skaleConfig ) ) { processSkaleConfigItems( cp, obj ); } diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 338bc0e71..065aa2c76 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -92,7 +92,7 @@ class ClientBase : public Interface { /// @param _callback Optional callback function for progress reporting std::pair< u256, ExecutionResult > estimateGas( Address const& _from, u256 _value, Address _dest, bytes const& _data, int64_t _maxGas, u256 _gasPrice, - GasEstimationCallback const& _callback ) override; + GasEstimationCallback const& _callback = GasEstimationCallback() ) override; u256 balanceAt( Address _a ) const override; u256 countAt( Address _a ) const override; @@ -136,6 +136,7 @@ class ClientBase : public Interface { return transactions( hashFromNumber( _block ) ); } TransactionHashes transactionHashes( h256 _blockHash ) const override; + using Interface::uncle; BlockHeader uncle( h256 _blockHash, unsigned _i ) const override; UncleHashes uncleHashes( h256 _blockHash ) const override; unsigned transactionCount( h256 _blockHash ) const override; @@ -146,6 +147,7 @@ class ClientBase : public Interface { } return transactionCount( hashFromNumber( _block ) ); } + using Interface::uncleCount; unsigned uncleCount( h256 _blockHash ) const override; unsigned number() const override; h256s pendingHashes() const override; diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 55ed1a2c4..f3e872751 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -132,7 +132,7 @@ bool hasPotentialInvalidTransactionsInBlock( BlockNumber _bn, const Interface& _ #endif -Eth::Eth( const std::string& configPath, eth::Interface& _eth, eth::AccountHolder& _ethAccounts ) +Eth::Eth( const std::string& configPath, eth::Client& _eth, eth::AccountHolder& _ethAccounts ) : skutils::json_config_file_accessor( configPath ), m_eth( _eth ), m_ethAccounts( _ethAccounts ), diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index 8059860d7..b7584084c 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -43,7 +43,7 @@ class KeyPair; namespace eth { class AccountHolder; struct TransactionSkeleton; -class Interface; +class Client; class LocalisedTransactionReceipt; } // namespace eth } // namespace dev @@ -135,7 +135,7 @@ std::string exceptionToErrorMessage(); */ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor { public: - Eth( const std::string& configPath, eth::Interface& _eth, eth::AccountHolder& _ethAccounts ); + Eth( const std::string& configPath, eth::Client& _eth, eth::AccountHolder& _ethAccounts ); virtual RPCModules implementedModules() const override { return RPCModules{ RPCModule{ "eth", "1.0" } }; @@ -220,9 +220,9 @@ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor void setTransactionDefaults( eth::TransactionSkeleton& _t ); protected: - eth::Interface* client() { return &m_eth; } + eth::Client* client() { return &m_eth; } - eth::Interface& m_eth; + eth::Client& m_eth; eth::AccountHolder& m_ethAccounts; // a cache that maps the call request to the pair of response string and block number diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index b8b61ff62..bea9e2026 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -830,38 +830,20 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); - // pragma solidity 0.8.4; + // contract test { - // uint value; - // function f(uint a) public pure returns(uint d) { - // return a * 7; - // } - // function setValue(uint _value) external { - // value = _value; - // } + // function f(uint a) returns(uint d) { return a * 7; } // } - string compiled = - "608060405234801561001057600080fd5b506101ef8061002060003" - "96000f3fe608060405234801561001057600080fd5b506004361061" - "00365760003560e01c8063552410771461003b578063b3de648b146" - "10057575b600080fd5b610055600480360381019061005091906100" - "bc565b610087565b005b610071600480360381019061006c9190610" - "0bc565b610091565b60405161007e91906100f4565b604051809103" - "90f35b8060008190555050565b60006007826100a0919061010f565" - "b9050919050565b6000813590506100b6816101a2565b9291505056" - "5b6000602082840312156100ce57600080fd5b60006100dc8482850" - "16100a7565b91505092915050565b6100ee81610169565b82525050" - "565b600060208201905061010960008301846100e5565b929150505" - "65b600061011a82610169565b915061012583610169565b9250817f" - "fffffffffffffffffffffffffffffffffffffffffffffffffffffff" - "fffffffff048311821515161561015e5761015d610173565b5b8282" - "02905092915050565b6000819050919050565b7f4e487b710000000" - "0000000000000000000000000000000000000000000000000600052" - "601160045260246000fd5b6101ab81610169565b81146101b657600" - "080fd5b5056fea26469706673582212200be8156151b5ef7c250fa7" - "b8c8ed4e2a1c32cd526f9c868223f6838fa1193c9e64736f6c63430" - "008040033"; + string compiled = + "6080604052341561000f57600080fd5b60b98061001d6000396000f300" + "608060405260043610603f576000357c01000000000000000000000000" + "00000000000000000000000000000000900463ffffffff168063b3de64" + "8b146044575b600080fd5b3415604e57600080fd5b606a600480360381" + "019080803590602001909291905050506080565b604051808281526020" + "0191505060405180910390f35b60006007820290509190505600a16562" + "7a7a72305820f294e834212334e2978c6dd090355312a3f0f9476b8eb9" + "8fb480406fc2728a960029"; Json::Value create; create["code"] = compiled; @@ -869,8 +851,8 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { BOOST_CHECK_EQUAL( jsToU256( fixture.rpcClient->eth_blockNumber() ), 1 ); BOOST_CHECK_EQUAL( jsToU256( fixture.rpcClient->eth_getTransactionCount( - toJS( fixture.coinbase.address() ), "latest" ) ), - 0 ); + toJS( fixture.coinbase.address() ), "latest" ) ), + 0 ); string txHash = fixture.rpcClient->eth_sendTransaction( create ); dev::eth::mineTransaction( *( fixture.client ), 1 ); @@ -891,28 +873,13 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { Json::Value inputCall; inputCall["to"] = contractAddress; - inputCall["input"] = "0xb3de648b0000000000000000000000000000000000000000000000000000000000000001"; + inputCall["data"] = "0xb3de648b0000000000000000000000000000000000000000000000000000000000000001"; inputCall["gas"] = "1000000"; inputCall["gasPrice"] = "0"; result = fixture.rpcClient->eth_call( inputCall, "latest" ); BOOST_CHECK_EQUAL( result, "0x0000000000000000000000000000000000000000000000000000000000000007" ); - Json::Value transact; - transact["to"] = contractAddress; - transact["data"] = "0x552410770000000000000000000000000000000000000000000000000000000000000001"; - txHash = fixture.rpcClient->eth_sendTransaction( transact ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - auto res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); - - Json::Value inputTx; - inputTx["to"] = contractAddress; - inputTx["input"] = "0x552410770000000000000000000000000000000000000000000000000000000000000002"; - txHash = fixture.rpcClient->eth_sendTransaction( inputTx ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - res = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL( res["status"], string( "0x1" ) ); } /* @@ -2163,8 +2130,7 @@ contract TestEstimateGas { dev::bytes data = dev::jsToBytes( estimateGasCall["data"].asString() ); BOOST_REQUIRE( dev::jsToU256( estimatedGas ) > dev::eth::TransactionBase::baseGasRequired( - false, &data, fixture.client->chainParams().makeEvmSchedule( - fixture.client->latestBlock().info().timestamp(), fixture.client->number() ) ) ); + false, &data, EVMSchedule() ) ); // try to send with this gas estimateGasCall["gas"] = toJS( jsToInt( estimatedGas ) ); From 6a9203acc48fe712925aadb31d22884be1a0a325 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 22 May 2024 18:17:44 +0100 Subject: [PATCH 06/16] Fix build --- libethereum/ClientBase.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 065aa2c76..45e3e2f30 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -116,6 +116,14 @@ class ClientBase : public Interface { bool uninstallWatch( unsigned _watchId ) override; LocalisedLogEntries checkWatch( unsigned _watchId ) override; + + using Interface::blockDetails; + using Interface::blockInfo; // for another overload + using Interface::transactionHashes; + using Interface::uncle; + using Interface::uncleCount; + using Interface::uncleHashes; + h256 hashFromNumber( BlockNumber _number ) const override; BlockNumber numberFromHash( h256 _blockHash ) const override; int compareBlockHashes( h256 _h1, h256 _h2 ) const override; @@ -136,7 +144,6 @@ class ClientBase : public Interface { return transactions( hashFromNumber( _block ) ); } TransactionHashes transactionHashes( h256 _blockHash ) const override; - using Interface::uncle; BlockHeader uncle( h256 _blockHash, unsigned _i ) const override; UncleHashes uncleHashes( h256 _blockHash ) const override; unsigned transactionCount( h256 _blockHash ) const override; @@ -147,7 +154,6 @@ class ClientBase : public Interface { } return transactionCount( hashFromNumber( _block ) ); } - using Interface::uncleCount; unsigned uncleCount( h256 _blockHash ) const override; unsigned number() const override; h256s pendingHashes() const override; From 16519fbb7bbd8e774d2f333ec1fea8dfebda817e Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 22 May 2024 19:20:18 +0100 Subject: [PATCH 07/16] Fix random in test --- test/unittests/libethereum/ClientTest.cpp | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 81781fa7c..746e92c85 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -39,7 +39,7 @@ using namespace dev::test; using namespace dev::p2p; namespace fs = boost::filesystem; -static size_t rand_port = 1024 + rand() % 64000; +static size_t rand_port = ( srand(time(nullptr)), 1024 + rand() % 64000 ); struct FixtureCommon { const string BTRFS_FILE_PATH = "btrfs.file"; diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index bea9e2026..43fc14b5b 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -62,7 +62,7 @@ using namespace dev; using namespace dev::eth; using namespace dev::test; -static size_t rand_port = 1024 + rand() % 64000; +static size_t rand_port = ( srand(time(nullptr)), 1024 + rand() % 64000 ); static std::string const c_genesisConfigString = R"( From 1ccff34555dc99cf865fe23bc8e4554e5259a2c5 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 23 May 2024 17:20:21 +0100 Subject: [PATCH 08/16] Fix tests --- libskale/httpserveroverride.cpp | 6 ++++-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libskale/httpserveroverride.cpp b/libskale/httpserveroverride.cpp index f76c94c69..be29eecef 100644 --- a/libskale/httpserveroverride.cpp +++ b/libskale/httpserveroverride.cpp @@ -2607,12 +2607,14 @@ bool SkaleServerOverride::implStartListening( // proxygen HTTP cc::success( "/" ) + cc::notice( esm2str( esm ) ) + " " ); return true; } catch ( const std::exception& ex ) { - logTraceServerEvent( false, ipVer, bIsSSL ? "HTTPS" : "HTTP", pSrv->serverIndex(), esm, + logTraceServerEvent( false, ipVer, bIsSSL ? "HTTPS" : "HTTP", + pSrv ? pSrv->serverIndex() : -1, esm, cc::fatal( "FAILED" ) + cc::error( " to start " ) + cc::attention( "proxygen" ) + cc::debug( "/" ) + cc::warn( bIsSSL ? "HTTPS" : "HTTP" ) + cc::error( " server: " ) + cc::warn( ex.what() ) ); } catch ( ... ) { - logTraceServerEvent( false, ipVer, bIsSSL ? "HTTPS" : "HTTP", pSrv->serverIndex(), esm, + logTraceServerEvent( false, ipVer, bIsSSL ? "HTTPS" : "HTTP", + pSrv ? pSrv->serverIndex() : -1, esm, cc::fatal( "FAILED" ) + cc::error( " to start " ) + cc::attention( "proxygen" ) + cc::debug( "/" ) + cc::warn( bIsSSL ? "HTTPS" : "HTTP" ) + cc::error( " server: " ) + cc::warn( "unknown exception" ) ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 43fc14b5b..b174aab40 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -376,7 +376,8 @@ JsonRpcFixture( const std::string& _config = "", bool _owner = true, serverOpts.netOpts_.bindOptsStandard_.cntServers_ = 1; serverOpts.netOpts_.bindOptsStandard_.strAddrHTTP4_ = chainParams.nodeInfo.ip; // random port - serverOpts.netOpts_.bindOptsStandard_.nBasePortHTTP4_ = std::rand() % 64000 + 1025; + // +3 because rand() seems to be called effectively simultaneously here and in "static" section - thus giving same port for consensus + serverOpts.netOpts_.bindOptsStandard_.nBasePortHTTP4_ = std::rand() % 64000 + 1025 + 3; std::cout << "PORT: " << serverOpts.netOpts_.bindOptsStandard_.nBasePortHTTP4_ << std::endl; skale_server_connector = new SkaleServerOverride( chainParams, client.get(), serverOpts ); rpcServer->addConnector( skale_server_connector ); From 09624d5d6b4ce1e593c6e9d35ae5633dee067029 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 24 May 2024 15:56:37 +0100 Subject: [PATCH 09/16] Fix test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index b174aab40..c2e286854 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -872,15 +872,6 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { BOOST_CHECK_EQUAL( result, "0x0000000000000000000000000000000000000000000000000000000000000007" ); - Json::Value inputCall; - inputCall["to"] = contractAddress; - inputCall["data"] = "0xb3de648b0000000000000000000000000000000000000000000000000000000000000001"; - inputCall["gas"] = "1000000"; - inputCall["gasPrice"] = "0"; - result = fixture.rpcClient->eth_call( inputCall, "latest" ); - BOOST_CHECK_EQUAL( - result, "0x0000000000000000000000000000000000000000000000000000000000000007" ); - } /* @@ -2131,7 +2122,7 @@ contract TestEstimateGas { dev::bytes data = dev::jsToBytes( estimateGasCall["data"].asString() ); BOOST_REQUIRE( dev::jsToU256( estimatedGas ) > dev::eth::TransactionBase::baseGasRequired( - false, &data, EVMSchedule() ) ); + false, &data, fixture.chainParams.scheduleForBlockNumber(1) ) ); // try to send with this gas estimateGasCall["gas"] = toJS( jsToInt( estimatedGas ) ); From 4805b84874963df0c039b67dec1c4fb020ae24b5 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 24 May 2024 17:21:42 +0100 Subject: [PATCH 10/16] Cosmetic changes --- VERSION | 2 +- libethereum/ClientBase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index d21858b11..9f6a62d00 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.18.1 +3.18.2 diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index cf1f564ae..e45075765 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -212,7 +212,7 @@ LocalisedLogEntries ClientBase::logs( LogFilter const& _f ) const { unsigned begin = min( bc().number() + 1, ( unsigned ) _f.latest() ); unsigned end = min( bc().number(), min( begin, ( unsigned ) _f.earliest() ) ); - if ( begin >= end && begin - end > bc().chainParams().getLogsBlocksLimit ) + if ( begin >= end && begin - end > (unsigned) bc().chainParams().getLogsBlocksLimit ) BOOST_THROW_EXCEPTION( TooBigResponse() ); // Handle pending transactions differently as they're not on the block chain. From c8c58e486465cb797c71976c9a0e2ec29ec59760 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 24 May 2024 18:10:08 +0100 Subject: [PATCH 11/16] Format --- libethereum/ClientBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index e45075765..72cd8506c 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -212,7 +212,7 @@ LocalisedLogEntries ClientBase::logs( LogFilter const& _f ) const { unsigned begin = min( bc().number() + 1, ( unsigned ) _f.latest() ); unsigned end = min( bc().number(), min( begin, ( unsigned ) _f.earliest() ) ); - if ( begin >= end && begin - end > (unsigned) bc().chainParams().getLogsBlocksLimit ) + if ( begin >= end && begin - end > ( unsigned ) bc().chainParams().getLogsBlocksLimit ) BOOST_THROW_EXCEPTION( TooBigResponse() ); // Handle pending transactions differently as they're not on the block chain. From bff6ece8baf7eb80d13dd6800cb8eba60515b12e Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 6 Jun 2024 18:19:05 +0100 Subject: [PATCH 12/16] bug 1911 eth feeHistory --- libweb3jsonrpc/Eth.cpp | 9 ++++----- libweb3jsonrpc/Eth.h | 2 +- libweb3jsonrpc/EthFace.h | 14 +++++++++----- .../libweb3jsonrpc/WebThreeStubClient.cpp | 9 ++++++--- test/unittests/libweb3jsonrpc/WebThreeStubClient.h | 4 +++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 ++ 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 11097c4fd..ba032a18a 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -962,7 +962,7 @@ Json::Value Eth::eth_createAccessList( return result; } -Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::string& _newestBlock, +Json::Value Eth::eth_feeHistory( dev::u256 _blockCount, const std::string& _newestBlock, const Json::Value& _rewardPercentiles ) { try { if ( !_rewardPercentiles.isArray() ) @@ -974,8 +974,7 @@ Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::stri } } - auto blockCount = jsToU256( _blockCount ); - if ( blockCount > MAX_BLOCK_RANGE ) + if ( _blockCount > MAX_BLOCK_RANGE ) throw std::runtime_error( "Max block range reached. Please try smaller blockCount." ); auto newestBlock = jsToBlockNumber( _newestBlock ); @@ -984,10 +983,10 @@ Json::Value Eth::eth_feeHistory( const std::string& _blockCount, const std::stri auto result = Json::Value( Json::objectValue ); dev::u256 oldestBlock; - if ( blockCount > newestBlock ) + if ( _blockCount > newestBlock ) oldestBlock = 1; else - oldestBlock = dev::u256( newestBlock ) - blockCount + 1; + oldestBlock = dev::u256( newestBlock ) - _blockCount + 1; result["oldestBlock"] = toJS( oldestBlock ); result["baseFeePerGas"] = Json::Value( Json::arrayValue ); diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index 2ecf0be5d..ae4c011f2 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -219,7 +219,7 @@ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor virtual Json::Value eth_createAccessList( const Json::Value& param1, const std::string& param2 ) override; virtual Json::Value eth_feeHistory( - const std::string& param1, const std::string& param2, const Json::Value& param3 ) override; + dev::u256 param1, const std::string& param2, const Json::Value& param3 ) override; virtual std::string eth_maxPriorityFeePerGas() override; void setTransactionDefaults( eth::TransactionSkeleton& _t ); diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index c87edf57b..a7f7991c8 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -7,6 +7,7 @@ #include "ModularServer.h" +#include #include #include @@ -222,8 +223,7 @@ class EthFace : public ServerInterface< EthFace > { jsonrpc::JSON_OBJECT, "param2", jsonrpc::JSON_STRING, NULL ), &dev::rpc::EthFace::eth_createAccessListI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_feeHistory", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_OBJECT, "param1", jsonrpc::JSON_STRING, "param2", - jsonrpc::JSON_STRING, "param3", jsonrpc::JSON_ARRAY, NULL ), + jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::EthFace::eth_feeHistoryI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_maxPriorityFeePerGas", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ), @@ -449,8 +449,12 @@ class EthFace : public ServerInterface< EthFace > { if ( !request.isArray() || request.size() != 3 ) BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); - response = - this->eth_feeHistory( request[0u].asString(), request[1u].asString(), request[2u] ); + if ( !request[0u].isString() && !request[0u].isUInt() ) + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); + auto blockCount = request[0u].isString() ? dev::jsToU256( request[0u].asString() ) : + dev::u256( request[0u].asUInt() ); + response = this->eth_feeHistory( blockCount, request[1u].asString(), request[2u] ); } inline virtual void eth_maxPriorityFeePerGasI( const Json::Value& request, Json::Value& response ) { @@ -525,7 +529,7 @@ class EthFace : public ServerInterface< EthFace > { virtual Json::Value eth_createAccessList( const Json::Value& param1, const std::string& param2 ) = 0; virtual Json::Value eth_feeHistory( - const std::string& param1, const std::string& param2, const Json::Value& param3 ) = 0; + dev::u256 param1, const std::string& param2, const Json::Value& param3 ) = 0; virtual std::string eth_maxPriorityFeePerGas() = 0; }; diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index 6891aacef..b37a52a91 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -841,10 +841,13 @@ Json::Value WebThreeStubClient::eth_createAccessList( const Json::Value& param1, throw jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); } - -Json::Value WebThreeStubClient::eth_feeHistory( const std::string& param1, const std::string& param2, const Json::Value& param3 ) { +#include +Json::Value WebThreeStubClient::eth_feeHistory( const Json::Value& param1, const std::string& param2, const Json::Value& param3 ) { Json::Value p; - p.append( param1 ); + if ( param1.isString() ) + p.append( param1.asString() ); + if ( param1.isUInt() ) + p.append( param1.asUInt() ); p.append( param2 ); p.append( param3 ); Json::Value result = this->CallMethod( "eth_feeHistory", p ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index 2be6ca519..9125b97ab 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -5,6 +5,8 @@ #ifndef JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ #define JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ +#include + #include class WebThreeStubClient : public jsonrpc::Client { @@ -98,7 +100,7 @@ class WebThreeStubClient : public jsonrpc::Client { std::string eth_sendRawTransaction( const std::string& param1 ) noexcept( false ); std::string eth_maxPriorityFeePerGas() noexcept( false ); Json::Value eth_createAccessList( const Json::Value& param1, const std::string& param2 ) noexcept( false ); - Json::Value eth_feeHistory( const std::string& param1, const std::string& param2, const Json::Value& param3 ) noexcept( false ); + Json::Value eth_feeHistory( const Json::Value& param1, const std::string& param2, const Json::Value& param3 ) noexcept( false ); bool eth_notePassword( const std::string& param1 ) noexcept( false ); bool db_put( const std::string& param1, const std::string& param2, const std::string& param3 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index c004aaf6d..aefed42db 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3226,6 +3226,8 @@ BOOST_AUTO_TEST_CASE( eip1559RpcMethods ) { BOOST_REQUIRE_EQUAL( feeHistory["reward"][i][j].asString(), toJS( 0 ) ); } } + + BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_feeHistory( blockCnt, "latest", percentiles ) ); } BOOST_AUTO_TEST_CASE( etherbase_generation2 ) { From 8cb6ecfa5488b5ed434e9549f78c7d451e8ffb56 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 6 Jun 2024 18:56:03 +0100 Subject: [PATCH 13/16] #1911 format --- test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index b37a52a91..c297164dc 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -841,7 +841,7 @@ Json::Value WebThreeStubClient::eth_createAccessList( const Json::Value& param1, throw jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); } -#include + Json::Value WebThreeStubClient::eth_feeHistory( const Json::Value& param1, const std::string& param2, const Json::Value& param3 ) { Json::Value p; if ( param1.isString() ) From cbda0bd6b2351db2a7eedafdcd24c88a96b06d3c Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 6 Jun 2024 19:48:31 +0100 Subject: [PATCH 14/16] #1911 fix unittests --- test/unittests/libethereum/ClientTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index ed9bdb878..9cc2e0b93 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -39,7 +39,7 @@ using namespace dev::test; using namespace dev::p2p; namespace fs = boost::filesystem; -static size_t rand_port = 1024 + rand() % 64000; +static size_t rand_port = ( srand(time(nullptr)), 1024 + rand() % 64000 ); struct FixtureCommon { const string BTRFS_FILE_PATH = "btrfs.file"; From a89f6d0d9c8bbd812f71f7f1f904cc086c6e811d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 11 Jun 2024 13:27:05 +0100 Subject: [PATCH 15/16] consensus 836 update consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index b1916ed05..9683c93ec 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit b1916ed05c3b77f5925662fa591b9a054290d0fd +Subproject commit 9683c93ec19d4dd28724d9ec2e105677360918d1 From e81939a4ca69eada2abfb3a66de77f9ec701cbb2 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 12 Jun 2024 13:45:42 +0100 Subject: [PATCH 16/16] 1774 revert hwm limits --- libskale/broadcaster.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libskale/broadcaster.cpp b/libskale/broadcaster.cpp index 195b055f9..20d15b232 100644 --- a/libskale/broadcaster.cpp +++ b/libskale/broadcaster.cpp @@ -97,8 +97,7 @@ void* ZmqBroadcaster::server_socket() const { val = 60000; zmq_setsockopt( m_zmq_server_socket, ZMQ_HEARTBEAT_TTL, &val, sizeof( val ) ); - // remove limits to prevent txns from being dropped out - val = 0; + val = 16; zmq_setsockopt( m_zmq_server_socket, ZMQ_SNDHWM, &val, sizeof( val ) ); @@ -132,7 +131,7 @@ void* ZmqBroadcaster::client_socket() const { value = 300; zmq_setsockopt( m_zmq_client_socket, ZMQ_TCP_KEEPALIVE_INTVL, &value, sizeof( value ) ); - value = 0; + value = 16; zmq_setsockopt( m_zmq_client_socket, ZMQ_RCVHWM, &value, sizeof( value ) ); const dev::eth::ChainParams& ch = m_client.chainParams();