From 3ecac21748341904c3d5591652051dcbec843455 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Sun, 28 Apr 2024 13:47:36 +0100 Subject: [PATCH 01/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] 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/24] #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/24] #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/24] 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 6bc6a2733673e19d0f07a5ff160f16fb94c361cb Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 11 Jun 2024 21:00:39 +0000 Subject: [PATCH 16/24] Add setup-build-publish workflow --- .github/workflows/setup-build-publish.yml | 160 ++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 .github/workflows/setup-build-publish.yml diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml new file mode 100644 index 000000000..a98e1562a --- /dev/null +++ b/.github/workflows/setup-build-publish.yml @@ -0,0 +1,160 @@ +name: 'Setup, Build and Publish' +on: + workflow_call: + inputs: + branch_name: + type: string + description: 'Branch name' + required: true + image_version: + type: string + description: 'Image version for docker hub' + required: true + cmake_options: + type: string + description: 'Additional cmake options' + required: false + build_type: + type: string + description: 'Build type of skaled binary' + required: true + node_type: + type: string + description: 'Node type of skaled build' + required: true + +jobs: + main: + runs-on: self-hosted + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + BUILD_TYPE: ${{ github.event.inputs.build_type }} + steps: + - name: update apt + run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test || true + sudo apt-get update || true + - name: install packages + run: | + sudo apt-get -y remove libzmq* || true + sudo apt-get -y install software-properties-common gcc-9 g++-9 || true + + - name: Use g++-9 and gcov-9 by default + run: | + echo "Updating all needed alternatives" + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9 + sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-9 9 + sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-9 9 + sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-9 9 + echo "Checking alternative for gcc" + which gcc + gcc --version + echo "Checking alternative for g++" + which g++ + g++ --version + echo "Checking alternative for gcov" + which gcov + gcov --version + echo "Checking alternative for gcov-dump" + which gcov-dump + gcov-dump --version + echo "Checking alternative for gcov-tool" + which gcov-tool + gcov-tool --version + + - name: Extract repo name + run: echo ::set-env name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}') + shell: bash + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + - name: checkout + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.branch_name }} + - name: Submodule update + run: | + rm -rf ./libconsensus || true + ls -1 + git submodule update --init --recursive + + - name: Prepare ccache timestamp + id: ccache_cache_timestamp + shell: cmake -P {0} + run: | + string(TIMESTAMP current_date "%Y-%m-%d-%H;%M;%S" UTC) + message("::set-output name=timestamp::${current_date}") + - name: Ccache cache files + uses: actions/cache@v1.1.0 + with: + path: .ccache + key: ${ { matrix.config.name } }-ccache-${ { steps.ccache_cache_timestamp.outputs.timestamp } } + restore-keys: | + ${ { matrix.config.name } }-ccache- + - name: Build dependencies + run: | + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + export CMAKE_BUILD_TYPE=$BUILD_TYPE + [[ $CMAKE_BUILD_TYPE = "Debug" ]] && export DEBUG_FLAG=1 || export DEBUG_FLAG=0 + cd deps + ./clean.sh + rm -f ./libwebsockets-from-git.tar.gz + ./build.sh PARALLEL_COUNT=$(nproc) DEBUG=$DEBUG_FLAG + cd .. + - name: Configure all + run: | + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + export CMAKE_BUILD_TYPE=$BUILD_TYPE + mkdir -p build + cd build + cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE ${{ github.event.inputs.cmake_options }} .. + cd .. + - name: Build all + run: | + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + export CMAKE_BUILD_TYPE=$BUILD_TYPE + cd build + make skaled -j$(nproc) + cd .. + + - name: Compose docker image name + if: github.event.inputs.node_type != 'Historic' + run: | + [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release + export VERSION=${{ github.event.inputs.image_version }}-$VERSION_SUFFIX + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Compose docker image name (historic) + if: github.event.inputs.node_type == 'Historic' + run: | + [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release + export VERSION=${{ github.event.inputs.image_version }}-$VERSION_SUFFIX-historic + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Build and publish container + env: + VERSION: ${{ env.VERSION }} + run: | + cp build/skaled/skaled scripts/skale_build/executable/ + export BRANCH=${{ github.event.inputs.branch_name }} + export RELEASE=true + bash ./scripts/build_and_publish.sh + + - name: Upload skaled binary as artifact + uses: actions/upload-artifact@v2 + if: ${{ always() }} + with: + name: skaled + path: ./build/skaled/skaled \ No newline at end of file From e81939a4ca69eada2abfb3a66de77f9ec701cbb2 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 12 Jun 2024 13:45:42 +0100 Subject: [PATCH 17/24] 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(); From 46761ca7fcaf4ec6f55086051c1b9b4957ac0e58 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 12 Jun 2024 16:15:02 +0000 Subject: [PATCH 18/24] Implement reusable workflows --- .github/workflows/custom_build.yml | 149 ++++++----------------------- 1 file changed, 27 insertions(+), 122 deletions(-) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 79c039b04..cb0afd7b7 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -23,128 +23,33 @@ on: - Debug - RelWithDebInfo default: RelWithDebInfo + skaled_type: + description: 'Type of skaled build' + type: choice + required: true + options: + - Core + - Historic + - All + default: Core jobs: - main_job: - runs-on: self-hosted - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - BUILD_TYPE: ${{ github.event.inputs.build_type }} - steps: - - name: update apt - run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test || true - sudo apt-get update || true - - name: install packages - run: | - sudo apt-get -y remove libzmq* || true - sudo apt-get -y install software-properties-common gcc-9 g++-9 || true - - - name: Use g++-9 and gcov-9 by default - run: | - echo "Updating all needed alternatives" - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9 - sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-9 9 - sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-9 9 - sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-9 9 - echo "Checking alternative for gcc" - which gcc - gcc --version - echo "Checking alternative for g++" - which g++ - g++ --version - echo "Checking alternative for gcov" - which gcov - gcov --version - echo "Checking alternative for gcov-dump" - which gcov-dump - gcov-dump --version - echo "Checking alternative for gcov-tool" - which gcov-tool - gcov-tool --version - - - name: Extract repo name - run: echo ::set-env name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}') - shell: bash - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - name: checkout - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.branch_name }} - - name: Submodule update - run: | - rm -rf ./libconsensus || true - ls -1 - git submodule update --init --recursive - - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - shell: cmake -P {0} - run: | - string(TIMESTAMP current_date "%Y-%m-%d-%H;%M;%S" UTC) - message("::set-output name=timestamp::${current_date}") - - name: Ccache cache files - uses: actions/cache@v1.1.0 - with: - path: .ccache - key: ${ { matrix.config.name } }-ccache-${ { steps.ccache_cache_timestamp.outputs.timestamp } } - restore-keys: | - ${ { matrix.config.name } }-ccache- - - name: Build dependencies - run: | - export CC=gcc-9 - export CXX=g++-9 - export TARGET=all - export CMAKE_BUILD_TYPE=$BUILD_TYPE - [[ $CMAKE_BUILD_TYPE = "Debug" ]] && export DEBUG_FLAG=1 || export DEBUG_FLAG=0 - cd deps - ./clean.sh - rm -f ./libwebsockets-from-git.tar.gz - ./build.sh PARALLEL_COUNT=$(nproc) DEBUG=$DEBUG_FLAG - cd .. - - name: Configure all - run: | - export CC=gcc-9 - export CXX=g++-9 - export TARGET=all - export CMAKE_BUILD_TYPE=$BUILD_TYPE - mkdir -p build - cd build - cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE ${{ github.event.inputs.cmake_options }} .. - cd .. - - name: Build all - run: | - export CC=gcc-9 - export CXX=g++-9 - export TARGET=all - export CMAKE_BUILD_TYPE=$BUILD_TYPE - cd build - make skaled -j$(nproc) - #echo "Ensure release mode skaled does not have any debug markers" - #strip skaled/skaled - cd .. - - - name: Build and publish container - run: | - cp build/skaled/skaled scripts/skale_build/executable/ - export BRANCH=${{ github.event.inputs.branch_name }} - [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release - export VERSION=${{ github.event.inputs.image_version }}-$VERSION_SUFFIX - echo "Version $VERSION" - export RELEASE=true - bash ./scripts/build_and_publish.sh + core_build: + if: github.event.inputs.skaled_type == 'Core' || github.event.inputs.skaled_type == 'All' + uses: ./.github/workflows/setup-build-publish.yml + with: + image_version: ${{ github.event.inputs.image_version }} + branch_name: ${{ github.event.inputs.branch_name }} + cmake_options: ${{ github.event.inputs.cmake_options }} + build_type: ${{ github.event.inputs.build_type }} + node_type: Core - - name: Upload skaled binary as artifact - uses: actions/upload-artifact@v2 - if: ${{ always() }} - with: - name: skaled - path: ./build/skaled/skaled + historic_build: + if: github.event.inputs.skaled_type == 'Historic' || github.event.inputs.skaled_type == 'All' + uses: ./.github/workflows/setup-build-publish.yml + with: + image_version: ${{ github.event.inputs.image_version }} + branch_name: ${{ github.event.inputs.branch_name }} + cmake_options: ${{ github.event.inputs.cmake_options }} + build_type: ${{ github.event.inputs.build_type }} + node_type: Historic \ No newline at end of file From d619b4375c3284ad45d61950ccb28d0d5660d714 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 12 Jun 2024 16:17:36 +0000 Subject: [PATCH 19/24] Customize cmake options --- .github/workflows/custom_build.yml | 2 +- .github/workflows/setup-build-publish.yml | 48 ++++++++++++----------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index cb0afd7b7..6b595550a 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -52,4 +52,4 @@ jobs: branch_name: ${{ github.event.inputs.branch_name }} cmake_options: ${{ github.event.inputs.cmake_options }} build_type: ${{ github.event.inputs.build_type }} - node_type: Historic \ No newline at end of file + node_type: Historic diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index a98e1562a..b6a9601bf 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -22,16 +22,31 @@ on: type: string description: 'Node type of skaled build' required: true - jobs: main: runs-on: self-hosted env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - BUILD_TYPE: ${{ github.event.inputs.build_type }} + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + BUILD_TYPE: ${{ inputs.build_type }} steps: + - name: Prepare workflow variables + if: inputs.node_type != 'Historic' + run: | + [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release + export VERSION=${{ inputs.image_version }}-$VERSION_SUFFIX + echo "VERSION=$VERSION" >> $GITHUB_ENV + export CMAKE_OPTS="${{ inputs.cmake_options }}" + echo "CMAKE_OPTS=$CMAKE_OPTS" >> $GITHUB_ENV + - name: Prepare workflow variables (historic) + if: inputs.node_type == 'Historic' + run: | + [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release + export VERSION=${{ inputs.image_version }}-$VERSION_SUFFIX-historic + echo "VERSION=$VERSION" >> $GITHUB_ENV + export CMAKE_OPTS="-DHISTORIC_STATE=1 ${{ inputs.cmake_options }}" + echo "CMAKE_OPTS=$CMAKE_OPTS" >> $GITHUB_ENV - name: update apt run: | sudo add-apt-repository ppa:ubuntu-toolchain-r/test || true @@ -77,7 +92,7 @@ jobs: - name: checkout uses: actions/checkout@v2 with: - ref: ${{ github.event.inputs.branch_name }} + ref: ${{ inputs.branch_name }} - name: Submodule update run: | rm -rf ./libconsensus || true @@ -110,6 +125,8 @@ jobs: ./build.sh PARALLEL_COUNT=$(nproc) DEBUG=$DEBUG_FLAG cd .. - name: Configure all + env: + CMAKE_OPTS: ${{ env.CMAKE_OPTS }} run: | export CC=gcc-9 export CXX=g++-9 @@ -117,7 +134,7 @@ jobs: export CMAKE_BUILD_TYPE=$BUILD_TYPE mkdir -p build cd build - cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE ${{ github.event.inputs.cmake_options }} .. + cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE $CMAKE_OPTS .. cd .. - name: Build all run: | @@ -128,27 +145,12 @@ jobs: cd build make skaled -j$(nproc) cd .. - - - name: Compose docker image name - if: github.event.inputs.node_type != 'Historic' - run: | - [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release - export VERSION=${{ github.event.inputs.image_version }}-$VERSION_SUFFIX - echo "VERSION=$VERSION" >> $GITHUB_ENV - - - name: Compose docker image name (historic) - if: github.event.inputs.node_type == 'Historic' - run: | - [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release - export VERSION=${{ github.event.inputs.image_version }}-$VERSION_SUFFIX-historic - echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Build and publish container env: VERSION: ${{ env.VERSION }} run: | cp build/skaled/skaled scripts/skale_build/executable/ - export BRANCH=${{ github.event.inputs.branch_name }} + export BRANCH=${{ inputs.branch_name }} export RELEASE=true bash ./scripts/build_and_publish.sh From 9f680b8ad0bb8ce149604b757e58867fb8e03b66 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 12 Jun 2024 17:38:01 +0100 Subject: [PATCH 20/24] #1922 fix block by number error --- libweb3jsonrpc/Eth.cpp | 3 ++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index ba032a18a..6fe5af509 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -602,7 +602,8 @@ Json::Value Eth::eth_getBlockByNumber( string const& _blockNumber, bool _include BlockNumber bn = ( h == LatestBlock || h == PendingBlock ) ? client()->number() : h; u256 baseFeePerGas; - if ( EIP1559TransactionsPatch::isEnabledWhen( client()->blockInfo( bn - 1 ).timestamp() ) ) + if ( bn > 0 && + EIP1559TransactionsPatch::isEnabledWhen( client()->blockInfo( bn - 1 ).timestamp() ) ) try { baseFeePerGas = client()->gasBidPrice( bn - 1 ); } catch ( std::invalid_argument& _e ) { diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 471f3833f..c955130e6 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3134,6 +3134,8 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" ); BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); + + BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_getBlockByNumber( "0x0", false ) ); } BOOST_AUTO_TEST_CASE( eip2930RpcMethods ) { From 3b420caafaac80057896025cbbe689d82bc06418 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 12 Jun 2024 19:53:38 +0000 Subject: [PATCH 21/24] Pass secrets into reusable workflow --- .github/workflows/custom_build.yml | 6 ++++++ .github/workflows/setup-build-publish.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 6b595550a..807c2f269 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -43,6 +43,9 @@ jobs: cmake_options: ${{ github.event.inputs.cmake_options }} build_type: ${{ github.event.inputs.build_type }} node_type: Core + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} historic_build: if: github.event.inputs.skaled_type == 'Historic' || github.event.inputs.skaled_type == 'All' @@ -53,3 +56,6 @@ jobs: cmake_options: ${{ github.event.inputs.cmake_options }} build_type: ${{ github.event.inputs.build_type }} node_type: Historic + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index b6a9601bf..2f415d818 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -22,6 +22,12 @@ on: type: string description: 'Node type of skaled build' required: true + secrets: + DOCKER_USERNAME: + required: true + DOCKER_PASSWORD: + required: true + jobs: main: runs-on: self-hosted From 18cb2f5fe6dc7bc92089b4a277a3dfa7ed7f5c71 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 13 Jun 2024 13:25:47 +0100 Subject: [PATCH 22/24] Update setup-build-publish.yml --- .github/workflows/setup-build-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index 2f415d818..d1b15117f 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -38,7 +38,7 @@ jobs: BUILD_TYPE: ${{ inputs.build_type }} steps: - name: Prepare workflow variables - if: inputs.node_type != 'Historic' + if: inputs.node_type != 'historic' run: | [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release export VERSION=${{ inputs.image_version }}-$VERSION_SUFFIX @@ -46,7 +46,7 @@ jobs: export CMAKE_OPTS="${{ inputs.cmake_options }}" echo "CMAKE_OPTS=$CMAKE_OPTS" >> $GITHUB_ENV - name: Prepare workflow variables (historic) - if: inputs.node_type == 'Historic' + if: inputs.node_type == 'historic' run: | [[ $BUILD_TYPE = "Debug" ]] && export VERSION_SUFFIX=debug || export VERSION_SUFFIX=release export VERSION=${{ inputs.image_version }}-$VERSION_SUFFIX-historic @@ -164,5 +164,5 @@ jobs: uses: actions/upload-artifact@v2 if: ${{ always() }} with: - name: skaled - path: ./build/skaled/skaled \ No newline at end of file + name: skaled-${{ inputs.node_type }} + path: ./build/skaled/skaled From 44527ec5c7485ccb3824bdb8204e1e4825465d6c Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 13 Jun 2024 13:26:09 +0100 Subject: [PATCH 23/24] Update custom_build.yml --- .github/workflows/custom_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 807c2f269..66aa8cd51 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -42,7 +42,7 @@ jobs: branch_name: ${{ github.event.inputs.branch_name }} cmake_options: ${{ github.event.inputs.cmake_options }} build_type: ${{ github.event.inputs.build_type }} - node_type: Core + node_type: core secrets: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} @@ -55,7 +55,7 @@ jobs: branch_name: ${{ github.event.inputs.branch_name }} cmake_options: ${{ github.event.inputs.cmake_options }} build_type: ${{ github.event.inputs.build_type }} - node_type: Historic + node_type: historic secrets: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} From 2b726178e55172acaedda0493091e1df77426074 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 13 Jun 2024 20:26:48 +0100 Subject: [PATCH 24/24] Update custom_build.yml --- .github/workflows/custom_build.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/custom_build.yml b/.github/workflows/custom_build.yml index 66aa8cd51..93316c47a 100644 --- a/.github/workflows/custom_build.yml +++ b/.github/workflows/custom_build.yml @@ -23,19 +23,9 @@ on: - Debug - RelWithDebInfo default: RelWithDebInfo - skaled_type: - description: 'Type of skaled build' - type: choice - required: true - options: - - Core - - Historic - - All - default: Core jobs: core_build: - if: github.event.inputs.skaled_type == 'Core' || github.event.inputs.skaled_type == 'All' uses: ./.github/workflows/setup-build-publish.yml with: image_version: ${{ github.event.inputs.image_version }} @@ -48,7 +38,6 @@ jobs: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} historic_build: - if: github.event.inputs.skaled_type == 'Historic' || github.event.inputs.skaled_type == 'All' uses: ./.github/workflows/setup-build-publish.yml with: image_version: ${{ github.event.inputs.image_version }}