diff --git a/libconsensus b/libconsensus index b1916ed05..9683c93ec 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit b1916ed05c3b77f5925662fa591b9a054290d0fd +Subproject commit 9683c93ec19d4dd28724d9ec2e105677360918d1 diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 96f769b5f..2790b4ee3 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -120,6 +120,7 @@ class ClientBase : public Interface { using Interface::blockInfo; // for another overload using Interface::transactionHashes; using Interface::uncle; + using Interface::uncleCount; using Interface::uncleHashes; h256 hashFromNumber( BlockNumber _number ) const override; @@ -152,7 +153,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; 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(); 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/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"; diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index 6891aacef..c297164dc 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -842,9 +842,12 @@ Json::Value WebThreeStubClient::eth_createAccessList( const Json::Value& param1, 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 ) { +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..471f3833f 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -380,7 +380,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 ); @@ -846,7 +847,7 @@ BOOST_AUTO_TEST_CASE( simple_contract ) { // } // } - string compiled = + string compiled = "608060405234801561001057600080fd5b506101ef8061002060003" "96000f3fe608060405234801561001057600080fd5b506004361061" "00365760003560e01c8063552410771461003b578063b3de648b146" @@ -3226,6 +3227,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 ) { @@ -4075,7 +4078,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 );