diff --git a/libethereum/Client.h b/libethereum/Client.h index c1b0ed173..c76562294 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -145,6 +145,8 @@ class Client : public ClientBase, protected Worker { /// Retrieve pending transactions Transactions pending() const override; + Transactions debugGetFutureTransactions() const { return m_tq.debugGetFutureTransactions(); } + /// Queues a block for import. ImportResult queueBlock( bytes const& _block, bool _isSafe = false ); diff --git a/libethereum/TransactionQueue.cpp b/libethereum/TransactionQueue.cpp index bfeee388f..6a075bf84 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -537,3 +537,14 @@ void TransactionQueue::verifierBody() { MICROPROFILE_LEAVE(); } } + +Transactions TransactionQueue::debugGetFutureTransactions() const { + Transactions res; + ReadGuard l( m_lock ); + for ( auto addressAndMap : m_future ) { + for ( auto nonceAndTransaction : addressAndMap.second ) { + res.push_back( nonceAndTransaction.second.transaction ); + } // for nonce + } // for address + return res; +} diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index 63ad3ee96..d089c4004 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -123,6 +123,8 @@ class TransactionQueue { template < class... Args > Transactions topTransactionsSync( unsigned _limit, Args... args ); + Transactions debugGetFutureTransactions() const; + /// Get a hash set of transactions in the queue /// @returns A hash set of all transactions in the queue const h256Hash knownTransactions() const; diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index 4f7e97839..8ae32497a 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -345,3 +345,17 @@ uint64_t Debug::debug_doBlocksDbCompaction() { return boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); } + +Json::Value Debug::debug_getFutureTransactions() { + try { + checkPrivilegedAccess(); + auto res = toJson( m_eth.debugGetFutureTransactions() ); + for ( auto& t : res ) + t.removeMember( "data" ); + return res; + } catch ( std::exception const& _e ) { + BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( _e.what() ) ); + } catch ( ... ) { + BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown error" ) ); + } // catch +} diff --git a/libweb3jsonrpc/Debug.h b/libweb3jsonrpc/Debug.h index a85473af0..63c88405a 100644 --- a/libweb3jsonrpc/Debug.h +++ b/libweb3jsonrpc/Debug.h @@ -62,6 +62,8 @@ class Debug : public DebugFace { virtual uint64_t debug_doStateDbCompaction() override; virtual uint64_t debug_doBlocksDbCompaction() override; + virtual Json::Value debug_getFutureTransactions() override; + private: eth::Client& m_eth; SkaleDebugInterface* m_debugInterface = nullptr; diff --git a/libweb3jsonrpc/DebugFace.h b/libweb3jsonrpc/DebugFace.h index c08681f11..ed988d76c 100644 --- a/libweb3jsonrpc/DebugFace.h +++ b/libweb3jsonrpc/DebugFace.h @@ -98,6 +98,10 @@ class DebugFace : public ServerInterface< DebugFace > { this->bindAndAddMethod( jsonrpc::Procedure( "debug_doBlocksDbCompaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ), &dev::rpc::DebugFace::debug_doBlocksDbCompactionI ); + + this->bindAndAddMethod( jsonrpc::Procedure( "debug_getFutureTransactions", + jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ), + &dev::rpc::DebugFace::debug_getFutureTransactionsI ); } inline virtual void debug_accountRangeAtI( const Json::Value& request, Json::Value& response ) { response = this->debug_accountRangeAt( request[0u].asString(), request[1u].asInt(), @@ -179,6 +183,10 @@ class DebugFace : public ServerInterface< DebugFace > { response = this->debug_doBlocksDbCompaction(); } + virtual void debug_getFutureTransactionsI( const Json::Value&, Json::Value& response ) { + response = this->debug_getFutureTransactions(); + } + virtual Json::Value debug_accountRangeAt( const std::string& param1, int param2, const std::string& param3, int param4 ) = 0; virtual Json::Value debug_traceTransaction( @@ -207,6 +215,8 @@ class DebugFace : public ServerInterface< DebugFace > { virtual uint64_t debug_doStateDbCompaction() = 0; virtual uint64_t debug_doBlocksDbCompaction() = 0; + + virtual Json::Value debug_getFutureTransactions() = 0; }; } // namespace rpc diff --git a/libweb3jsonrpc/Net.h b/libweb3jsonrpc/Net.h index bc53e0c2b..dbf63c355 100644 --- a/libweb3jsonrpc/Net.h +++ b/libweb3jsonrpc/Net.h @@ -44,7 +44,7 @@ class Net : public NetFace { virtual bool net_listening() override; private: - const dev::eth::ChainParams& m_chainParams; + const dev::eth::ChainParams m_chainParams; }; } // namespace rpc diff --git a/skaled/main.cpp b/skaled/main.cpp index b39664739..5b9b0b110 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -1988,7 +1988,7 @@ int main( int argc, char** argv ) try { #else // debug interface is enabled on core node if bEnabledAPIs_debug is true auto pDebugFace = bEnabledAPIs_debug ? - new rpc::Debug( *g_client, &debugInterface, argv_string ) : + new rpc::Debug( *g_client, &debugInterface, argv_string, true ) : nullptr; #endif diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 12c113e16..3fd38dd38 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -346,7 +346,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { rpcServer.reset( new FullServer( ethFace , new rpc::Net( chainParams ), new rpc::Web3( /*web3->clientVersion()*/ ), // TODO Add real version? new rpc::AdminEth( *client, *gasPricer, keyManager, *sessionManager.get() ), - /*new rpc::AdminNet(*web3, *sessionManager), */ new rpc::Debug( *client ), + /*new rpc::AdminNet(*web3, *sessionManager), */ new rpc::Debug( *client, nullptr, "", true ), new rpc::Test( *client ) ) ); //