From 59e263ce522e08844e308e85999d5677632860be Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 26 Dec 2023 18:18:45 +0000 Subject: [PATCH] #1748 fixing compatibiliti with geth prestate --- libhistoric/PrestateTracePrinter.cpp | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/libhistoric/PrestateTracePrinter.cpp b/libhistoric/PrestateTracePrinter.cpp index 12f4d3013..a51d7de16 100644 --- a/libhistoric/PrestateTracePrinter.cpp +++ b/libhistoric/PrestateTracePrinter.cpp @@ -35,9 +35,22 @@ void PrestateTracePrinter::print( Json::Value& _jsonTrace, const ExecutionResult for ( auto&& item : m_standardTrace.getAccessedAccounts() ) { printAllAccessedAccountPreValues( _jsonTrace, _statePre, item ); }; + + + auto minerAddress = m_standardTrace.getBlockAuthor(); + + if ( m_standardTrace.getAccessedAccounts().count( minerAddress ) == 0 ) { + // to be compatible with geth always print miner balance + // miner balance is not in the list of accessed accounts, print it anyway + Json::Value minerValue; + minerValue["balance"] = + AlethStandardTrace::toGethCompatibleCompactHexPrefixed( _statePre.balance( minerAddress ) ); + _jsonTrace[toHexPrefixed( minerAddress )] = minerValue; + } } } + void PrestateTracePrinter::printDiff( Json::Value& _jsonTrace, const ExecutionResult&, const HistoricState& _statePre, const HistoricState& _statePost ) { STATE_CHECK( _jsonTrace.isObject() ) @@ -61,27 +74,26 @@ void PrestateTracePrinter::printAllAccessedAccountPreValues( STATE_CHECK( _jsonTrace.isObject() ) - Json::Value storagePreValues; + Json::Value accountPreValues; // if this _address did not exist, we do not include it in the diff if ( !_statePre.addressInUse( _address ) ) return; auto balance = _statePre.balance( _address ); - if (m_standardTrace.isCall() && _address == m_standardTrace.getFrom()) { + if ( m_standardTrace.isCall() && _address == m_standardTrace.getFrom() ) { // take into account that for calls balance is modified in the state before execution balance = m_standardTrace.getOriginalFromBalance(); } else { // geth does not print nonce for from address in debug_traceCall; - storagePreValues["nonce"] = ( uint64_t ) _statePre.getNonce( _address ); + accountPreValues["nonce"] = ( uint64_t ) _statePre.getNonce( _address ); } - storagePreValues["balance"] = - AlethStandardTrace::toGethCompatibleCompactHexPrefixed( balance ); + accountPreValues["balance"] = AlethStandardTrace::toGethCompatibleCompactHexPrefixed( balance ); bytes const& code = _statePre.code( _address ); if ( code != NullBytes ) { - storagePreValues["code"] = toHexPrefixed( code ); + accountPreValues["code"] = toHexPrefixed( code ); } Json::Value storagePairs; @@ -102,12 +114,12 @@ void PrestateTracePrinter::printAllAccessedAccountPreValues( } if ( storagePairs ) { - storagePreValues["storage"] = storagePairs; + accountPreValues["storage"] = storagePairs; } // if nothing changed we do not add it to the diff - if ( storagePreValues ) - _jsonTrace[toHexPrefixed( _address )] = storagePreValues; + if ( accountPreValues ) + _jsonTrace[toHexPrefixed( _address )] = accountPreValues; }