From 3e387fb13b4e058aa86400901c3acaa4e3bbc4f2 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 13 Dec 2023 16:05:50 +0000 Subject: [PATCH 1/6] SKALED-1431 debug_getFutureTransactions call --- libethereum/Client.h | 2 ++ libethereum/TransactionQueue.cpp | 11 +++++++++++ libethereum/TransactionQueue.h | 2 ++ libweb3jsonrpc/Debug.cpp | 4 ++++ libweb3jsonrpc/Debug.h | 2 ++ libweb3jsonrpc/DebugFace.h | 10 ++++++++++ 6 files changed, 31 insertions(+) diff --git a/libethereum/Client.h b/libethereum/Client.h index d5e35d911..a43d37eae 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -142,6 +142,8 @@ class Client : public ClientBase, protected Worker { /// Retrieve pending transactions Transactions pending() const override; + Transactions DEBUG_getFutureTransactions() 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..0d9e50097 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..f4f585cc7 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 6bbb5cb25..bc3ed5dce 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -358,3 +358,7 @@ uint64_t Debug::debug_doBlocksDbCompaction() { return boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); } + +Json::Value Debug::debug_getFutureTransactions() { + return toJson( m_eth.DEBUG_getFutureTransactions() ); +} 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 From 84c41063901ec485edc7e16e576442eaa77fae63 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 15 Dec 2023 17:12:50 +0000 Subject: [PATCH 2/6] SKALED-1431 Problem fixes --- libethereum/Client.h | 2 +- libethereum/TransactionQueue.cpp | 2 +- libethereum/TransactionQueue.h | 2 +- libhistoric/AlethStandardTrace.cpp | 2 +- libweb3jsonrpc/Debug.cpp | 9 ++++++++- skaled/main.cpp | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libethereum/Client.h b/libethereum/Client.h index a43d37eae..0dda19d1c 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -142,7 +142,7 @@ class Client : public ClientBase, protected Worker { /// Retrieve pending transactions Transactions pending() const override; - Transactions DEBUG_getFutureTransactions() const { return m_tq.DEBUGgetFutureTransactions(); } + 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 0d9e50097..6a075bf84 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -538,7 +538,7 @@ void TransactionQueue::verifierBody() { } } -Transactions TransactionQueue::DEBUGgetFutureTransactions() const { +Transactions TransactionQueue::debugGetFutureTransactions() const { Transactions res; ReadGuard l( m_lock ); for ( auto addressAndMap : m_future ) { diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index f4f585cc7..d089c4004 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -123,7 +123,7 @@ class TransactionQueue { template < class... Args > Transactions topTransactionsSync( unsigned _limit, Args... args ); - Transactions DEBUGgetFutureTransactions() const; + Transactions debugGetFutureTransactions() const; /// Get a hash set of transactions in the queue /// @returns A hash set of all transactions in the queue diff --git a/libhistoric/AlethStandardTrace.cpp b/libhistoric/AlethStandardTrace.cpp index 9875e6dcc..cad1cdc2d 100644 --- a/libhistoric/AlethStandardTrace.cpp +++ b/libhistoric/AlethStandardTrace.cpp @@ -219,7 +219,7 @@ AlethStandardTrace::AlethStandardTrace( m_options( _options ), // if it is a call trace, the transaction does not have signature // therefore, its hash should not include signature - m_txHash( _t.sha3(_isCall? dev::eth::WithoutSignature: dev::eth::WithSignature) ), + m_txHash( _t.sha3( _isCall ? dev::eth::WithoutSignature : dev::eth::WithSignature ) ), m_lastOpRecord( // the top function is executed at depth 0 // therefore it is called from depth -1 diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index bc3ed5dce..523e94697 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -360,5 +360,12 @@ uint64_t Debug::debug_doBlocksDbCompaction() { } Json::Value Debug::debug_getFutureTransactions() { - return toJson( m_eth.DEBUG_getFutureTransactions() ); + try { + checkPrivilegedAccess(); + return toJson( m_eth.debugGetFutureTransactions() ); + } catch ( std::exception const& _e ) { + BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( _e.what() ) ); + } catch ( ... ) { + BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown error" ) ); + } // catch } 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 From 1b0debabd42ed9ef1437e04b3f0b67d6f776c2b2 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 17:34:38 +0000 Subject: [PATCH 3/6] SKALED-1431 remove data from transactions --- libweb3jsonrpc/Debug.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index 523e94697..cd5defee0 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -82,7 +82,7 @@ Json::Value Debug::debug_traceBlockByNumber( const string& if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); - } +} try { return m_eth.traceBlock( bN, _jsonTraceConfig ); @@ -118,7 +118,7 @@ Json::Value Debug::debug_traceBlockByHash( string const& if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); - } +} try { return m_eth.traceBlock( bN, _jsonTraceConfig ); @@ -152,17 +152,17 @@ Json::Value Debug::debug_traceTransaction( string const& if ( localisedTransaction.blockHash() == h256( 0 ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "no committed transaction with this hash" ) ); - } +} auto blockNumber = localisedTransaction.blockNumber(); if ( !m_eth.isKnown( blockNumber ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown block number" ) ); - } +} if ( blockNumber == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); - } +} auto traceOptions = TraceOptions::make( _jsonTraceConfig ); auto tracer = make_shared< AlethStandardTrace >( localisedTransaction, traceOptions ); @@ -177,7 +177,7 @@ Json::Value Debug::debug_traceTransaction( string const& string lowerCaseTxStr = _txHashStr; for ( auto& c : lowerCaseTxStr ) { c = std::tolower( static_cast< unsigned char >( c ) ); - } + } for ( Json::Value::ArrayIndex i = 0; i < tracedBlock.size(); i++ ) { @@ -188,7 +188,7 @@ Json::Value Debug::debug_traceTransaction( string const& STATE_CHECK( transactionTrace.isMember( "result" ) ); return transactionTrace["result"]; } - } +} BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "No transaction in block" ) ); @@ -227,17 +227,17 @@ Json::Value Debug::debug_traceCall( Json::Value const& if ( bN == LatestBlock || bN == PendingBlock ) { bN = m_eth.number(); - } + } if ( !m_eth.isKnown( bN ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown block number:" + _blockNumber ) ); - } +} if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); - } +} TransactionSkeleton ts = toTransactionSkeleton( _call ); @@ -362,7 +362,10 @@ uint64_t Debug::debug_doBlocksDbCompaction() { Json::Value Debug::debug_getFutureTransactions() { try { checkPrivilegedAccess(); - return toJson( m_eth.debugGetFutureTransactions() ); + auto res = toJson( m_eth.DEBUG_getFutureTransactions() ); + for ( auto& t : res ) + t.removeMember( "data" ); + return res; } catch ( std::exception const& _e ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( _e.what() ) ); } catch ( ... ) { From fa8828080980f1bc469655762dcf242d15ea5462 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 18:12:45 +0000 Subject: [PATCH 4/6] SKALED-1431 Format --- libweb3jsonrpc/Debug.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index cd5defee0..32dec7bca 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -82,7 +82,7 @@ Json::Value Debug::debug_traceBlockByNumber( const string& if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); -} + } try { return m_eth.traceBlock( bN, _jsonTraceConfig ); @@ -118,7 +118,7 @@ Json::Value Debug::debug_traceBlockByHash( string const& if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); -} + } try { return m_eth.traceBlock( bN, _jsonTraceConfig ); @@ -152,17 +152,17 @@ Json::Value Debug::debug_traceTransaction( string const& if ( localisedTransaction.blockHash() == h256( 0 ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "no committed transaction with this hash" ) ); -} + } auto blockNumber = localisedTransaction.blockNumber(); if ( !m_eth.isKnown( blockNumber ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown block number" ) ); -} + } if ( blockNumber == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); -} + } auto traceOptions = TraceOptions::make( _jsonTraceConfig ); auto tracer = make_shared< AlethStandardTrace >( localisedTransaction, traceOptions ); @@ -177,7 +177,7 @@ Json::Value Debug::debug_traceTransaction( string const& string lowerCaseTxStr = _txHashStr; for ( auto& c : lowerCaseTxStr ) { c = std::tolower( static_cast< unsigned char >( c ) ); - } + } for ( Json::Value::ArrayIndex i = 0; i < tracedBlock.size(); i++ ) { @@ -188,7 +188,7 @@ Json::Value Debug::debug_traceTransaction( string const& STATE_CHECK( transactionTrace.isMember( "result" ) ); return transactionTrace["result"]; } -} + } BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "No transaction in block" ) ); @@ -227,17 +227,17 @@ Json::Value Debug::debug_traceCall( Json::Value const& if ( bN == LatestBlock || bN == PendingBlock ) { bN = m_eth.number(); - } + } if ( !m_eth.isKnown( bN ) ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Unknown block number:" + _blockNumber ) ); -} + } if ( bN == 0 ) { BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( "Block number must be more than zero" ) ); -} + } TransactionSkeleton ts = toTransactionSkeleton( _call ); From 420bf62662c827109fbc03c725d785d922c6ef2e Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 19:51:39 +0000 Subject: [PATCH 5/6] SKALED-1431 Finish renaming --- libweb3jsonrpc/Debug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index 32dec7bca..d5ef8711c 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -362,7 +362,7 @@ uint64_t Debug::debug_doBlocksDbCompaction() { Json::Value Debug::debug_getFutureTransactions() { try { checkPrivilegedAccess(); - auto res = toJson( m_eth.DEBUG_getFutureTransactions() ); + auto res = toJson( m_eth.debugGetFutureTransactions() ); for ( auto& t : res ) t.removeMember( "data" ); return res; From 2bb97f304088eb77723f7f05e0e405b1185c95ce Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 22 Dec 2023 16:15:44 +0000 Subject: [PATCH 6/6] SKALED-1431 Fixing tests --- libweb3jsonrpc/Net.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 ) ) ); //