From 2b22a450386a940999206593368802e0360652d6 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 15 Sep 2023 12:51:33 +0000 Subject: [PATCH 01/16] Enable tx broadcasting --- libethereum/SkaleHost.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 8a3b54109..dedc5aefe 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -762,27 +762,23 @@ void SkaleHost::startWorking() { // recursively calls this func - so working is still false!) working = true; - if ( !this->m_client.chainParams().nodeInfo.syncNode ) { - try { - m_broadcaster->startService(); - } catch ( const Broadcaster::StartupException& ) { - working = false; - std::throw_with_nested( SkaleHost::CreationException() ); - } - - auto bcast_func = std::bind( &SkaleHost::broadcastFunc, this ); - m_broadcastThread = std::thread( bcast_func ); + try { + m_broadcaster->startService(); + } catch ( const Broadcaster::StartupException& ) { + working = false; + std::throw_with_nested( SkaleHost::CreationException() ); } + auto bcast_func = std::bind( &SkaleHost::broadcastFunc, this ); + m_broadcastThread = std::thread( bcast_func ); + auto csus_func = [&]() { try { m_consensus->startAll(); } catch ( const std::exception& ) { // cleanup m_exitNeeded = true; - if ( !this->m_client.chainParams().nodeInfo.syncNode ) { - m_broadcastThread.join(); - } + m_broadcastThread.join(); ExitHandler::exitHandler( -1, ExitHandler::ec_termninated_by_signal ); return; } From 5e19bd3f95ddb6b758166a07b14517ac5dd106b7 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 15 Sep 2023 14:38:03 +0000 Subject: [PATCH 02/16] Enable transactions methods for syncNode --- libweb3jsonrpc/Eth.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 42f89a002..c86acc62c 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -56,28 +56,6 @@ Eth::Eth( const std::string& configPath, eth::Interface& _eth, eth::AccountHolde m_callCache( MAX_CALL_CACHE_ENTRIES ), m_receiptsCache( MAX_RECEIPT_CACHE_ENTRIES ) {} -bool Eth::isEnabledTransactionSending() const { - bool isEnabled = true; - try { - nlohmann::json joConfig = getConfigJSON(); - if ( joConfig.count( "skaleConfig" ) == 0 ) - throw std::runtime_error( "error config.json file, cannot find \"skaleConfig\"" ); - const nlohmann::json& joSkaleConfig = joConfig["skaleConfig"]; - if ( joSkaleConfig.count( "nodeInfo" ) == 0 ) - throw std::runtime_error( - "error config.json file, cannot find \"skaleConfig\"/\"nodeInfo\"" ); - const nlohmann::json& joSkaleConfig_nodeInfo = joSkaleConfig["nodeInfo"]; - if ( joSkaleConfig_nodeInfo.count( "syncNode" ) == 0 ) - throw std::runtime_error( - "error config.json file, cannot find " - "\"skaleConfig\"/\"nodeInfo\"/\"syncNode\"" ); - const nlohmann::json& joSkaleConfig_nodeInfo_syncNode = joSkaleConfig_nodeInfo["syncNode"]; - isEnabled = joSkaleConfig_nodeInfo_syncNode.get< bool >() ? false : true; - } catch ( ... ) { - } - return isEnabled; -} - string Eth::eth_protocolVersion() { return toJS( eth::c_protocolVersion ); } @@ -288,8 +266,6 @@ void Eth::setTransactionDefaults( TransactionSkeleton& _t ) { string Eth::eth_sendTransaction( Json::Value const& _json ) { try { - if ( !isEnabledTransactionSending() ) - throw std::runtime_error( "transacton sending feature is disabled on this instance" ); TransactionSkeleton t = toTransactionSkeleton( _json ); setTransactionDefaults( t ); pair< bool, Secret > ar = m_ethAccounts.authenticate( t ); @@ -357,8 +333,6 @@ Json::Value Eth::eth_inspectTransaction( std::string const& _rlp ) { // TODO Catch exceptions for all calls other eth_-calls in outer scope! /// skale string Eth::eth_sendRawTransaction( std::string const& _rlp ) { - if ( !isEnabledTransactionSending() ) - throw JsonRpcException( "transacton sending feature is disabled on this instance" ); // Don't need to check the transaction signature (CheckTransaction::None) since it // will be checked as a part of transaction import Transaction t( jsToBytes( _rlp, OnFailed::Throw ), CheckTransaction::None ); From 2fbb33c974e9521b228f2941197695024d2f2afa Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 15 Sep 2023 14:47:42 +0000 Subject: [PATCH 03/16] Exit sync node if stateRoot --- libethereum/SkaleHost.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index dedc5aefe..a55c6e368 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -592,8 +592,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro << cc::debug( stCurrent.hex() ) << std::endl; // FATAL if mismatch in non-default - if ( _winningNodeIndex != 0 && dev::h256::Arith( stCurrent ) != _stateRoot && - !this->m_client.chainParams().nodeInfo.syncNode ) { + if ( _winningNodeIndex != 0 && dev::h256::Arith( stCurrent ) != _stateRoot ) { clog( VerbosityError, "skale-host" ) << cc::fatal( "FATAL STATE ROOT MISMATCH ERROR:" ) << cc::error( " current state root " ) From 0893864e37492a5bd8f1ca424318021d4324baaf Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 23 Nov 2023 16:26:34 +0000 Subject: [PATCH 04/16] #1135 Remove txs from queue --- libethereum/SkaleHost.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 5f9311fe9..1fb0237b9 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -649,8 +649,9 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // if already known // TODO clear occasionally this cache?! + Transaction t; if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { - Transaction t = m_m_transaction_cache.at( sha.asArray() ); + t = m_m_transaction_cache.at( sha.asArray() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); @@ -663,18 +664,25 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // for test std::thread( [t, this]() { m_client.importTransaction( t ); } // ).detach(); } else { - Transaction t( data, CheckTransaction::Everything, true ); + t = Transaction( data, CheckTransaction::Everything, true ); t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Will import consensus-born txn!"; m_debugTracer.tracepoint( "import_consensus_born" ); have_consensus_born = true; } + + // Deleting transaction from the transaction queue if it was broadcasted from + // the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { - // TODO fix this!!? - clog( VerbosityWarning, "skale-host" ) - << "Consensus returned 'future'' transaction that we didn't yet send!!"; - m_debugTracer.tracepoint( "import_future" ); + if ( m_client.chainParams().nodeInfo.syncNode ) { + LOG( m_debugLogger ) << "Dropping txn from sync node " << sha << std::endl; + m_tq.dropGood( t ); + } else { + clog( VerbosityWarning, "skale-host" ) + << "Consensus returned 'future'' transaction that we didn't yet send!!"; + m_debugTracer.tracepoint( "import_future" ); + } } } // for From e5ea3e39feaf272a9237699649c75ac9509eb25c Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 23 Nov 2023 17:51:49 +0000 Subject: [PATCH 05/16] Fix linter --- libethereum/SkaleHost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 1fb0237b9..90e583e33 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -673,7 +673,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro } // Deleting transaction from the transaction queue if it was broadcasted from - // the sync node + // the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { if ( m_client.chainParams().nodeInfo.syncNode ) { LOG( m_debugLogger ) << "Dropping txn from sync node " << sha << std::endl; From d387c774bbe949d357d833ce16461e0d4e51ea35 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 13 Dec 2023 18:08:34 +0000 Subject: [PATCH 06/16] #1135 Add unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 43 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 1da3f94a9..9c4247c8c 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -245,7 +245,9 @@ class TestIpcClient : public jsonrpc::IClientConnector { }; struct JsonRpcFixture : public TestOutputHelperFixture { - JsonRpcFixture( const std::string& _config = "", bool _owner = true, bool _deploymentControl = true, bool _generation2 = false, bool _mtmEnabled = false ) { + JsonRpcFixture( const std::string& _config = "", bool _owner = true, + bool _deploymentControl = true, bool _generation2 = false, + bool _mtmEnabled = false, bool _isSyncNode = false ) { dev::p2p::NetworkPreferences nprefs; ChainParams chainParams; @@ -293,6 +295,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port; } chainParams.sChain.multiTransactionMode = _mtmEnabled; + chainParams.nodeInfo.syncNode = _isSyncNode; // web3.reset( new WebThreeDirect( // "eth tests", tempDir.path(), "", chainParams, WithExisting::Kill, {"eth"}, @@ -322,7 +325,8 @@ struct JsonRpcFixture : public TestOutputHelperFixture { client->injectSkaleHost(); client->startWorking(); - block_promise.get_future().wait(); + if ( !_isSyncNode ) + block_promise.get_future().wait(); if ( !_generation2 ) client->setAuthor( coinbase.address() ); @@ -724,6 +728,41 @@ BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_errorDuplicateTransaction ) { "Same transaction already exists in the pending transaction queue." ); } +BOOST_AUTO_TEST_CASE( send_raw_tx_sync ) { + // Enable sync mode + JsonRpcFixture fixture( c_genesisConfigString, true, true, true, false ); + Address senderAddress = fixture.coinbase.address(); + fixture.client->setAuthor( senderAddress ); + + // contract test { + // function f(uint a) returns(uint d) { return a * 7; } + // } + + string compiled = + "6080604052341561000f57600080fd5b60b98061001d6000396000f300" + "608060405260043610603f576000357c01000000000000000000000000" + "00000000000000000000000000000000900463ffffffff168063b3de64" + "8b146044575b600080fd5b3415604e57600080fd5b606a600480360381" + "019080803590602001909291905050506080565b604051808281526020" + "0191505060405180910390f35b60006007820290509190505600a16562" + "7a7a72305820f294e834212334e2978c6dd090355312a3f0f9476b8eb9" + "8fb480406fc2728a960029"; + + Json::Value create; + create["code"] = compiled; + create["gas"] = "180000"; + + BOOST_REQUIRE( fixture.client->transactionQueueStatus().current == 0); + + // Sending tx to sync node + string txHash = fixture.rpcClient->eth_sendTransaction( create ); + + auto pendingTransactions = fixture.client->pending(); + BOOST_REQUIRE( pendingTransactions.size() == 1); + auto txHashFromQueue = "0x" + pendingTransactions[0].sha3().hex(); + BOOST_REQUIRE( txHashFromQueue == txHash ); +} + BOOST_AUTO_TEST_CASE( eth_signTransaction ) { JsonRpcFixture fixture; auto address = fixture.coinbase.address(); From 34212e836c2a483d47937bb36dfb72b715eb9068 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 15:23:20 +0000 Subject: [PATCH 07/16] #1135 Update unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 5bab45bf1..51366c78e 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -749,7 +749,7 @@ BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_errorDuplicateTransaction ) { BOOST_AUTO_TEST_CASE( send_raw_tx_sync ) { // Enable sync mode - JsonRpcFixture fixture( c_genesisConfigString, true, true, true, false ); + JsonRpcFixture fixture( c_genesisConfigString, true, true, true, false, true ); Address senderAddress = fixture.coinbase.address(); fixture.client->setAuthor( senderAddress ); From b483366577f2887636b1f8ae41a87aceebe3b29f Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 17:43:49 +0000 Subject: [PATCH 08/16] #1651 Fix logs and vars naming --- libethereum/SkaleHost.cpp | 114 +++++++++++++++++--------------------- libethereum/SkaleHost.h | 4 ++ 2 files changed, 56 insertions(+), 62 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index e00e284ec..04f569845 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -571,13 +571,12 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro std::lock_guard< std::recursive_mutex > lock( m_pending_createMutex ); if ( m_ignoreNewBlocks ) { - clog( VerbosityWarning, "skale-host" ) << "WARNING: skaled got new block #" << _blockID - << " after timestamp-related exit initiated!"; + LOG( m_warningLogger ) << "WARNING: skaled got new block #" << _blockID + << " after timestamp-related exit initiated!"; return; } - LOG( m_debugLogger ) << cc::debug( "createBlock " ) << cc::notice( "ID" ) << cc::debug( " = " ) - << cc::warn( "#" ) << cc::num10( _blockID ) << std::endl; + LOG( m_debugLogger ) << "createBlock ID = #" << _blockID; m_debugTracer.tracepoint( "create_block" ); // convert bytes back to transactions (using caching), delete them from q and push results into @@ -587,22 +586,17 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro dev::h256 stCurrent = this->m_client.blockInfo( this->m_client.hashFromNumber( _blockID - 1 ) ).stateRoot(); - LOG( m_traceLogger ) << cc::debug( "STATE ROOT FOR BLOCK: " ) - << cc::debug( std::to_string( _blockID - 1 ) ) << ' ' - << cc::debug( stCurrent.hex() ) << std::endl; + LOG( m_traceLogger ) << "STATE ROOT FOR BLOCK: " << std::to_string( _blockID - 1 ) << " " + << stCurrent.hex(); // FATAL if mismatch in non-default if ( _winningNodeIndex != 0 && dev::h256::Arith( stCurrent ) != _stateRoot ) { - clog( VerbosityError, "skale-host" ) - << cc::fatal( "FATAL STATE ROOT MISMATCH ERROR:" ) - << cc::error( " current state root " ) - << cc::warn( dev::h256::Arith( stCurrent ).str() ) - << cc::error( " is not equal to arrived state root " ) - << cc::warn( _stateRoot.str() ) << cc::error( " with block ID " ) - << cc::notice( "#" ) << cc::num10( _blockID ) << cc::warn( ", " ) - << cc::p( "/data_dir" ) - << cc::error( " cleanup is recommended, exiting with code " ) - << cc::num10( int( ExitHandler::ec_state_root_mismatch ) ) << "..."; + LOG( m_errorLogger ) << "FATAL STATE ROOT MISMATCH ERROR: current state root " + << dev::h256::Arith( stCurrent ).str() + << " is not equal to arrived state root " << _stateRoot.str() + << " with block ID #" << _blockID + << ", /data_dir cleanup is recommended, exiting with code " + << int( ExitHandler::ec_state_root_mismatch ) << "..."; if ( AmsterdamFixPatch::stateRootCheckingEnabled( m_client ) ) { m_ignoreNewBlocks = true; m_consensus->exitGracefully(); @@ -612,16 +606,14 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // WARN if default but non-zero if ( _winningNodeIndex == 0 && _stateRoot != u256() ) - clog( VerbosityWarning, "skale-host" ) - << cc::warn( "WARNING: STATE ROOT MISMATCH!" ) - << cc::warn( " Current block is DEFAULT BUT arrived state root is " ) - << cc::warn( _stateRoot.str() ) << cc::warn( " with block ID " ) - << cc::notice( "#" ) << cc::num10( _blockID ); + LOG( m_warningLogger ) << "WARNING: STATE ROOT MISMATCH!" + << "Current block is DEFAULT BUT arrived state root is " + << _stateRoot.str() << " with block ID #" << _blockID; } std::vector< Transaction > out_txns; // resultant Transaction vector - std::atomic_bool have_consensus_born = false; // means we need to re-verify old txns + std::atomic_bool haveConsensusBorn = false; // means we need to re-verify old txns // HACK this is for not allowing new transactions in tq between deletion and block creation! // TODO decouple SkaleHost and Client!!! @@ -635,11 +627,11 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro for ( auto it = _approvedTransactions.begin(); it != _approvedTransactions.end(); ++it ) { const bytes& data = *it; h256 sha = sha3( data ); - LOG( m_traceLogger ) << cc::debug( "Arrived txn: " ) << sha << std::endl; + LOG( m_traceLogger ) << "Arrived txn: " << sha; jarrProcessedTxns.push_back( toJS( sha ) ); #ifdef DEBUG_TX_BALANCE if ( sent.count( sha ) != m_transaction_cache.count( sha.asArray() ) ) { - std::cerr << cc::error( "createBlock assert" ) << std::endl; + LOG( m_errorLogger ) << "createBlock assert"; // sleep(200); assert( sent.count( sha ) == m_transaction_cache.count( sha.asArray() ) ); } @@ -667,20 +659,20 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro t = Transaction( data, CheckTransaction::Everything, true ); t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty ); out_txns.push_back( t ); - LOG( m_debugLogger ) << "Will import consensus-born txn!"; + LOG( m_debugLogger ) << "Will import consensus-born txn"; m_debugTracer.tracepoint( "import_consensus_born" ); - have_consensus_born = true; + haveConsensusBorn = true; } - // Deleting transaction from the transaction queue if it was broadcasted from - // the sync node + // Deleting transaction from the transaction queue if + // it was broadcasted from the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { if ( m_client.chainParams().nodeInfo.syncNode ) { - LOG( m_debugLogger ) << "Dropping txn from sync node " << sha << std::endl; + LOG( m_debugLogger ) << "Dropping txn from sync node " << sha; m_tq.dropGood( t ); } else { - clog( VerbosityWarning, "skale-host" ) - << "Consensus returned 'future'' transaction that we didn't yet send!!"; + LOG( m_traceLogger ) + << "Consensus returned future transaction that we didn't yet send"; m_debugTracer.tracepoint( "import_future" ); } } @@ -714,35 +706,33 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro boost::chrono::high_resolution_clock::time_point skaledTimeFinish = boost::chrono::high_resolution_clock::now(); if ( latestBlockTime != boost::chrono::high_resolution_clock::time_point() ) { - clog( VerbosityInfo, "skale-host" ) - << "SWT:" - << boost::chrono::duration_cast< boost::chrono::milliseconds >( - skaledTimeFinish - skaledTimeStart ) - .count() - << ':' << "BFT:" - << boost::chrono::duration_cast< boost::chrono::milliseconds >( - skaledTimeFinish - latestBlockTime ) - .count(); + LOG( m_infoLogger ) << "SWT:" + << boost::chrono::duration_cast< boost::chrono::milliseconds >( + skaledTimeFinish - skaledTimeStart ) + .count() + << ':' << "BFT:" + << boost::chrono::duration_cast< boost::chrono::milliseconds >( + skaledTimeFinish - latestBlockTime ) + .count(); } else { - clog( VerbosityInfo, "skale-host" ) - << "SWT:" - << boost::chrono::duration_cast< boost::chrono::milliseconds >( - skaledTimeFinish - skaledTimeStart ) - .count(); + LOG( m_infoLogger ) << "SWT:" + << boost::chrono::duration_cast< boost::chrono::milliseconds >( + skaledTimeFinish - skaledTimeStart ) + .count(); } latestBlockTime = skaledTimeFinish; - LOG( m_debugLogger ) << cc::success( "Successfully imported " ) << n_succeeded - << cc::success( " of " ) << out_txns.size() - << cc::success( " transactions" ) << std::endl; + LOG( m_debugLogger ) << "Successfully imported " << n_succeeded << " of " << out_txns.size() + << " transactions"; - if ( have_consensus_born ) + if ( haveConsensusBorn ) this->m_lastBlockWithBornTransactions = _blockID; logState(); - clog( VerbosityInfo, "skale-host" ) - << "TQBYTES:CTQ:" << m_tq.status().currentBytes << ":FTQ:" << m_tq.status().futureBytes - << ":TQSIZE:CTQ:" << m_tq.status().current << ":FTQ:" << m_tq.status().future; + LOG( m_infoLogger ) << "TQBYTES:CTQ:" << m_tq.status().currentBytes + << ":FTQ:" << m_tq.status().futureBytes + << ":TQSIZE:CTQ:" << m_tq.status().current + << ":FTQ:" << m_tq.status().future; if ( m_instanceMonitor != nullptr ) { if ( m_instanceMonitor->isTimeToRotate( _timeStamp ) ) { @@ -750,15 +740,15 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro m_ignoreNewBlocks = true; m_consensus->exitGracefully(); ExitHandler::exitHandler( -1, ExitHandler::ec_rotation_complete ); - clog( VerbosityInfo, "skale-host" ) << "Rotation is completed. Instance is exiting"; + LOG( m_infoLogger ) << "Rotation is completed. Instance is exiting"; } } } catch ( const std::exception& ex ) { - cerror << "CRITICAL " << ex.what() << " (in createBlock)"; - cerror << "\n" << skutils::signal::generate_stack_trace() << "\n" << std::endl; + LOG( m_errorLogger ) << "CRITICAL " << ex.what() << " (in createBlock)"; + LOG( m_errorLogger ) << "\n" << skutils::signal::generate_stack_trace() << "\n"; } catch ( ... ) { - cerror << "CRITICAL unknown exception (in createBlock)"; - cerror << "\n" << skutils::signal::generate_stack_trace() << "\n" << std::endl; + LOG( m_errorLogger ) << "CRITICAL unknown exception (in createBlock)"; + LOG( m_errorLogger ) << "\n" << skutils::signal::generate_stack_trace() << "\n"; } void SkaleHost::startWorking() { @@ -776,10 +766,10 @@ void SkaleHost::startWorking() { std::throw_with_nested( SkaleHost::CreationException() ); } - auto bcast_func = std::bind( &SkaleHost::broadcastFunc, this ); - m_broadcastThread = std::thread( bcast_func ); + auto broadcastFunction = std::bind( &SkaleHost::broadcastFunc, this ); + m_broadcastThread = std::thread( broadcastFunction ); - auto csus_func = [&]() { + auto consensusFunction = [&]() { try { m_consensus->startAll(); } catch ( const std::exception& ) { @@ -816,7 +806,7 @@ void SkaleHost::startWorking() { // m_consensus->setEmptyBlockIntervalMs( tmp_interval ); }; // func - m_consensusThread = std::thread( csus_func ); + m_consensusThread = std::thread( consensusFunction ); } // TODO finish all gracefully to allow all undone jobs be finished diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index a92fc5462..9a910ad98 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -204,6 +204,10 @@ class SkaleHost { bool m_broadcastEnabled; + + dev::Logger m_errorLogger{ dev::createLogger( dev::VerbosityError, "skale-host" ) }; + dev::Logger m_warningLogger{ dev::createLogger( dev::VerbosityWarning, "skale-host" ) }; + dev::Logger m_infoLogger{ dev::createLogger( dev::VerbosityInfo, "skale-host" ) }; dev::Logger m_debugLogger{ dev::createLogger( dev::VerbosityDebug, "skale-host" ) }; dev::Logger m_traceLogger{ dev::createLogger( dev::VerbosityTrace, "skale-host" ) }; void logState(); From 25ec6224ff5dac948a21b77a45dd792c467efa4c Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 18:42:20 +0000 Subject: [PATCH 09/16] #1135 Improve exceptions handling --- libethereum/SkaleHost.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 04f569845..59d80be3f 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -668,7 +668,8 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // it was broadcasted from the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { if ( m_client.chainParams().nodeInfo.syncNode ) { - LOG( m_debugLogger ) << "Dropping txn from sync node " << sha; + LOG( m_traceLogger ) + << "Dropping broadcasted txn from sync node " << sha; m_tq.dropGood( t ); } else { LOG( m_traceLogger ) @@ -764,6 +765,9 @@ void SkaleHost::startWorking() { } catch ( const Broadcaster::StartupException& ) { working = false; std::throw_with_nested( SkaleHost::CreationException() ); + } catch ( ... ) { + working = false; + std::throw_with_nested( std::runtime_error( "Error in starting broadcaster service" ) ); } auto broadcastFunction = std::bind( &SkaleHost::broadcastFunc, this ); @@ -772,7 +776,7 @@ void SkaleHost::startWorking() { auto consensusFunction = [&]() { try { m_consensus->startAll(); - } catch ( const std::exception& ) { + } catch ( ... ) { // cleanup m_exitNeeded = true; m_broadcastThread.join(); From f70bd4e7cbca1a58ced60e1c3e01d246f6d543da Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 18:46:28 +0000 Subject: [PATCH 10/16] #1135 Fix linter --- libethereum/SkaleHost.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 59d80be3f..59de0f3d6 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -668,8 +668,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // it was broadcasted from the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { if ( m_client.chainParams().nodeInfo.syncNode ) { - LOG( m_traceLogger ) - << "Dropping broadcasted txn from sync node " << sha; + LOG( m_traceLogger ) << "Dropping broadcasted txn from sync node " << sha; m_tq.dropGood( t ); } else { LOG( m_traceLogger ) From f8b75f07cc6255d40ce1566f9ea377dd817001a3 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 19:37:37 +0000 Subject: [PATCH 11/16] #1135 Fix naming --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 51366c78e..7640a5b24 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -318,17 +318,17 @@ struct JsonRpcFixture : public TestOutputHelperFixture { client->setAuthor( coinbase.address() ); // wait for 1st block - because it's always empty - std::promise< void > block_promise; + std::promise< void > blockPromise; auto importHandler = client->setOnBlockImport( - [&block_promise]( BlockHeader const& ) { - block_promise.set_value(); + [&blockPromise]( BlockHeader const& ) { + blockPromise.set_value(); } ); client->injectSkaleHost(); client->startWorking(); if ( !_isSyncNode ) - block_promise.get_future().wait(); + blockPromise.get_future().wait(); if ( !_generation2 ) client->setAuthor( coinbase.address() ); From 76b963c80ba9e34442a4d753c82033c1801fab76 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 18 Dec 2023 20:06:33 +0000 Subject: [PATCH 12/16] #1135 Remove transaction deletion logic --- libethereum/SkaleHost.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 59de0f3d6..45d5b2cb9 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -590,7 +590,8 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro << stCurrent.hex(); // FATAL if mismatch in non-default - if ( _winningNodeIndex != 0 && dev::h256::Arith( stCurrent ) != _stateRoot ) { + if ( _winningNodeIndex != 0 && dev::h256::Arith( stCurrent ) != _stateRoot && + !this->m_client.chainParams().nodeInfo.syncNode ) { LOG( m_errorLogger ) << "FATAL STATE ROOT MISMATCH ERROR: current state root " << dev::h256::Arith( stCurrent ).str() << " is not equal to arrived state root " << _stateRoot.str() @@ -664,17 +665,10 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro haveConsensusBorn = true; } - // Deleting transaction from the transaction queue if - // it was broadcasted from the sync node if ( m_tq.knownTransactions().count( sha ) != 0 ) { - if ( m_client.chainParams().nodeInfo.syncNode ) { - LOG( m_traceLogger ) << "Dropping broadcasted txn from sync node " << sha; - m_tq.dropGood( t ); - } else { - LOG( m_traceLogger ) - << "Consensus returned future transaction that we didn't yet send"; - m_debugTracer.tracepoint( "import_future" ); - } + LOG( m_traceLogger ) + << "Consensus returned future transaction that we didn't yet send"; + m_debugTracer.tracepoint( "import_future" ); } } // for From 36e943a78841996b9d58b52e357c852c9da83713 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 18 Dec 2023 20:22:51 +0000 Subject: [PATCH 13/16] #1135 Code cleanup --- libethereum/SkaleHost.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 45d5b2cb9..68794f5b5 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -642,9 +642,8 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // if already known // TODO clear occasionally this cache?! - Transaction t; if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { - t = m_m_transaction_cache.at( sha.asArray() ); + Transaction t = m_m_transaction_cache.at( sha.asArray() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); @@ -657,7 +656,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // for test std::thread( [t, this]() { m_client.importTransaction( t ); } // ).detach(); } else { - t = Transaction( data, CheckTransaction::Everything, true ); + Transaction t( data, CheckTransaction::Everything, true ); t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Will import consensus-born txn"; From 761de60c44b1a4863b1379ef4e5fbd69343c6416 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 18 Dec 2023 20:26:09 +0000 Subject: [PATCH 14/16] #1135 Update consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 952e3890d..77c101094 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 952e3890d620d55d56e32dc0fbd26637f23d0694 +Subproject commit 77c101094ce15dc549cb4a1e606919c8e8170012 From 3147f3456e3e305495b6b1179d526dfab09c4d73 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 21 Dec 2023 21:26:44 +0000 Subject: [PATCH 15/16] Fix net_version test --- libweb3jsonrpc/Net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From a2d536317bd910dd75f59f653bf21010cb3a98a8 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 26 Dec 2023 12:51:48 +0000 Subject: [PATCH 16/16] fix old tests names --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49803f389..b0255608d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -188,7 +188,7 @@ jobs: ./testeth -t BlockQueueSuite -- --express && touch /tmp/BlockQueueSuitePassed ./testeth -t ClientBase -- --express && touch /tmp/ClientBasePassed ./testeth -t EstimateGas -- --express && touch /tmp/EstimateGasPassed - ./testeth -t IMABLSPublicKey -- --express && touch /tmp/IMABLSPublicKeyPassed + ./testeth -t getHistoricNodesData -- --express && touch /tmp/getHistoricNodesDataPassed ./testeth -t ExtVmSuite -- --express && touch /tmp/ExtVmSuitePassed ./testeth -t GasPricer -- --express && touch /tmp/GasPricerPassed ./testeth -t BasicTests -- --express && touch /tmp/BasicTestsPassed @@ -239,7 +239,7 @@ jobs: ls /tmp/BlockQueueSuitePassed || ./testeth -t BlockQueueSuite -- --express --verbosity 4 ls /tmp/ClientBasePassed || ./testeth -t ClientBase -- --express --verbosity 4 ls /tmp/EstimateGasPassed || ./testeth -t EstimateGas -- --express --verbosity 4 - ls /tmp/IMABLSPublicKeyPassed || ./testeth -t IMABLSPublicKey -- --express --verbosity 4 + ls /tmp/getHistoricNodesDataPassed || ./testeth -t getHistoricNodesData -- --express --verbosity 4 ls /tmp/ExtVmSuitePassed || ./testeth -t ExtVmSuite -- --express --verbosity 4 ls /tmp/GasPricerPassed || ./testeth -t GasPricer -- --express --verbosity 4 ls /tmp/BasicTestsPassed || ./testeth -t BasicTests -- --express --verbosity 4