From c578e593c4c4848e2dfab6dc97a151d89a23193d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 May 2024 19:00:03 +0100 Subject: [PATCH 1/4] #1890 add more logs for archive node --- libethereum/Client.cpp | 4 ++++ libethereum/SkaleHost.cpp | 1 + libhistoric/HistoricState.cpp | 17 ++++++++++++++++- libhistoric/HistoricState.h | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 19bd071b8..8f12991f7 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -717,6 +717,10 @@ size_t Client::syncTransactions( << cc::debug( " transactions in " ) << cc::size10( timer.elapsed() * 1000 ) << cc::debug( "(" ) << ( bool ) m_syncTransactionQueue << cc::debug( ")" ); + if ( chainParams().nodeInfo.syncNode ) + LOG( m_logger ) << "HSCT: " + << m_working.mutableState().mutableHistoricState().getBlockCommitTime(); + return goodReceipts; } diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 01434a060..b1a140d6d 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -723,6 +723,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro skaledTimeFinish - skaledTimeStart ) .count(); } + latestBlockTime = skaledTimeFinish; LOG( m_debugLogger ) << "Successfully imported " << n_succeeded << " of " << out_txns.size() << " transactions"; diff --git a/libhistoric/HistoricState.cpp b/libhistoric/HistoricState.cpp index d1e8f6d57..0bb845048 100644 --- a/libhistoric/HistoricState.cpp +++ b/libhistoric/HistoricState.cpp @@ -44,7 +44,8 @@ HistoricState::HistoricState( HistoricState const& _s ) m_unchangedCacheEntries( _s.m_unchangedCacheEntries ), m_nonExistingAccountsCache( _s.m_nonExistingAccountsCache ), m_unrevertablyTouched( _s.m_unrevertablyTouched ), - m_accountStartNonce( _s.m_accountStartNonce ) {} + m_accountStartNonce( _s.m_accountStartNonce ), + blockCommitTimeMs( _s.blockCommitTimeMs ) {} OverlayDB HistoricState::openDB( fs::path const& _basePath, h256 const& _genesisHash, WithExisting _we ) { @@ -137,6 +138,7 @@ HistoricState& HistoricState::operator=( HistoricState const& _s ) { m_nonExistingAccountsCache = _s.m_nonExistingAccountsCache; m_unrevertablyTouched = _s.m_unrevertablyTouched; m_accountStartNonce = _s.m_accountStartNonce; + blockCommitTimeMs = _s.blockCommitTimeMs; return *this; } @@ -194,11 +196,24 @@ void HistoricState::clearCacheIfTooLarge() const { } void HistoricState::commitExternalChanges( AccountMap const& _accountMap ) { + boost::chrono::high_resolution_clock::time_point historicStateStart = + boost::chrono::high_resolution_clock::now(); commitExternalChangesIntoTrieDB( _accountMap, m_state ); m_state.db()->commit(); m_changeLog.clear(); m_cache.clear(); m_unchangedCacheEntries.clear(); + boost::chrono::high_resolution_clock::time_point historicStateFinish = + boost::chrono::high_resolution_clock::now(); + blockCommitTimeMs += boost::chrono::duration_cast< boost::chrono::milliseconds >( + historicStateFinish - historicStateStart ) + .count(); +} + +uint64_t HistoricState::getBlockCommitTime() { + uint64_t retVal = blockCommitTimeMs; + blockCommitTimeMs = 0; + return retVal; } diff --git a/libhistoric/HistoricState.h b/libhistoric/HistoricState.h index ab07529b7..44fe6cf76 100644 --- a/libhistoric/HistoricState.h +++ b/libhistoric/HistoricState.h @@ -296,6 +296,8 @@ class HistoricState { void setRootFromDB(); + uint64_t getBlockCommitTime(); + private: /// Turns all "touched" empty accounts into non-alive accounts. void removeEmptyAccounts(); @@ -345,6 +347,8 @@ class HistoricState { AddressHash commitExternalChangesIntoTrieDB( AccountMap const& _cache, SecureTrieDB< Address, OverlayDB >& _state ); + + uint64_t blockCommitTimeMs = 0; }; std::ostream& operator<<( std::ostream& _out, HistoricState const& _s ); From 156c18ed66e8e2986e8046904dbb6337ad5784c5 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 May 2024 19:37:53 +0100 Subject: [PATCH 2/4] #1890 fix build --- libethereum/Client.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8f12991f7..240bea3f7 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -717,10 +717,10 @@ size_t Client::syncTransactions( << cc::debug( " transactions in " ) << cc::size10( timer.elapsed() * 1000 ) << cc::debug( "(" ) << ( bool ) m_syncTransactionQueue << cc::debug( ")" ); - if ( chainParams().nodeInfo.syncNode ) - LOG( m_logger ) << "HSCT: " - << m_working.mutableState().mutableHistoricState().getBlockCommitTime(); - +#ifdef HISTORIC_STATE + LOG( m_logger ) << "HSCT: " + << m_working.mutableState().mutableHistoricState().getBlockCommitTime(); +#endif return goodReceipts; } From 0c6b99458af4ccb7964eb04be9cd688eccebdbab Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 May 2024 19:46:30 +0100 Subject: [PATCH 3/4] #1890 format --- libethereum/Client.cpp | 5 ++--- libhistoric/HistoricState.cpp | 12 ++++++------ libhistoric/HistoricState.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 240bea3f7..0e69541f5 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -713,9 +713,8 @@ size_t Client::syncTransactions( // Tell network about the new transactions. m_skaleHost->noteNewTransactions(); - ctrace << cc::debug( "Processed " ) << cc::size10( newPendingReceipts.size() ) - << cc::debug( " transactions in " ) << cc::size10( timer.elapsed() * 1000 ) - << cc::debug( "(" ) << ( bool ) m_syncTransactionQueue << cc::debug( ")" ); + ctrace << "Processed " << newPendingReceipts.size() << " transactions in " + << timer.elapsed() * 1000 << "(" << ( bool ) m_syncTransactionQueue << ")"; #ifdef HISTORIC_STATE LOG( m_logger ) << "HSCT: " diff --git a/libhistoric/HistoricState.cpp b/libhistoric/HistoricState.cpp index 0bb845048..b467d1aba 100644 --- a/libhistoric/HistoricState.cpp +++ b/libhistoric/HistoricState.cpp @@ -45,7 +45,7 @@ HistoricState::HistoricState( HistoricState const& _s ) m_nonExistingAccountsCache( _s.m_nonExistingAccountsCache ), m_unrevertablyTouched( _s.m_unrevertablyTouched ), m_accountStartNonce( _s.m_accountStartNonce ), - blockCommitTimeMs( _s.blockCommitTimeMs ) {} + m_blockCommitTimeMs( _s.m_blockCommitTimeMs ) {} OverlayDB HistoricState::openDB( fs::path const& _basePath, h256 const& _genesisHash, WithExisting _we ) { @@ -138,7 +138,7 @@ HistoricState& HistoricState::operator=( HistoricState const& _s ) { m_nonExistingAccountsCache = _s.m_nonExistingAccountsCache; m_unrevertablyTouched = _s.m_unrevertablyTouched; m_accountStartNonce = _s.m_accountStartNonce; - blockCommitTimeMs = _s.blockCommitTimeMs; + m_blockCommitTimeMs = _s.m_blockCommitTimeMs; return *this; } @@ -205,14 +205,14 @@ void HistoricState::commitExternalChanges( AccountMap const& _accountMap ) { m_unchangedCacheEntries.clear(); boost::chrono::high_resolution_clock::time_point historicStateFinish = boost::chrono::high_resolution_clock::now(); - blockCommitTimeMs += boost::chrono::duration_cast< boost::chrono::milliseconds >( + m_blockCommitTimeMs += boost::chrono::duration_cast< boost::chrono::milliseconds >( historicStateFinish - historicStateStart ) - .count(); + .count(); } uint64_t HistoricState::getBlockCommitTime() { - uint64_t retVal = blockCommitTimeMs; - blockCommitTimeMs = 0; + uint64_t retVal = m_blockCommitTimeMs; + m_blockCommitTimeMs = 0; return retVal; } diff --git a/libhistoric/HistoricState.h b/libhistoric/HistoricState.h index 44fe6cf76..9b5de2a97 100644 --- a/libhistoric/HistoricState.h +++ b/libhistoric/HistoricState.h @@ -348,7 +348,7 @@ class HistoricState { AddressHash commitExternalChangesIntoTrieDB( AccountMap const& _cache, SecureTrieDB< Address, OverlayDB >& _state ); - uint64_t blockCommitTimeMs = 0; + uint64_t m_blockCommitTimeMs = 0; }; std::ostream& operator<<( std::ostream& _out, HistoricState const& _s ); From c56e96aab97661cfc992cb3d35c55c2c904097f0 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 14 May 2024 13:08:20 +0100 Subject: [PATCH 4/4] #1890 format --- libdevcore/LevelDB.h | 2 +- libethereum/Client.cpp | 2 +- libhistoric/HistoricState.cpp | 20 ++++++++------------ libhistoric/HistoricState.h | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/libdevcore/LevelDB.h b/libdevcore/LevelDB.h index c2a1f7ee9..514a93648 100644 --- a/libdevcore/LevelDB.h +++ b/libdevcore/LevelDB.h @@ -71,6 +71,7 @@ class LevelDB : public DatabaseFace { static std::atomic< uint64_t > g_keyDeletesStats; // count of the keys that are scheduled to be deleted but are not yet deleted static std::atomic< uint64_t > g_keysToBeDeletedStats; + static uint64_t getCurrentTimeMs(); private: std::unique_ptr< leveldb::DB > m_db; @@ -123,7 +124,6 @@ class LevelDB : public DatabaseFace { } }; void openDBInstanceUnsafe(); - uint64_t getCurrentTimeMs(); void reopenDataBaseIfNeeded(); }; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 0e69541f5..a2bcb2958 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -718,7 +718,7 @@ size_t Client::syncTransactions( #ifdef HISTORIC_STATE LOG( m_logger ) << "HSCT: " - << m_working.mutableState().mutableHistoricState().getBlockCommitTime(); + << m_working.mutableState().mutableHistoricState().getAndResetBlockCommitTime(); #endif return goodReceipts; } diff --git a/libhistoric/HistoricState.cpp b/libhistoric/HistoricState.cpp index b467d1aba..1e50521de 100644 --- a/libhistoric/HistoricState.cpp +++ b/libhistoric/HistoricState.cpp @@ -45,7 +45,7 @@ HistoricState::HistoricState( HistoricState const& _s ) m_nonExistingAccountsCache( _s.m_nonExistingAccountsCache ), m_unrevertablyTouched( _s.m_unrevertablyTouched ), m_accountStartNonce( _s.m_accountStartNonce ), - m_blockCommitTimeMs( _s.m_blockCommitTimeMs ) {} + m_totalTimeSpentInStateCommitsPerBlock( _s.m_totalTimeSpentInStateCommitsPerBlock ) {} OverlayDB HistoricState::openDB( fs::path const& _basePath, h256 const& _genesisHash, WithExisting _we ) { @@ -138,7 +138,7 @@ HistoricState& HistoricState::operator=( HistoricState const& _s ) { m_nonExistingAccountsCache = _s.m_nonExistingAccountsCache; m_unrevertablyTouched = _s.m_unrevertablyTouched; m_accountStartNonce = _s.m_accountStartNonce; - m_blockCommitTimeMs = _s.m_blockCommitTimeMs; + m_totalTimeSpentInStateCommitsPerBlock = _s.m_totalTimeSpentInStateCommitsPerBlock; return *this; } @@ -196,23 +196,19 @@ void HistoricState::clearCacheIfTooLarge() const { } void HistoricState::commitExternalChanges( AccountMap const& _accountMap ) { - boost::chrono::high_resolution_clock::time_point historicStateStart = - boost::chrono::high_resolution_clock::now(); + auto historicStateStart = dev::db::LevelDB::getCurrentTimeMs(); commitExternalChangesIntoTrieDB( _accountMap, m_state ); m_state.db()->commit(); m_changeLog.clear(); m_cache.clear(); m_unchangedCacheEntries.clear(); - boost::chrono::high_resolution_clock::time_point historicStateFinish = - boost::chrono::high_resolution_clock::now(); - m_blockCommitTimeMs += boost::chrono::duration_cast< boost::chrono::milliseconds >( - historicStateFinish - historicStateStart ) - .count(); + auto historicStateFinish = dev::db::LevelDB::getCurrentTimeMs(); + m_totalTimeSpentInStateCommitsPerBlock += historicStateFinish - historicStateStart; } -uint64_t HistoricState::getBlockCommitTime() { - uint64_t retVal = m_blockCommitTimeMs; - m_blockCommitTimeMs = 0; +uint64_t HistoricState::getAndResetBlockCommitTime() { + uint64_t retVal = m_totalTimeSpentInStateCommitsPerBlock; + m_totalTimeSpentInStateCommitsPerBlock = 0; return retVal; } diff --git a/libhistoric/HistoricState.h b/libhistoric/HistoricState.h index 9b5de2a97..f1273bb58 100644 --- a/libhistoric/HistoricState.h +++ b/libhistoric/HistoricState.h @@ -296,7 +296,7 @@ class HistoricState { void setRootFromDB(); - uint64_t getBlockCommitTime(); + uint64_t getAndResetBlockCommitTime(); private: /// Turns all "touched" empty accounts into non-alive accounts. @@ -348,7 +348,7 @@ class HistoricState { AddressHash commitExternalChangesIntoTrieDB( AccountMap const& _cache, SecureTrieDB< Address, OverlayDB >& _state ); - uint64_t m_blockCommitTimeMs = 0; + uint64_t m_totalTimeSpentInStateCommitsPerBlock = 0; }; std::ostream& operator<<( std::ostream& _out, HistoricState const& _s );