From f4ebfc73376912b7b7e794856fd83d3fd31225a2 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Tue, 4 Jul 2023 13:21:41 +0100 Subject: [PATCH 001/159] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3f67e25ce..c5b45eb7b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.17.0 +3.18.0 From 9777e762096ab13725dd2dea7200c90826cdd57a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 4 Jul 2023 16:34:06 +0100 Subject: [PATCH 002/159] SKALED-1575 Create docker tag N.M.K-latest --- scripts/build_and_publish.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/build_and_publish.sh b/scripts/build_and_publish.sh index 366c6bc7b..b46116436 100644 --- a/scripts/build_and_publish.sh +++ b/scripts/build_and_publish.sh @@ -9,14 +9,8 @@ NAME=schain REPO_NAME=skalenetwork/$NAME IMAGE_NAME=$REPO_NAME:$VERSION -LABEL="develop" -if [ $BRANCH = "stable" ] -then - LABEL="stable" -elif [ $BRANCH = "beta" ] -then - LABEL="beta" -fi +LABEL="$BRANCH" + LATEST_IMAGE_NAME=$REPO_NAME:$LABEL-latest if [[ $VERSION == *"historic" ]] From 2a14037c7908a3562a49a54c682779f8e17bcfa0 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 4 Jul 2023 17:58:12 +0100 Subject: [PATCH 003/159] Use versions without "v"- --- scripts/build_and_publish.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/build_and_publish.sh b/scripts/build_and_publish.sh index b46116436..f486f273e 100644 --- a/scripts/build_and_publish.sh +++ b/scripts/build_and_publish.sh @@ -9,8 +9,9 @@ NAME=schain REPO_NAME=skalenetwork/$NAME IMAGE_NAME=$REPO_NAME:$VERSION -LABEL="$BRANCH" - +# 3.17.0-develop.22 -> 3.17.0-develop +# 3.17.0-develop.22-hostoric -> 3.17.0-develop +LABEL="${VERSION%.*}" LATEST_IMAGE_NAME=$REPO_NAME:$LABEL-latest if [[ $VERSION == *"historic" ]] From 7fbda2b29f5b82422c92be2598910ea62380cd79 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 4 Jul 2023 18:10:01 +0100 Subject: [PATCH 004/159] Special case for stable branch --- scripts/build_and_publish.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/build_and_publish.sh b/scripts/build_and_publish.sh index f486f273e..9a0e32f12 100644 --- a/scripts/build_and_publish.sh +++ b/scripts/build_and_publish.sh @@ -12,6 +12,14 @@ IMAGE_NAME=$REPO_NAME:$VERSION # 3.17.0-develop.22 -> 3.17.0-develop # 3.17.0-develop.22-hostoric -> 3.17.0-develop LABEL="${VERSION%.*}" + +# 3.17.0 -> 3.17.0 +# 3.17.0-historic -> 3.17.0 +if [[ "$BRANCH" == "stable" ]] +then + LABEL=${VERSION%-historic} +fi + LATEST_IMAGE_NAME=$REPO_NAME:$LABEL-latest if [[ $VERSION == *"historic" ]] From 7bc3f3df5f929e1043a4b2e36b91b411417b1d54 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 5 Jul 2023 15:22:15 +0100 Subject: [PATCH 005/159] SKALED-1575 Push latest image --- scripts/build_and_publish.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/build_and_publish.sh b/scripts/build_and_publish.sh index 9a0e32f12..f02f0b0c0 100644 --- a/scripts/build_and_publish.sh +++ b/scripts/build_and_publish.sh @@ -47,8 +47,4 @@ echo "Built $IMAGE_NAME" echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin docker push $IMAGE_NAME || exit $? - -if [ $BRANCH = $LABEL ] -then - docker push $LATEST_IMAGE_NAME || exit $? -fi +docker push $LATEST_IMAGE_NAME || exit $? From a7cf816b43fa90a89661e5cf237ab0ba90809698 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 7 Sep 2023 12:39:53 +0100 Subject: [PATCH 006/159] SKALED-1623 Don't force exit on signal after internal exit --- libdevcore/Common.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index 9828da2cc..e7135ae4c 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -47,11 +47,18 @@ void ExitHandler::exitHandler( int s ) { } void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { - std::string strMessagePrefix = ExitHandler::shouldExit() ? - cc::error( "\nStop flag was already raised on. " ) + - cc::fatal( "WILL FORCE TERMINATE." ) + - cc::error( " Caught (second) signal. " ) : - cc::error( "\nCaught (first) signal. " ); + std::string strMessagePrefix; + if ( nSignalNo > 0 ) { + strMessagePrefix = ( ExitHandler::shouldExit() && s_nStopSignal > 0 ) ? + cc::error( "\nStop flag was already raised on. " ) + + cc::fatal( "WILL FORCE TERMINATE." ) + + cc::error( " Caught (second) signal. " ) : + cc::error( "\nCaught (first) signal. " ); + } else { + strMessagePrefix = ExitHandler::shouldExit() ? + cc::error( "\nInternal exit initiated. " ) : + cc::error( "\nInternal exit requested while already exiting. " ); + } std::cerr << strMessagePrefix << cc::error( skutils::signal::signal2str( nSignalNo ) ) << "\n\n"; std::cerr.flush(); @@ -153,7 +160,8 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { // nice exit here: - if ( ExitHandler::shouldExit() ) { + // TODO deduplicate with first if() + if ( ExitHandler::shouldExit() && s_nStopSignal > 0 && nSignalNo > 0 ) { std::cerr << ( "\n" + cc::fatal( "SIGNAL-HANDLER:" ) + " " + cc::error( "Will force exit now..." ) + "\n\n" ); _exit( 13 ); From 195974f245492475a726654d73c4d7b243606243 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 13 Sep 2023 12:01:25 +0100 Subject: [PATCH 007/159] 1619 add content-type to header --- libskutils/src/http_pg.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libskutils/src/http_pg.cpp b/libskutils/src/http_pg.cpp index fc2fb766d..83952d64c 100644 --- a/libskutils/src/http_pg.cpp +++ b/libskutils/src/http_pg.cpp @@ -203,6 +203,7 @@ void request_site::onEOM() noexcept { } else { std::string strOut = rslt.joOut_.dump(); bldr.header( "content-length", skutils::tools::format( "%zu", strOut.size() ) ); + bldr.header( "Content-Type", "application/json" ); bldr.body( strOut ); } bldr.sendWithEOM(); From 2b22a450386a940999206593368802e0360652d6 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 15 Sep 2023 12:51:33 +0000 Subject: [PATCH 008/159] 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 009/159] 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 010/159] 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 a3a46ded6706e29706b0fbb46a670e776a15609c Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 26 Sep 2023 17:13:21 +0100 Subject: [PATCH 011/159] 1550 reenable cat cycle test --- .github/workflows/functional-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index 489c82421..14d743434 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -65,8 +65,8 @@ - name: skaled+load_python+all run: SKALED_PROVIDER=skaled_providers/binary_from_container ./run_tests.sh skaled+load_python+all - # - name: skaled+load_js+run_angry_cats - # run: SKALED_PROVIDER=skaled_providers/endpoint_by_container ./run_tests.sh skaled+load_js+run_angry_cats + - name: skaled+load_js+run_angry_cats + run: SKALED_PROVIDER=skaled_providers/endpoint_by_container ./run_tests.sh skaled+load_js+run_angry_cats - name: skaled+internals+test_snapshot_api run: SKALED_PROVIDER=skaled_providers/binary_from_container ./run_tests.sh skaled+internals+test_snapshot_api From 8feadd2cb96daeda617241fb111a2bfcfdffbbf1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 28 Sep 2023 18:41:28 +0100 Subject: [PATCH 012/159] 1198 handle params in blockNumber --- libweb3jsonrpc/Eth.cpp | 5 ++++- libweb3jsonrpc/Eth.h | 2 +- libweb3jsonrpc/EthFace.h | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 42f89a002..a9feea08d 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -110,7 +110,10 @@ Json::Value Eth::eth_accounts() { return toJson( m_ethAccounts.allAccounts() ); } -string Eth::eth_blockNumber() { +string Eth::eth_blockNumber( const Json::Value& request ) { + if ( !request.empty() ) { + BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); + } return toJS( client()->number() ); } diff --git a/libweb3jsonrpc/Eth.h b/libweb3jsonrpc/Eth.h index ee661dbdd..12e029aa3 100644 --- a/libweb3jsonrpc/Eth.h +++ b/libweb3jsonrpc/Eth.h @@ -77,7 +77,7 @@ class Eth : public dev::rpc::EthFace, public skutils::json_config_file_accessor virtual bool eth_mining() override; virtual std::string eth_gasPrice() override; virtual Json::Value eth_accounts() override; - virtual std::string eth_blockNumber() override; + virtual std::string eth_blockNumber( const Json::Value& request ) override; virtual std::string eth_getBalance( std::string const& _address, std::string const& _blockNumber ) override; virtual std::string eth_getStorageAt( std::string const& _address, std::string const& _position, diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 7c31b4f62..648d4424c 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -244,8 +244,7 @@ class EthFace : public ServerInterface< EthFace > { response = this->eth_accounts(); } inline virtual void eth_blockNumberI( const Json::Value& request, Json::Value& response ) { - ( void ) request; - response = this->eth_blockNumber(); + response = this->eth_blockNumber( request ); } inline virtual void eth_getBalanceI( const Json::Value& request, Json::Value& response ) { response = this->eth_getBalance( request[0u].asString(), request[1u].asString() ); @@ -432,7 +431,7 @@ class EthFace : public ServerInterface< EthFace > { virtual bool eth_mining() = 0; virtual std::string eth_gasPrice() = 0; virtual Json::Value eth_accounts() = 0; - virtual std::string eth_blockNumber() = 0; + virtual std::string eth_blockNumber( const Json::Value& request ) = 0; virtual std::string eth_getBalance( const std::string& param1, const std::string& param2 ) = 0; virtual std::string eth_getStorageAt( const std::string& param1, const std::string& param2, const std::string& param3 ) = 0; From 334e06417081fd935495c937fcbb340ba13f3f84 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 3 Oct 2023 13:14:57 +0100 Subject: [PATCH 013/159] 1482 update consensus for db usage call fix --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 5a9b85d8f..2a4cd3f5b 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 5a9b85d8f171e1ba5f7dfe244cff70e0e39aa5f4 +Subproject commit 2a4cd3f5b21000c7f1c6c5346491082729dc43d1 From 4434e5192ddab2dcd18b58d57b8c90e2d967fd26 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 9 Oct 2023 15:19:04 +0100 Subject: [PATCH 014/159] 1482 update consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 2a4cd3f5b..ef26c4a02 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 2a4cd3f5b21000c7f1c6c5346491082729dc43d1 +Subproject commit ef26c4a020884f280addd9b54037ee77fe396ecf From fed1457ed51fdde76a07abaaead3d51bb7a64283 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 Oct 2023 11:23:06 +0100 Subject: [PATCH 015/159] 1689 fix microprofile option --- libdevcore/CMakeLists.txt | 5 +++-- skaled/main.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index 19f5f4b85..99d179d1e 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -15,8 +15,9 @@ add_library(devcore ${sources} ${headers}) add_dependencies(devcore secp256k1) target_compile_options( devcore PRIVATE - -Wno-error=deprecated-copy -Wno-error=unused-result -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=maybe-uninitialized - ) + -Wno-error=deprecated-copy -Wno-error=unused-result -Wno-error=unused-parameter + -Wno-error=unused-variable -Wno-error=maybe-uninitialized -Wno-error=class-memaccess +) # Needed to prevent including system-level boost headers: target_include_directories(devcore SYSTEM PUBLIC ${Boost_INCLUDE_DIR} PRIVATE ../utils) diff --git a/skaled/main.cpp b/skaled/main.cpp index 8118b017e..d33635a2f 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -550,6 +550,7 @@ int main( int argc, char** argv ) try { cc::_on_ = false; cc::_max_value_size_ = 2048; MicroProfileSetEnableAllGroups( true ); + dev::setThreadName( "main" ); BlockHeader::useTimestampHack = false; srand( time( nullptr ) ); setCLocale(); @@ -2773,7 +2774,6 @@ int main( int argc, char** argv ) try { << cc::debug( "Done, programmatic shutdown via Web3 is disabled" ); } - dev::setThreadName( "main" ); if ( g_client ) { unsigned int n = g_client->blockChain().details().number; unsigned int mining = 0; From 9692d78e2f061ff1b944fe42f865869497d33489 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 17 Oct 2023 19:43:41 +0100 Subject: [PATCH 016/159] SKALED-1623 Logs fix --- libdevcore/Common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index dcdc348fd..26a99db7f 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -56,8 +56,8 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { cc::error( "\nCaught (first) signal. " ); } else { strMessagePrefix = ExitHandler::shouldExit() ? - cc::error( "\nInternal exit initiated. " ) : - cc::error( "\nInternal exit requested while already exiting. " ); + cc::error( "\nInternal exit requested while already exiting. " ) : + cc::error( "\nInternal exit initiated. " ); } std::cerr << strMessagePrefix << cc::error( skutils::signal::signal2str( nSignalNo ) ) << "\n\n"; From 4a0e3905e5f12b29cede8c372a84e62402226fff Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 18 Oct 2023 11:59:09 +0000 Subject: [PATCH 017/159] 1640 drop broadcast txns if skaled has outdated state --- libethereum/SkaleHost.cpp | 9 +++++++++ libethereum/SkaleHost.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 8a3b54109..c612c9c79 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -66,6 +66,8 @@ using namespace dev::eth; #define CONSENSUS 1 #endif +const int SkaleHost::REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC = 360; + std::unique_ptr< ConsensusInterface > DefaultConsensusFactory::create( ConsensusExtFace& _extFace ) const { #if CONSENSUS @@ -325,6 +327,13 @@ void SkaleHost::logState() { } h256 SkaleHost::receiveTransaction( std::string _rlp ) { + // drop incoming transactions if skaled has an outdated state + if ( m_client.bc().info( m_client.bc().currentHash() ).timestamp() + + REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC < + std::time( NULL ) ) { + return h256(); + } + Transaction transaction( jsToBytes( _rlp, OnFailed::Throw ), CheckTransaction::None ); h256 sha = transaction.sha3(); diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index bb79d5d60..0069a8e56 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -214,4 +214,8 @@ class SkaleHost { std::atomic_int total_sent, total_arrived; boost::chrono::high_resolution_clock::time_point latestBlockTime; + + // reject old transactions that come through broadcast + // if current ts is much bigger than currentBlock.ts + static const int REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC; }; From b2104059d2166ababe4a5d61f1f01a61717dfbdc Mon Sep 17 00:00:00 2001 From: Oleh Date: Wed, 18 Oct 2023 13:24:29 +0100 Subject: [PATCH 018/159] 1640 drop broadcast transactions if skaled has outdated state --- libethereum/SkaleHost.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index c612c9c79..50bedcd66 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -328,8 +328,7 @@ void SkaleHost::logState() { h256 SkaleHost::receiveTransaction( std::string _rlp ) { // drop incoming transactions if skaled has an outdated state - if ( m_client.bc().info( m_client.bc().currentHash() ).timestamp() + - REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC < + if ( m_client.bc().info().timestamp() + REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC < std::time( NULL ) ) { return h256(); } From aac143fa1fbf60c9058b202bda0014c432e86f98 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 18 Oct 2023 15:46:34 +0100 Subject: [PATCH 019/159] 1640 add logs when dropping txn through broadcast --- libethereum/SkaleHost.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 50bedcd66..65fb0f143 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -330,6 +330,7 @@ h256 SkaleHost::receiveTransaction( std::string _rlp ) { // drop incoming transactions if skaled has an outdated state if ( m_client.bc().info().timestamp() + REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC < std::time( NULL ) ) { + LOG( m_debugLogger ) << "Dropped the transaction received through broadcast"; return h256(); } From cd4698945f8c0ee6d54b996b4d385cd1f6c03bac Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:56:42 +0100 Subject: [PATCH 020/159] new op codes --- libevm/Instruction.cpp | 4 + libevm/Instruction.h | 1 + libevm/LegacyVM.cpp | 12 +++ libevm/LegacyVMConfig.h | 2 +- .../historicstate/hardhat/contracts/Push0.sol | 15 ++++ .../hardhat/scripts/push0_test.ts | 84 +++++++++++++++++++ 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/historicstate/hardhat/contracts/Push0.sol create mode 100644 test/historicstate/hardhat/scripts/push0_test.ts diff --git a/libevm/Instruction.cpp b/libevm/Instruction.cpp index 78e8eec2d..bb4f25d20 100644 --- a/libevm/Instruction.cpp +++ b/libevm/Instruction.cpp @@ -86,6 +86,10 @@ static const std::map c_instructionInfo = { Instruction::MSIZE, { "MSIZE", 0, 1, Tier::Base } }, { Instruction::GAS, { "GAS", 0, 1, Tier::Base } }, { Instruction::JUMPDEST, { "JUMPDEST", 0, 0, Tier::Special } }, + // As per EIP-3855 PUSH0 instruction tire is base (2 gas units) + // As all other PUSH instructions, it removes zero elements from stack and + // pushes 1 element to stack + { Instruction::PUSH0, { "PUSH0", 0, 1, Tier::Base } }, { Instruction::PUSH1, { "PUSH1", 0, 1, Tier::VeryLow } }, { Instruction::PUSH2, { "PUSH2", 0, 1, Tier::VeryLow } }, { Instruction::PUSH3, { "PUSH3", 0, 1, Tier::VeryLow } }, diff --git a/libevm/Instruction.h b/libevm/Instruction.h index 573b57107..44c35ad6b 100644 --- a/libevm/Instruction.h +++ b/libevm/Instruction.h @@ -94,6 +94,7 @@ enum class Instruction : uint8_t { GAS, ///< get the amount of available gas JUMPDEST, ///< set a potential jump destination + PUSH0 = 0x5f, // EIP-3855 PUSH1 = 0x60, ///< place 1 byte item on stack PUSH2, ///< place 2 byte item on stack PUSH3, ///< place 3 byte item on stack diff --git a/libevm/LegacyVM.cpp b/libevm/LegacyVM.cpp index 8a0775112..5f2f0f772 100644 --- a/libevm/LegacyVM.cpp +++ b/libevm/LegacyVM.cpp @@ -1355,6 +1355,18 @@ void LegacyVM::interpretCases() { } CONTINUE + // EIP-3855. Code PUSH0 is similar to PUSH1 but pushes 0 + CASE( PUSH0 ) { + //throwBadInstruction(); + ON_OP(); + updateIOGas(); + ++m_PC; + m_SPP[0] = 0; + ++m_PC; + } + CONTINUE + + CASE( PUSH1 ) { ON_OP(); updateIOGas(); diff --git a/libevm/LegacyVMConfig.h b/libevm/LegacyVMConfig.h index 4b8bde611..9908d712c 100644 --- a/libevm/LegacyVMConfig.h +++ b/libevm/LegacyVMConfig.h @@ -254,7 +254,7 @@ namespace eth { &&BEGINDATA, \ &&BEGINSUB, \ &&INVALID, \ - &&INVALID, \ + &&PUSH0, /* EIP-3855 */ \ &&PUSH1, /* 60, */ \ &&PUSH2, \ &&PUSH3, \ diff --git a/test/historicstate/hardhat/contracts/Push0.sol b/test/historicstate/hardhat/contracts/Push0.sol new file mode 100644 index 000000000..a2ffc4522 --- /dev/null +++ b/test/historicstate/hardhat/contracts/Push0.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.9; + +contract Push0 { + + //uint256 public constant ZERO = 0; + + function getZero() public { + // this trigger compiler using push0 to stack since operations use lots of zeros + // uint256 one = 0; + //one = one + 1 + ZERO; + //uint256 two = one * 0; + //uint256 three = one * ZERO; + } +} \ No newline at end of file diff --git a/test/historicstate/hardhat/scripts/push0_test.ts b/test/historicstate/hardhat/scripts/push0_test.ts new file mode 100644 index 000000000..20c9f700a --- /dev/null +++ b/test/historicstate/hardhat/scripts/push0_test.ts @@ -0,0 +1,84 @@ +const OWNER_ADDRESS: string = "0x907cd0881E50d359bb9Fd120B1A5A143b1C97De6"; +const ZERO_ADDRESS: string = "0xO000000000000000000000000000000000000000"; +const INITIAL_MINT: bigint = 10000000000000000000000000000000000000000n; + +import {ethers} from "hardhat"; + +async function waitUntilNextBlock() { + + const current = await hre.ethers.provider.getBlockNumber(); + let newBlock = current; + console.log(`BLOCK_NUMBER ${current}`); + + while (newBlock == current) { + newBlock = await hre.ethers.provider.getBlockNumber(); + } + + console.log(`BLOCK_NUMBER ${newBlock}`); + + return current; + +} + +function CHECK(result: any): void { + if (!result) { + const message: string = `Check failed ${result}` + console.log(message); + throw message; + } +} + +async function getAndPrintTrace(hash: string): Promise { +// const trace = await ethers.provider.send('debug_traceTransaction', [hash, {"tracer":"prestateTracer", +// "tracerConfig": {"diffMode":true}}]); + +// const trace = await ethers.provider.send('debug_traceTransaction', [hash, {"tracer": "callTracer", +// "tracerConfig": {"withLog":true}}]); + + const trace = await ethers.provider.send('debug_traceTransaction', [hash, {}]); + + + + console.log(JSON.stringify(trace, null, 4)); + return trace; +} + +async function deployWriteAndDestroy(): Promise { + + console.log(`Deploying ...`); + + const Push0Test = await ethers.getContractFactory("Push0"); + const test = await Push0Test.deploy(); + const testContract = await test.deployed(); + + + const deployBn = await ethers.provider.getBlockNumber(); + + const hash = testContract.deployTransaction.hash; + console.log(`Gas limit ${testContract.deployTransaction.gasLimit}`); + console.log(`Contract deployed to ${testContract.address} at block ${deployBn} tx hash ${hash}`); + + + // await waitUntilNextBlock() + + await getAndPrintTrace(hash) + + + console.log(`Now testing`); + + const transferReceipt = await testContract.getZero() + console.log(`Gas limit ${transferReceipt.gasLimit}`); + + +} + +async function main(): Promise { + await deployWriteAndDestroy(); +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main().catch((error: any) => { + console.error(error); + process.exitCode = 1; +}); \ No newline at end of file From 83379f9309aa55ce9e7c354e41027096d3bb43fe Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:44:02 +0100 Subject: [PATCH 021/159] 1700 push zero --- libethcore/ChainOperationParams.h | 2 ++ libethereum/ChainParams.cpp | 7 +++++ libethereum/Client.cpp | 3 +++ libethereum/ValidationSchemes.cpp | 2 ++ libevm/LegacyVM.cpp | 10 ++++--- libskale/CMakeLists.txt | 1 + libskale/PushZeroPatch.cpp | 11 ++++++++ libskale/PushZeroPatch.h | 27 +++++++++++++++++++ test/historicstate/configs/basic_config.json | 3 ++- .../historicstate/hardhat/contracts/Push0.sol | 14 +++++----- test/historicstate/hardhat/hardhat.config.js | 2 +- .../hardhat/scripts/push0_test.ts | 2 +- 12 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 libskale/PushZeroPatch.cpp create mode 100644 libskale/PushZeroPatch.h diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index ddab8e679..3fba5e1a7 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -175,6 +175,8 @@ struct SChain { time_t verifyDaSigsPatchTimestamp = 0; time_t storageDestructionPatchTimestamp = 0; time_t powCheckPatchTimestamp = 0; + time_t pushZeroPatchTimestamp = 0; + SChain() { name = "TestChain"; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 6b4693a9e..d4d9c6913 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -266,6 +266,13 @@ ChainParams ChainParams::loadConfig( sChainObj.at( "powCheckPatchTimestamp" ).get_int64() : 0; + s.pushZeroPatchTimestamp = + sChainObj.count( "pushZeroPatchTimestamp" ) ? + sChainObj.at( "pushZeroPatchTimestamp" ).get_int64() : + 0; + + + if ( sChainObj.count( "nodeGroups" ) ) { std::vector< NodeGroup > nodeGroups; for ( const auto& nodeGroupConf : sChainObj["nodeGroups"].get_obj() ) { diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 36e651e0c..e00139f2e 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -162,6 +163,7 @@ Client::Client( ChainParams const& _params, int _networkID, RevertableFSPatch::setTimestamp( chainParams().sChain.revertableFSPatchTimestamp ); StorageDestructionPatch::setTimestamp( chainParams().sChain.storageDestructionPatchTimestamp ); POWCheckPatch::setTimestamp( chainParams().sChain.powCheckPatchTimestamp ); + PushZeroPatch::setTimestamp( chainParams().sChain.pushZeroPatchTimestamp ); } @@ -654,6 +656,7 @@ size_t Client::syncTransactions( RevertableFSPatch::lastBlockTimestamp = blockChain().info().timestamp(); StorageDestructionPatch::lastBlockTimestamp = blockChain().info().timestamp(); POWCheckPatch::lastBlockTimestamp = blockChain().info().timestamp(); + PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp(); DEV_WRITE_GUARDED( x_working ) { diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index cebb16c8e..ae4fc2068 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -268,6 +268,8 @@ void validateConfigJson( js::mObject const& _obj ) { { "storageDestructionPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "powCheckPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, + { "pushZeroPatchTimestamp", + { { js::int_type }, JsonFieldPresence::Optional } }, { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } } } ); js::mArray const& nodes = sChain.at( "nodes" ).get_array(); diff --git a/libevm/LegacyVM.cpp b/libevm/LegacyVM.cpp index 5f2f0f772..757a02823 100644 --- a/libevm/LegacyVM.cpp +++ b/libevm/LegacyVM.cpp @@ -15,6 +15,7 @@ along with cpp-ethereum. If not, see . */ +#include "libskale/PushZeroPatch.h" #include "LegacyVM.h" using namespace std; @@ -1356,14 +1357,17 @@ void LegacyVM::interpretCases() { CONTINUE // EIP-3855. Code PUSH0 is similar to PUSH1 but pushes 0 + // we need to increment program counter only by one since + // the value is not read from program code as in PUSH1 CASE( PUSH0 ) { - //throwBadInstruction(); + if (!PushZeroPatch::isEnabled()) { + throwBadInstruction(); + } ON_OP(); updateIOGas(); - ++m_PC; m_SPP[0] = 0; ++m_PC; - } + }; CONTINUE diff --git a/libskale/CMakeLists.txt b/libskale/CMakeLists.txt index cad33c885..d83455e63 100644 --- a/libskale/CMakeLists.txt +++ b/libskale/CMakeLists.txt @@ -20,6 +20,7 @@ set(sources OverlayFS.cpp StorageDestructionPatch.cpp POWCheckPatch.cpp + PushZeroPatch.cpp ) set(headers diff --git a/libskale/PushZeroPatch.cpp b/libskale/PushZeroPatch.cpp new file mode 100644 index 000000000..e7ef4f6c1 --- /dev/null +++ b/libskale/PushZeroPatch.cpp @@ -0,0 +1,11 @@ +#include "PushZeroPatch.h" + +time_t PushZeroPatch::pushZeroPatchTimestamp; +time_t PushZeroPatch::lastBlockTimestamp; + +bool PushZeroPatch::isEnabled() { + if ( pushZeroPatchTimestamp == 0 ) { + return false; + } + return pushZeroPatchTimestamp <= lastBlockTimestamp; +} diff --git a/libskale/PushZeroPatch.h b/libskale/PushZeroPatch.h new file mode 100644 index 000000000..6ebab4e9f --- /dev/null +++ b/libskale/PushZeroPatch.h @@ -0,0 +1,27 @@ +#include +#include + +namespace dev { +namespace eth { +class Client; +} +} // namespace dev + +/* + * Context: enable effective storage destruction + */ +class PushZeroPatch : public SchainPatch { +public: + static bool isEnabled(); + + static void setTimestamp( time_t _timeStamp ) { + printInfo( __FILE__, _timeStamp ); + pushZeroPatchTimestamp = _timeStamp; + } + + +private: + friend class dev::eth::Client; + static time_t pushZeroPatchTimestamp; + static time_t lastBlockTimestamp; +}; \ No newline at end of file diff --git a/test/historicstate/configs/basic_config.json b/test/historicstate/configs/basic_config.json index aa5915277..ea3bbf1d6 100644 --- a/test/historicstate/configs/basic_config.json +++ b/test/historicstate/configs/basic_config.json @@ -322,10 +322,11 @@ "sChain": { "schainName": "TestChain", - "schainID": 1, + "schainID": 5, "schainOwner": "0x907cd0881E50d359bb9Fd120B1A5A143b1C97De6", "contractStorageLimit": 10000000000, "emptyBlockIntervalMs": 10000, + "pushZeroPatchTimestamp": 1, "nodes": [ { "nodeID": 1112, "ip": "127.0.0.1", "basePort": 1231, "schainIndex" : 1, "publicKey":""} ] diff --git a/test/historicstate/hardhat/contracts/Push0.sol b/test/historicstate/hardhat/contracts/Push0.sol index a2ffc4522..e09e457b6 100644 --- a/test/historicstate/hardhat/contracts/Push0.sol +++ b/test/historicstate/hardhat/contracts/Push0.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.9; +pragma solidity ^0.8.20; contract Push0 { - //uint256 public constant ZERO = 0; + uint256 public constant ZERO = 0; function getZero() public { - // this trigger compiler using push0 to stack since operations use lots of zeros - // uint256 one = 0; - //one = one + 1 + ZERO; - //uint256 two = one * 0; - //uint256 three = one * ZERO; + // this triggers compiler using push0 to stack since operations use lots of zeros + uint256 one = 0; + one = one + 1 + ZERO; + uint256 two = one * 0; + uint256 three = one * ZERO; } } \ No newline at end of file diff --git a/test/historicstate/hardhat/hardhat.config.js b/test/historicstate/hardhat/hardhat.config.js index d369e02ba..3ff48bfba 100644 --- a/test/historicstate/hardhat/hardhat.config.js +++ b/test/historicstate/hardhat/hardhat.config.js @@ -10,7 +10,7 @@ module.exports = { const INSECURE_PRIVATE_KEY = "bd200f4e7f597f3c2c77fb405ee7fabeb249f63f03f43d5927b4fa0c43cfe85e"; module.exports = { - solidity: "0.8.9", + solidity: "0.8.20", networks: { skaled: { url: `http://localhost:1234`, diff --git a/test/historicstate/hardhat/scripts/push0_test.ts b/test/historicstate/hardhat/scripts/push0_test.ts index 20c9f700a..18446a589 100644 --- a/test/historicstate/hardhat/scripts/push0_test.ts +++ b/test/historicstate/hardhat/scripts/push0_test.ts @@ -61,7 +61,7 @@ async function deployWriteAndDestroy(): Promise { // await waitUntilNextBlock() - await getAndPrintTrace(hash) + //await getAndPrintTrace(hash) console.log(`Now testing`); From bbd707dd80e776e9afd488e64a88ce0e65ed08a2 Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:55:46 +0100 Subject: [PATCH 022/159] 1700 PUSHD --- libethereum/ChainParams.cpp | 8 +++----- libethereum/ValidationSchemes.cpp | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index d4d9c6913..a1706b858 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -266,11 +266,9 @@ ChainParams ChainParams::loadConfig( sChainObj.at( "powCheckPatchTimestamp" ).get_int64() : 0; - s.pushZeroPatchTimestamp = - sChainObj.count( "pushZeroPatchTimestamp" ) ? - sChainObj.at( "pushZeroPatchTimestamp" ).get_int64() : - 0; - + s.pushZeroPatchTimestamp = sChainObj.count( "pushZeroPatchTimestamp" ) ? + sChainObj.at( "pushZeroPatchTimestamp" ).get_int64() : + 0; if ( sChainObj.count( "nodeGroups" ) ) { diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index ae4fc2068..2765ebb59 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -268,8 +268,7 @@ void validateConfigJson( js::mObject const& _obj ) { { "storageDestructionPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "powCheckPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, - { "pushZeroPatchTimestamp", - { { js::int_type }, JsonFieldPresence::Optional } }, + { "pushZeroPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } } } ); js::mArray const& nodes = sChain.at( "nodes" ).get_array(); From 33502b101d746c5cfcebd036a9b35f2360c1a657 Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:01:26 +0100 Subject: [PATCH 023/159] 1700 add pushd --- libevm/Instruction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevm/Instruction.h b/libevm/Instruction.h index 44c35ad6b..0dc52bdad 100644 --- a/libevm/Instruction.h +++ b/libevm/Instruction.h @@ -94,7 +94,7 @@ enum class Instruction : uint8_t { GAS, ///< get the amount of available gas JUMPDEST, ///< set a potential jump destination - PUSH0 = 0x5f, // EIP-3855 + PUSH0 = 0x5f, // EIP-3855 PUSH1 = 0x60, ///< place 1 byte item on stack PUSH2, ///< place 2 byte item on stack PUSH3, ///< place 3 byte item on stack From aad381b41f8b4299234e9187cc4f987beff068bc Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:03:30 +0100 Subject: [PATCH 024/159] 1700 clang format --- libevm/LegacyVM.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libevm/LegacyVM.cpp b/libevm/LegacyVM.cpp index 757a02823..098e6624f 100644 --- a/libevm/LegacyVM.cpp +++ b/libevm/LegacyVM.cpp @@ -15,8 +15,8 @@ along with cpp-ethereum. If not, see . */ -#include "libskale/PushZeroPatch.h" #include "LegacyVM.h" +#include "libskale/PushZeroPatch.h" using namespace std; using namespace dev; @@ -28,12 +28,12 @@ uint64_t LegacyVM::memNeed( u256 const& _offset, u256 const& _size ) { template < class S > S divWorkaround( S const& _a, S const& _b ) { - return ( S )( s512( _a ) / s512( _b ) ); + return ( S ) ( s512( _a ) / s512( _b ) ); } template < class S > S modWorkaround( S const& _a, S const& _b ) { - return ( S )( s512( _a ) % s512( _b ) ); + return ( S ) ( s512( _a ) % s512( _b ) ); } @@ -354,7 +354,7 @@ void LegacyVM::interpretCases() { updateMem( toInt63( m_SP[0] ) + 1 ); updateIOGas(); - m_mem[( unsigned ) m_SP[0]] = ( _byte_ )( m_SP[1] & 0xff ); + m_mem[( unsigned ) m_SP[0]] = ( _byte_ ) ( m_SP[1] & 0xff ); } NEXT @@ -1083,7 +1083,9 @@ void LegacyVM::interpretCases() { CASE( XPUT ) CASE( XGET ) CASE( XSWIZZLE ) - CASE( XSHUFFLE ) { throwBadInstruction(); } + CASE( XSHUFFLE ) { + throwBadInstruction(); + } CONTINUE #endif @@ -1360,7 +1362,7 @@ void LegacyVM::interpretCases() { // we need to increment program counter only by one since // the value is not read from program code as in PUSH1 CASE( PUSH0 ) { - if (!PushZeroPatch::isEnabled()) { + if ( !PushZeroPatch::isEnabled() ) { throwBadInstruction(); } ON_OP(); From 53f4ecf37505f33c42edc941028147526fbb928a Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:06:42 +0100 Subject: [PATCH 025/159] 1700 clang format --- libevm/LegacyVM.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libevm/LegacyVM.cpp b/libevm/LegacyVM.cpp index 098e6624f..a987a3b0c 100644 --- a/libevm/LegacyVM.cpp +++ b/libevm/LegacyVM.cpp @@ -28,12 +28,12 @@ uint64_t LegacyVM::memNeed( u256 const& _offset, u256 const& _size ) { template < class S > S divWorkaround( S const& _a, S const& _b ) { - return ( S ) ( s512( _a ) / s512( _b ) ); + return ( S )( s512( _a ) / s512( _b ) ); } template < class S > S modWorkaround( S const& _a, S const& _b ) { - return ( S ) ( s512( _a ) % s512( _b ) ); + return ( S )( s512( _a ) % s512( _b ) ); } @@ -354,7 +354,7 @@ void LegacyVM::interpretCases() { updateMem( toInt63( m_SP[0] ) + 1 ); updateIOGas(); - m_mem[( unsigned ) m_SP[0]] = ( _byte_ ) ( m_SP[1] & 0xff ); + m_mem[( unsigned ) m_SP[0]] = ( _byte_ )( m_SP[1] & 0xff ); } NEXT @@ -1083,9 +1083,7 @@ void LegacyVM::interpretCases() { CASE( XPUT ) CASE( XGET ) CASE( XSWIZZLE ) - CASE( XSHUFFLE ) { - throwBadInstruction(); - } + CASE( XSHUFFLE ) { throwBadInstruction(); } CONTINUE #endif From 71f75faa2dca55440b1b3d30225a2d548ea1b166 Mon Sep 17 00:00:00 2001 From: kladkogex <13399135+kladkogex@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:09:31 +0100 Subject: [PATCH 026/159] 1700 clang format --- libethereum/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index e00139f2e..0cc6b9ca8 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -54,11 +54,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include From 685fd9176132db9ec9f3e4709eeaf2153022a570 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 20 Oct 2023 17:02:26 +0100 Subject: [PATCH 027/159] 1702 add owner field to nodes in chain params --- libethcore/ChainOperationParams.h | 8 ++++++-- libethereum/ChainParams.cpp | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index ec57fe4ed..9bbe6dcb4 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -78,6 +78,7 @@ struct NodeInfo { uint16_t port; std::string ip6; uint16_t port6; + std::string owner; std::string sgxServerUrl; std::string keyShareName; std::string ecdsaKeyName; @@ -89,7 +90,7 @@ struct NodeInfo { NodeInfo( std::string _name = "TestNode", u256 _id = 1, std::string _ip = "127.0.0.11", uint16_t _port = 11111, std::string _ip6 = "::1", uint16_t _port6 = 11111, - std::string _sgxServerUrl = "", std::string _ecdsaKeyName = "", + std::string _owner = "", std::string _sgxServerUrl = "", std::string _ecdsaKeyName = "", std::string _keyShareName = "", const std::array< std::string, 4 >& _BLSPublicKeys = { "1085704699902305713594457076223282948137075635957851808699051999328" @@ -110,6 +111,7 @@ struct NodeInfo { port = _port; ip6 = _ip6; port6 = _port6; + owner = _owner; sgxServerUrl = _sgxServerUrl; ecdsaKeyName = _ecdsaKeyName; keyShareName = _keyShareName; @@ -131,6 +133,7 @@ struct sChainNode { u256 port6; u256 sChainIndex; std::string publicKey; + std::string owner; std::array< std::string, 4 > blsPublicKey; }; @@ -140,6 +143,7 @@ struct GroupNode { u256 id; u256 schainIndex; std::string publicKey; + std::string owner; }; /// skale @@ -184,7 +188,7 @@ struct SChain { // HACK This creates one node and allows to run tests - BUT when loading config we need to // delete this explicitly!! sChainNode me = { u256( 1 ), "127.0.0.11", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), - "0xfa", { "0", "1", "0", "1" } }; + "0xfa", "", { "0", "1", "0", "1" } }; nodes.push_back( me ); } }; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index fb48f748d..bbb2a1247 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -113,6 +113,7 @@ ChainParams ChainParams::loadConfig( auto nodeName = infoObj.at( "nodeName" ).get_str(); auto nodeID = infoObj.at( "nodeID" ).get_uint64(); + std::string owner = infoObj.at( "owner" ).get_str(); bool syncNode = false; bool archiveMode = false; bool syncFromCatchup = false; @@ -187,7 +188,7 @@ ChainParams ChainParams::loadConfig( } cp.nodeInfo = { nodeName, nodeID, ip, static_cast< uint16_t >( port ), ip6, - static_cast< uint16_t >( port6 ), sgxServerUrl, ecdsaKeyName, keyShareName, + static_cast< uint16_t >( port6 ), owner, sgxServerUrl, ecdsaKeyName, keyShareName, BLSPublicKeys, commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup }; auto sChainObj = skaleObj.at( "sChain" ).get_obj(); @@ -287,7 +288,8 @@ ChainParams ChainParams::loadConfig( u256 sChainIndex = groupNodeConfObj[0].get_uint64(); u256 id = groupNodeConfObj[1].get_uint64(); std::string publicKey = groupNodeConfObj[2].get_str(); - groupNodes.push_back( { id, sChainIndex, publicKey } ); + std::string owner = groupNodeConfObj[3].get_str(); + groupNodes.push_back( { id, sChainIndex, publicKey, owner } ); } std::sort( groupNodes.begin(), groupNodes.end(), []( const GroupNode& lhs, const GroupNode& rhs ) { @@ -322,6 +324,7 @@ ChainParams ChainParams::loadConfig( node.id = nodeConfObj.at( "nodeID" ).get_uint64(); node.ip = nodeConfObj.at( "ip" ).get_str(); node.port = nodeConfObj.at( "basePort" ).get_uint64(); + node.owner = nodeConfObj.at( "owner" ).get_str(); try { node.ip6 = nodeConfObj.at( "ip6" ).get_str(); } catch ( ... ) { From 68978ab6cc0e5525ac85a05f6e95280b9e40c6bb Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:43:41 +0100 Subject: [PATCH 028/159] 1700 clang format --- libconsensus | 2 +- libethereum/ValidationSchemes.cpp | 85 ++++++++++++++++--------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/libconsensus b/libconsensus index ef26c4a02..5a9b85d8f 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit ef26c4a020884f280addd9b54037ee77fe396ecf +Subproject commit 5a9b85d8f171e1ba5f7dfe244cff70e0e39aa5f4 diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index ff6dca9c3..3a23277f4 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -269,50 +269,53 @@ void validateConfigJson( js::mObject const& _obj ) { { { js::int_type }, JsonFieldPresence::Optional } }, { "powCheckPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "pushZeroPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, - { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } } } ); { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, - { "skipInvalidTransactionsPatchTimestamp", - { { js::int_type }, JsonFieldPresence::Optional } } } ); + { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, + { + "skipInvalidTransactionsPatchTimestamp", { + { js::int_type }, JsonFieldPresence::Optional + } } +} ); - js::mArray const& nodes = sChain.at( "nodes" ).get_array(); - for ( auto const& obj : nodes ) { - const js::mObject node = obj.get_obj(); +js::mArray const& nodes = sChain.at( "nodes" ).get_array(); +for ( auto const& obj : nodes ) { + const js::mObject node = obj.get_obj(); - requireJsonFields( node, "ChainParams::loadConfig::skaleConfig::sChain::nodes", - { { "nodeName", { { js::str_type }, JsonFieldPresence::Optional } }, - { "nodeID", { { js::int_type }, JsonFieldPresence::Required } }, - { "ip", { { js::str_type }, JsonFieldPresence::Required } }, - { "publicIP", { { js::str_type }, JsonFieldPresence::Optional } }, // TODO not used - { "basePort", { { js::int_type }, JsonFieldPresence::Required } }, - { "ip6", { { js::str_type }, JsonFieldPresence::Optional } }, - { "basePort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "info-acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, - { "schainIndex", { { js::int_type }, JsonFieldPresence::Required } }, - { "publicKey", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey0", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey1", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey2", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey3", { { js::str_type }, JsonFieldPresence::Optional } }, - { "owner", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blockAuthor", { { js::str_type }, JsonFieldPresence::Optional } } } ); - } + requireJsonFields( node, "ChainParams::loadConfig::skaleConfig::sChain::nodes", + { { "nodeName", { { js::str_type }, JsonFieldPresence::Optional } }, + { "nodeID", { { js::int_type }, JsonFieldPresence::Required } }, + { "ip", { { js::str_type }, JsonFieldPresence::Required } }, + { "publicIP", { { js::str_type }, JsonFieldPresence::Optional } }, // TODO not used + { "basePort", { { js::int_type }, JsonFieldPresence::Required } }, + { "ip6", { { js::str_type }, JsonFieldPresence::Optional } }, + { "basePort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "info-acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, + { "schainIndex", { { js::int_type }, JsonFieldPresence::Required } }, + { "publicKey", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey0", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey1", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey2", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey3", { { js::str_type }, JsonFieldPresence::Optional } }, + { "owner", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blockAuthor", { { js::str_type }, JsonFieldPresence::Optional } } } ); +} } void validateAccountMaskObj( js::mObject const& _obj ) { From 1a4c7a91215ac77ee4ccd5ab4a956584f2f0d519 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:54:59 +0100 Subject: [PATCH 029/159] 1700 clang format --- libethereum/ValidationSchemes.cpp | 83 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index 3a23277f4..fdf83fdeb 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -271,51 +271,48 @@ void validateConfigJson( js::mObject const& _obj ) { { "pushZeroPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, - { - "skipInvalidTransactionsPatchTimestamp", { - { js::int_type }, JsonFieldPresence::Optional - } } -} ); + { "skipInvalidTransactionsPatchTimestamp", + { { js::int_type }, JsonFieldPresence::Optional } } } ); -js::mArray const& nodes = sChain.at( "nodes" ).get_array(); -for ( auto const& obj : nodes ) { - const js::mObject node = obj.get_obj(); + js::mArray const& nodes = sChain.at( "nodes" ).get_array(); + for ( auto const& obj : nodes ) { + const js::mObject node = obj.get_obj(); - requireJsonFields( node, "ChainParams::loadConfig::skaleConfig::sChain::nodes", - { { "nodeName", { { js::str_type }, JsonFieldPresence::Optional } }, - { "nodeID", { { js::int_type }, JsonFieldPresence::Required } }, - { "ip", { { js::str_type }, JsonFieldPresence::Required } }, - { "publicIP", { { js::str_type }, JsonFieldPresence::Optional } }, // TODO not used - { "basePort", { { js::int_type }, JsonFieldPresence::Required } }, - { "ip6", { { js::str_type }, JsonFieldPresence::Optional } }, - { "basePort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "httpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "wssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoHttpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, - { "infoWssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, - { "info-acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, - { "schainIndex", { { js::int_type }, JsonFieldPresence::Required } }, - { "publicKey", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey0", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey1", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey2", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blsPublicKey3", { { js::str_type }, JsonFieldPresence::Optional } }, - { "owner", { { js::str_type }, JsonFieldPresence::Optional } }, - { "blockAuthor", { { js::str_type }, JsonFieldPresence::Optional } } } ); -} + requireJsonFields( node, "ChainParams::loadConfig::skaleConfig::sChain::nodes", + { { "nodeName", { { js::str_type }, JsonFieldPresence::Optional } }, + { "nodeID", { { js::int_type }, JsonFieldPresence::Required } }, + { "ip", { { js::str_type }, JsonFieldPresence::Required } }, + { "publicIP", { { js::str_type }, JsonFieldPresence::Optional } }, // TODO not used + { "basePort", { { js::int_type }, JsonFieldPresence::Required } }, + { "ip6", { { js::str_type }, JsonFieldPresence::Optional } }, + { "basePort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "httpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "wssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoHttpsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWsRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWsRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWssRpcPort", { { js::int_type }, JsonFieldPresence::Optional } }, + { "infoWssRpcPort6", { { js::int_type }, JsonFieldPresence::Optional } }, + { "info-acceptors", { { js::int_type }, JsonFieldPresence::Optional } }, + { "schainIndex", { { js::int_type }, JsonFieldPresence::Required } }, + { "publicKey", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey0", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey1", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey2", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blsPublicKey3", { { js::str_type }, JsonFieldPresence::Optional } }, + { "owner", { { js::str_type }, JsonFieldPresence::Optional } }, + { "blockAuthor", { { js::str_type }, JsonFieldPresence::Optional } } } ); + } } void validateAccountMaskObj( js::mObject const& _obj ) { From a733b76de45622be7bb0807a855d838662d69fd2 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Oct 2023 15:51:32 +0100 Subject: [PATCH 030/159] 1702 use historicGroupIndex --- libethereum/ChainParams.cpp | 13 +++- libethereum/Client.cpp | 18 ++--- libethereum/Client.h | 24 +++++-- libethereum/Precompiled.cpp | 69 ++++++++++++++++--- libethereum/SkaleHost.cpp | 12 ++++ libethereum/SkaleHost.h | 9 +++ test/unittests/libethereum/ClientTest.cpp | 16 +++-- .../mapreduce_consensus/ConsensusEngine.cpp | 2 +- 8 files changed, 131 insertions(+), 32 deletions(-) diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index bbb2a1247..0d80616ee 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -113,13 +113,16 @@ ChainParams ChainParams::loadConfig( auto nodeName = infoObj.at( "nodeName" ).get_str(); auto nodeID = infoObj.at( "nodeID" ).get_uint64(); - std::string owner = infoObj.at( "owner" ).get_str(); bool syncNode = false; bool archiveMode = false; bool syncFromCatchup = false; - std::string ip, ip6, keyShareName, sgxServerUrl; + std::string ip, ip6, keyShareName, sgxServerUrl, owner; size_t t = 0; uint64_t port = 0, port6 = 0; + try { + owner = infoObj.at( "owner" ).get_str(); + } catch ( ... ) { + } try { ip = infoObj.at( "bindIP" ).get_str(); } catch ( ... ) { @@ -324,7 +327,11 @@ ChainParams ChainParams::loadConfig( node.id = nodeConfObj.at( "nodeID" ).get_uint64(); node.ip = nodeConfObj.at( "ip" ).get_str(); node.port = nodeConfObj.at( "basePort" ).get_uint64(); - node.owner = nodeConfObj.at( "owner" ).get_str(); + try { + node.owner = nodeConfObj.at( "owner" ).get_str(); + } catch ( ... ) { + node.owner = ""; + } try { node.ip6 = nodeConfObj.at( "ip6" ).get_str(); } catch ( ... ) { diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 06cec9516..35bc83642 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -312,7 +312,7 @@ void Client::init( WithExisting _forceAction, u256 _networkId ) { Defaults::setDBPath( m_dbPath ); if ( ChainParams().sChain.nodeGroups.size() > 0 ) - initIMABLSPublicKey(); + initHistoricGroupIndex(); // init snapshots for not newly created chains if ( number() ) { @@ -619,7 +619,7 @@ size_t Client::importTransactionsAsBlock( } if ( chainParams().sChain.nodeGroups.size() > 0 ) - updateIMABLSPublicKey(); + updateHistoricGroupIndex(); m_snapshotAgent->doSnapshotIfNeeded( number(), _timestamp ); @@ -1285,9 +1285,9 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, return ret; } -void Client::initIMABLSPublicKey() { +void Client::initHistoricGroupIndex() { if ( number() == 0 ) { - imaBLSPublicKeyGroupIndex = 0; + historicGroupIndex = 0; return; } @@ -1308,15 +1308,15 @@ void Client::initIMABLSPublicKey() { it = prevIt; } - imaBLSPublicKeyGroupIndex = std::distance( chainParams().sChain.nodeGroups.begin(), it ); + historicGroupIndex = std::distance( chainParams().sChain.nodeGroups.begin(), it ); } -void Client::updateIMABLSPublicKey() { +void Client::updateHistoricGroupIndex() { uint64_t blockTimestamp = blockInfo( hashFromNumber( number() ) ).timestamp(); - uint64_t currentFinishTs = chainParams().sChain.nodeGroups[imaBLSPublicKeyGroupIndex].finishTs; + uint64_t currentFinishTs = chainParams().sChain.nodeGroups[historicGroupIndex].finishTs; if ( blockTimestamp >= currentFinishTs ) - ++imaBLSPublicKeyGroupIndex; - assert( imaBLSPublicKeyGroupIndex < chainParams().sChain.nodeGroups.size() ); + ++historicGroupIndex; + assert( historicGroupIndex < chainParams().sChain.nodeGroups.size() ); } // new block watch diff --git a/libethereum/Client.h b/libethereum/Client.h index 2e3155612..90f491282 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -297,7 +297,22 @@ class Client : public ClientBase, protected Worker { } std::array< std::string, 4 > getIMABLSPublicKey() const { - return chainParams().sChain.nodeGroups[imaBLSPublicKeyGroupIndex].blsPublicKey; + return chainParams().sChain.nodeGroups[historicGroupIndex].blsPublicKey; + } + + // get node id for historic node in chain + std::string getHistoricNodeId( unsigned _id ) const { + return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_id].id.str(); + } + + // get schain index for historic node in chain + std::string getHistoricNodeIndex( unsigned _idx ) const { + return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].schainIndex.str(); + } + + // get node owner for historic node in chain + std::string getHistoricNodeOwner( unsigned _idx ) const { + return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].owner; } void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); } @@ -532,10 +547,11 @@ class Client : public ClientBase, protected Worker { fs::path m_dbPath; private: - void initIMABLSPublicKey(); - void updateIMABLSPublicKey(); + void initHistoricGroupIndex(); + void updateHistoricGroupIndex(); - unsigned imaBLSPublicKeyGroupIndex = 0; + // which group corresponds to the current block timestamp on this node + unsigned historicGroupIndex = 0; public: FILE* performance_fd; diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 6a0a1c63f..964a1a072 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -756,22 +756,57 @@ static dev::u256 stat_parse_u256_hex_or_dec( const std::string& strValue ) { return uValue; } +static bool isCallToHistoricData( const std::string& callData ) { + return skutils::tools::wildcmp( "skaleConfig.sChain.nodes.*", callData.c_str() ); +} + +static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { + unsigned id = std::stoul( callData.substr( callData.find( '[' ), callData.find( ']' ) + 1 ) ); + std::string fieldName; + if ( callData.find( "id" ) != std::string::npos ) { + fieldName = "id"; + } else if ( callData.find( "schainIndex" ) != std::string::npos ) { + fieldName = "schainIndex"; + } else if ( callData.find( "owner" ) != std::string::npos ) { + fieldName = "owner"; + } else { + fieldName = "unknown field"; + } + return { fieldName, id }; +} + ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { try { size_t lengthName; std::string rawName; convertBytesToString( _in, 0, rawName, lengthName ); + std::cout << "PATH: " << rawName << '\n'; if ( !stat_is_accessible_json_path( rawName ) ) throw std::runtime_error( "Security poicy violation, inaccessible configuration JSON path: " + rawName ); if ( !g_configAccesssor ) throw std::runtime_error( "Config accessor was not initialized" ); - nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); - nlohmann::json joValue = - skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); - std::string strValue = skutils::tools::trim_copy( - joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); + + std::string strValue; + if ( isCallToHistoricData( rawName ) ) { + std::string field; + unsigned id; + std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); + if ( field == "id" ) { + strValue = g_skaleHost->getHistoricNodeId( id ); + } else if ( field == "schainIndex" ) { + strValue = g_skaleHost->getHistoricNodeIndex( id ); + } else { + throw std::runtime_error( "Incorrect config field" ); + } + } else { + nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); + nlohmann::json joValue = + skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); + strValue = skutils::tools::trim_copy( + joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); + } // dev::u256 uValue( strValue.c_str() ); dev::u256 uValue = stat_parse_u256_hex_or_dec( strValue ); @@ -807,11 +842,25 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { if ( !g_configAccesssor ) throw std::runtime_error( "Config accessor was not initialized" ); - nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); - nlohmann::json joValue = - skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); - std::string strValue = skutils::tools::trim_copy( - joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); + + std::string strValue; + if ( isCallToHistoricData( rawName ) ) { + std::string field; + unsigned id; + std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); + if ( field == "owner" ) { + strValue = g_skaleHost->getHistoricNodeOwner( id ); + } else { + throw std::runtime_error( "Incorrect config field" ); + } + } else { + nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); + nlohmann::json joValue = + skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); + strValue = skutils::tools::trim_copy( + joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); + } + dev::u256 uValue( strValue.c_str() ); bytes response = toBigEndian( uValue ); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 8a3b54109..53a318180 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -950,6 +950,18 @@ std::array< std::string, 4 > SkaleHost::getIMABLSPublicKey() const { return m_client.getIMABLSPublicKey(); } +std::string SkaleHost::getHistoricNodeId( unsigned _id ) const { + return m_client.getHistoricNodeId( _id ); +} + +std::string SkaleHost::getHistoricNodeIndex( unsigned _index ) const { + return m_client.getHistoricNodeIndex( _index ); +} + +std::string SkaleHost::getHistoricNodeOwner( unsigned _idx ) const { + return m_client.getHistoricNodeOwner( _idx ); +} + uint64_t SkaleHost::submitOracleRequest( const string& _spec, string& _receipt, string& _errorMessage ) { return m_consensus->submitOracleRequest( _spec, _receipt, _errorMessage ); diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index bb79d5d60..b5ae631c9 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -126,6 +126,15 @@ class SkaleHost { std::map< std::string, uint64_t > getConsensusDbUsage() const; std::array< std::string, 4 > getIMABLSPublicKey() const; + // get node id for historic node in chain + std::string getHistoricNodeId( unsigned _id ) const; + + // get schain index for historic node in chain + std::string getHistoricNodeIndex( unsigned _idx ) const; + + // get node owner for historic node in chain + std::string getHistoricNodeOwner( unsigned _idx ) const; + uint64_t submitOracleRequest( const string& _spec, string& _receipt, string& _errorMessage ); uint64_t checkOracleResult( const string& _receipt, string& _result ); diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index c49302cad..40c7872f9 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -871,7 +871,8 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "30": [ 0, 30, - "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b" + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", + "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" ] }, "finish_ts": null, @@ -887,7 +888,8 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "26": [ 3, 26, - "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba" + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", + "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" ] }, "finish_ts": 4294967290, @@ -900,7 +902,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + } }, "nodes": [ - { "nodeID": 1112, "ip": "127.0.0.1", "basePort": )E"+std::to_string( rand_port ) + R"E(, "schainIndex" : 1, "publicKey": "0xfa"} + { "nodeID": 1112, "ip": "127.0.0.1", "basePort": )E"+std::to_string( rand_port ) + R"E(, "schainIndex" : 1, "publicKey": "0xfa", "owner": "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd"} ] } }, @@ -923,9 +925,10 @@ BOOST_AUTO_TEST_CASE( initAndUpdateIMABLSPUblicKey ) { std::array< std::string, 4 > imaBLSPublicKeyOnStartUp = { "12457351342169393659284905310882617316356538373005664536506840512800919345414", "11573096151310346982175966190385407867176668720531590318594794283907348596326", "13929944172721019694880576097738949215943314024940461401664534665129747139387", "7375214420811287025501422512322868338311819657776589198925786170409964211914" }; - BOOST_REQUIRE( testClient->getIMABLSPublicKey() == imaBLSPublicKeyOnStartUp ); - + BOOST_REQUIRE( testClient->getHistoricNodeOwner( 0 ) == "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" ); + BOOST_REQUIRE( testClient->getHistoricNodeId( 0 ) == "26" ); + BOOST_REQUIRE( testClient->getHistoricNodeIndex( 0 ) == "3" ); BOOST_REQUIRE( testClient->mineBlocks( 1 ) ); @@ -934,6 +937,9 @@ BOOST_AUTO_TEST_CASE( initAndUpdateIMABLSPUblicKey ) { std::array< std::string, 4 > imaBLSPublicKeyAfterBlock = { "10860211539819517237363395256510340030868592687836950245163587507107792195621", "2419969454136313127863904023626922181546178935031521540751337209075607503568", "3399776985251727272800732947224655319335094876742988846345707000254666193993", "16982202412630419037827505223148517434545454619191931299977913428346639096984" }; BOOST_REQUIRE( testClient->getIMABLSPublicKey() == imaBLSPublicKeyAfterBlock ); + BOOST_REQUIRE( testClient->getHistoricNodeOwner( 0 ) == "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" ); + BOOST_REQUIRE( testClient->getHistoricNodeId( 0 ) == "30" ); + BOOST_REQUIRE( testClient->getHistoricNodeIndex( 0 ) == "0" ); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp index 8b78e0bd1..320415246 100644 --- a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp +++ b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp @@ -214,7 +214,7 @@ class ConsensusExtFaceFixture : public ConsensusExtFace { chainParams.nodeInfo.port = chainParams.nodeInfo.port6 = rand_port; chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port; - sChainNode node2{u256( 2 ), "127.0.0.12", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), "0xfa", {"0", "1", "0", "1"}}; + sChainNode node2{u256( 2 ), "127.0.0.12", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), "0xfa", "", {"0", "1", "0", "1"}}; chainParams.sChain.nodes.push_back( node2 ); ////////////////////////////////////////////// From 80c2e4439a99cec6c67f50aaefde950591028669 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:58:00 +0100 Subject: [PATCH 031/159] 1700 fix test --- test/historicstate/hardhat/scripts/push0_test.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/test/historicstate/hardhat/scripts/push0_test.ts b/test/historicstate/hardhat/scripts/push0_test.ts index 18446a589..d76a0a934 100644 --- a/test/historicstate/hardhat/scripts/push0_test.ts +++ b/test/historicstate/hardhat/scripts/push0_test.ts @@ -1,6 +1,6 @@ const OWNER_ADDRESS: string = "0x907cd0881E50d359bb9Fd120B1A5A143b1C97De6"; const ZERO_ADDRESS: string = "0xO000000000000000000000000000000000000000"; -const INITIAL_MINT: bigint = 10000000000000000000000000000000000000000n; +const INITIAL_MINT: bigint = 10000000000000000000000000000000000000000; import {ethers} from "hardhat"; @@ -29,16 +29,9 @@ function CHECK(result: any): void { } async function getAndPrintTrace(hash: string): Promise { -// const trace = await ethers.provider.send('debug_traceTransaction', [hash, {"tracer":"prestateTracer", -// "tracerConfig": {"diffMode":true}}]); - -// const trace = await ethers.provider.send('debug_traceTransaction', [hash, {"tracer": "callTracer", -// "tracerConfig": {"withLog":true}}]); const trace = await ethers.provider.send('debug_traceTransaction', [hash, {}]); - - console.log(JSON.stringify(trace, null, 4)); return trace; } @@ -58,12 +51,6 @@ async function deployWriteAndDestroy(): Promise { console.log(`Gas limit ${testContract.deployTransaction.gasLimit}`); console.log(`Contract deployed to ${testContract.address} at block ${deployBn} tx hash ${hash}`); - - // await waitUntilNextBlock() - - //await getAndPrintTrace(hash) - - console.log(`Now testing`); const transferReceipt = await testContract.getZero() From 4d59da961ba27d52be7e11ed11e025ca5a2c60c6 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:09:06 +0100 Subject: [PATCH 032/159] #1700 Fast forward consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 5a9b85d8f..79d6b7fd6 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 5a9b85d8f171e1ba5f7dfe244cff70e0e39aa5f4 +Subproject commit 79d6b7fd676e5f52aed5ff626066e810d5219f13 From b7cd5a5e3d91faaa7c46b37a34cc8e24edc88d03 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Oct 2023 17:51:29 +0100 Subject: [PATCH 033/159] 1702 update precompiled to work with oracle --- libethereum/Precompiled.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 964a1a072..ef2416f2d 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -761,7 +761,8 @@ static bool isCallToHistoricData( const std::string& callData ) { } static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { - unsigned id = std::stoul( callData.substr( callData.find( '[' ), callData.find( ']' ) + 1 ) ); + size_t numberLength = callData.find( ']' ) - callData.find( '[' ) - 1; + unsigned id = std::stoul( callData.substr( callData.find( '[' ) + 1, numberLength ) ); std::string fieldName; if ( callData.find( "id" ) != std::string::npos ) { fieldName = "id"; @@ -780,7 +781,6 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { size_t lengthName; std::string rawName; convertBytesToString( _in, 0, rawName, lengthName ); - std::cout << "PATH: " << rawName << '\n'; if ( !stat_is_accessible_json_path( rawName ) ) throw std::runtime_error( "Security poicy violation, inaccessible configuration JSON path: " + rawName ); From 295b85030738626b37d925f0aeade62763122530 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 30 Oct 2023 17:51:34 +0000 Subject: [PATCH 034/159] 1702 improve tests --- libethereum/Precompiled.cpp | 7 +- .../unittests/libethereum/PrecompiledTest.cpp | 201 +++++++++++++++++- 2 files changed, 197 insertions(+), 11 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index ef2416f2d..a4211a67b 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -790,6 +790,9 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { std::string strValue; if ( isCallToHistoricData( rawName ) ) { + if ( !g_skaleHost ) + throw std::runtime_error( "SkaleHost accessor was not initialized" ); + std::string field; unsigned id; std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); @@ -813,7 +816,6 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { // std::cout << "------------ Loaded config var \"" // << rawName << "\" value is " << uValue // << "\n"; - bytes response = toBigEndian( uValue ); return { true, response }; } catch ( std::exception& ex ) { @@ -845,6 +847,9 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { std::string strValue; if ( isCallToHistoricData( rawName ) ) { + if ( !g_skaleHost ) + throw std::runtime_error( "SkaleHost accessor was not initialized" ); + std::string field; unsigned id; std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 861cbb595..1bdc069ea 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -37,6 +40,20 @@ using namespace dev::eth; using namespace dev::test; namespace ut = boost::unit_test; +std::string numberToHex( size_t inputNumber ) { + std::stringstream sstream; + sstream << std::hex << inputNumber; + std::string hexNumber = sstream.str(); + hexNumber.insert( hexNumber.begin(), 64 - hexNumber.length(), '0' ); + return hexNumber; +} + +std::string stringToHex( std::string inputString ) { + std::string hexString = toHex( inputString.begin(), inputString.end(), "" ); + hexString.insert( hexString.begin() + hexString.length(), 64 - hexString.length(), '0' ); + return hexString; +} + BOOST_FIXTURE_TEST_SUITE( PrecompiledTests, TestOutputHelperFixture ) BOOST_AUTO_TEST_CASE( modexpFermatTheorem, @@ -1557,18 +1574,182 @@ BOOST_AUTO_TEST_CASE( ecpairingCost ) { BOOST_CHECK_EQUAL( static_cast< int >( costIstanbul ), in.size() / 192 * 34000 + 45000 ); } -std::string numberToHex( size_t inputNumber ) { - std::stringstream sstream; - sstream << std::hex << inputNumber; - std::string hexNumber = sstream.str(); - hexNumber.insert( hexNumber.begin(), 64 - hexNumber.length(), '0' ); - return hexNumber; +static std::string const genesisInfoSkaleConfigTest = std::string() + + R"E( +{ + "sealEngine": "Ethash", + "params": { + "accountStartNonce": "0x00", + "homesteadForkBlock": "0x00", + "EIP150ForkBlock": "0x00", + "EIP158ForkBlock": "0x00", + "byzantiumForkBlock": "0x00", + "constantinopleForkBlock": "0x00", + "constantinopleFixForkBlock": "0x00", + "networkID" : "12313219", + "chainID": "0x01", + "maximumExtraDataSize": "0x20", + "tieBreakingGas": false, + "minGasLimit": "0x1388", + "maxGasLimit": "7fffffffffffffff", + "gasLimitBoundDivisor": "0x0400", + "minimumDifficulty": "0x020000", + "difficultyBoundDivisor": "0x0800", + "durationLimit": "0x0d", + "blockReward": "0x4563918244F40000" + }, + "genesis": { + "nonce": "0x0000000000000042", + "difficulty": "0x020000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", + "gasLimit": "0x47E7C4" + }, + "skaleConfig": { + "nodeInfo": { + "nodeName": "Node1", + "nodeID": 1112, + "bindIP": "127.0.0.1", + "basePort": 1234, + "logLevel": "trace", + "logLevelProposal": "trace", + "ecdsaKeyName": "NEK:fa112" + }, + "sChain": { + "schainName": "TestChain", + "schainID": 1, + "contractStorageLimit": 32000, + "emptyBlockIntervalMs": -1, + "nodeGroups": { + "1": { + "nodes": { + "30": [ + 0, + 30, + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", + "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" + ] + }, + "finish_ts": null, + "bls_public_key": { + "blsPublicKey0": "10860211539819517237363395256510340030868592687836950245163587507107792195621", + "blsPublicKey1": "2419969454136313127863904023626922181546178935031521540751337209075607503568", + "blsPublicKey2": "3399776985251727272800732947224655319335094876742988846345707000254666193993", + "blsPublicKey3": "16982202412630419037827505223148517434545454619191931299977913428346639096984" + } + }, + "0": { + "nodes": { + "26": [ + 3, + 26, + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", + "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" + ] + }, + "finish_ts": 4294967290, + "bls_public_key": { + "blsPublicKey0": "12457351342169393659284905310882617316356538373005664536506840512800919345414", + "blsPublicKey1": "11573096151310346982175966190385407867176668720531590318594794283907348596326", + "blsPublicKey2": "13929944172721019694880576097738949215943314024940461401664534665129747139387", + "blsPublicKey3": "7375214420811287025501422512322868338311819657776589198925786170409964211914" + } + } + }, + "nodes": [ + { "nodeID": 1112, "ip": "127.0.0.1", "basePort": 1234, "schainIndex" : 1, "publicKey": "0xfa", "owner": "0x21abd6db4e347b4e8c937c1c8370e4b5ed3f0dd3db69cbdb7a38e1e50b1b82fc"} + ] + } + }, + "accounts": { + "0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, + "0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, + "0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } }, + "0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }, + "0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp", "startingBlock" : "0x2dc6c0" } }, + "0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "startingBlock" : "0x2dc6c0", "linear": { "base": 500, "word": 0 } } }, + "0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "startingBlock" : "0x2dc6c0", "linear": { "base": 40000, "word": 0 } } }, + "0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product", "startingBlock" : "0x2dc6c0" } }, + "0xca4409573a5129a72edf85d6c51e26760fc9c903": { "balance": "100000000000000000000000" }, + "0xD2001300000000000000000000000000000000D2": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x6080604052348015600f57600080fd5b506004361060325760003560e01c8063815b8ab41460375780638273f754146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050606a565b005b60686081565b005b60005a90505b815a82031015607d576070565b5050565b60005a9050609660028281609157fe5b04606a565b5056fea165627a7a72305820f5fb5a65e97cbda96c32b3a2e1497cd6b7989179b5dc29e9875bcbea5a96c4520029"}, + "0xD2001300000000000000000000000000000000D4": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80632098776714610051578063b8bd717f1461007f578063d37165fa146100ad578063fdde8d66146100db575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610109565b005b6100ab6004803603602081101561009557600080fd5b8101908080359060200190929190505050610136565b005b6100d9600480360360208110156100c357600080fd5b8101908080359060200190929190505050610170565b005b610107600480360360208110156100f157600080fd5b8101908080359060200190929190505050610191565b005b60005a90505b815a8203101561011e5761010f565b600080fd5b815a8203101561013257610123565b5050565b60005a90505b815a8203101561014b5761013c565b600060011461015957600080fd5b5a90505b815a8203101561016c5761015d565b5050565b60005a9050600081830390505b805a8303101561018c5761017d565b505050565b60005a90505b815a820310156101a657610197565b60016101b157600080fd5b5a90505b815a820310156101c4576101b5565b505056fea264697066735822122089b72532621e7d1849e444ee6efaad4fb8771258e6f79755083dce434e5ac94c64736f6c63430006000033"}, + "0xd40B3c51D0ECED279b1697DbdF45d4D19b872164": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x6080604052348015600f57600080fd5b506004361060325760003560e01c80636057361d146037578063b05784b8146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b60686088565b6040518082815260200191505060405180910390f35b8060008190555050565b6000805490509056fea2646970667358221220e5ff9593bfa9540a34cad5ecbe137dcafcfe1f93e3c4832610438d6f0ece37db64736f6c63430006060033"}, + "0xD2001300000000000000000000000000000000D3": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063ee919d501461003b578063f0fdf83414610069575b600080fd5b6100676004803603602081101561005157600080fd5b81019080803590602001909291905050506100af565b005b6100956004803603602081101561007f57600080fd5b8101908080359060200190929190505050610108565b604051808215151515815260200191505060405180910390f35b600160008083815260200190815260200160002060006101000a81548160ff021916908315150217905550600080600083815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006020528060005260406000206000915054906101000a900460ff168156fea2646970667358221220cf479cb746c4b897c88be4ad8e2612a14e27478f91928c49619c98da374a3bf864736f6c63430006000033"}, + "0xD40b89C063a23eb85d739f6fA9B14341838eeB2b": { "balance": "0", "nonce": "0", "storage": {"0x101e368776582e57ab3d116ffe2517c0a585cd5b23174b01e275c2d8329c3d83": "0x0000000000000000000000000000000000000000000000000000000000000001"}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80634df7e3d014610051578063d82cf7901461006f578063ee919d501461009d578063f0fdf834146100cb575b600080fd5b610059610111565b6040518082815260200191505060405180910390f35b61009b6004803603602081101561008557600080fd5b8101908080359060200190929190505050610117565b005b6100c9600480360360208110156100b357600080fd5b810190808035906020019092919050505061017d565b005b6100f7600480360360208110156100e157600080fd5b81019080803590602001909291905050506101ab565b604051808215151515815260200191505060405180910390f35b60015481565b60008082815260200190815260200160002060009054906101000a900460ff16151560011515141561017a57600080600083815260200190815260200160002060006101000a81548160ff02191690831515021790555060018054016001819055505b50565b600160008083815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006020528060005260406000206000915054906101000a900460ff168156fea264697066735822122000af6f9a0d5c9b8b642648557291c9eb0f9732d60094cf75e14bb192abd97bcc64736f6c63430006000033"} + } } +)E"; -std::string stringToHex( std::string inputString ) { - std::string hexString = toHex( inputString.begin(), inputString.end(), "" ); - hexString.insert( hexString.begin() + hexString.length(), 64 - hexString.length(), '0' ); - return hexString; +BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { + ChainParams chainParams; + chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); + + dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "/home/oleh/work/skaled/build/test/libethereum/PrecompiledConfig.h" ) ); + + std::unique_ptr client; + dev::WithExisting withExisting = dev::WithExisting::Trust; + client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, + shared_ptr< GasPricer >(), nullptr, nullptr, getDataDir(), + withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); + + std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); + dev::eth::g_skaleHost = skaleHost; + client->injectSkaleHost( skaleHost ); + + PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); + + bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( res.first ); + BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 26 ); + + in = dev::asBytes( "0000000000000000000000000000000000000000000000000000000000000028skaleConfig.sChain.nodes.[0].schainIndex" ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( res.first ); + BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 3 ); + + in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); + + in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); +} + +BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { + ChainParams chainParams; + chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); + + PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); + + bytes in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + auto res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( res.first ); + BOOST_REQUIRE( res.second == fromHex("0x21abd6db4e347b4e8c937c1c8370e4b5ed3f0dd3db69cbdb7a38e1e50b1b82fc") ); + + in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); + + in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); + + in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); } struct FilestorageFixture : public TestOutputHelperFixture { From 786882f2ab3b778a1a3859ef426943851ec7883c Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 31 Oct 2023 12:12:36 +0000 Subject: [PATCH 035/159] 1702 improve tests --- .../libethereum/PrecompiledConfig.json | 105 ++++++++++++++++++ .../unittests/libethereum/PrecompiledTest.cpp | 35 ++++-- 2 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 test/unittests/libethereum/PrecompiledConfig.json diff --git a/test/unittests/libethereum/PrecompiledConfig.json b/test/unittests/libethereum/PrecompiledConfig.json new file mode 100644 index 000000000..afea6f9b0 --- /dev/null +++ b/test/unittests/libethereum/PrecompiledConfig.json @@ -0,0 +1,105 @@ +{ + "sealEngine": "Ethash", + "params": { + "accountStartNonce": "0x00", + "homesteadForkBlock": "0x00", + "EIP150ForkBlock": "0x00", + "EIP158ForkBlock": "0x00", + "byzantiumForkBlock": "0x00", + "constantinopleForkBlock": "0x00", + "constantinopleFixForkBlock": "0x00", + "networkID" : "12313219", + "chainID": "0x01", + "maximumExtraDataSize": "0x20", + "tieBreakingGas": false, + "minGasLimit": "0x1388", + "maxGasLimit": "7fffffffffffffff", + "gasLimitBoundDivisor": "0x0400", + "minimumDifficulty": "0x020000", + "difficultyBoundDivisor": "0x0800", + "durationLimit": "0x0d", + "blockReward": "0x4563918244F40000" + }, + "genesis": { + "nonce": "0x0000000000000042", + "difficulty": "0x020000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", + "gasLimit": "0x47E7C4" + }, + "skaleConfig": { + "nodeInfo": { + "nodeName": "Node1", + "nodeID": 1112, + "bindIP": "127.0.0.1", + "basePort": 1234, + "logLevel": "trace", + "logLevelProposal": "trace", + "ecdsaKeyName": "NEK:fa112" + }, + "sChain": { + "schainName": "TestChain", + "schainID": 1, + "contractStorageLimit": 32000, + "emptyBlockIntervalMs": -1, + "nodeGroups": { + "1": { + "nodes": { + "30": [ + 0, + 30, + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", + "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" + ] + }, + "finish_ts": null, + "bls_public_key": { + "blsPublicKey0": "10860211539819517237363395256510340030868592687836950245163587507107792195621", + "blsPublicKey1": "2419969454136313127863904023626922181546178935031521540751337209075607503568", + "blsPublicKey2": "3399776985251727272800732947224655319335094876742988846345707000254666193993", + "blsPublicKey3": "16982202412630419037827505223148517434545454619191931299977913428346639096984" + } + }, + "0": { + "nodes": { + "26": [ + 3, + 26, + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", + "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" + ] + }, + "finish_ts": 4294967290, + "bls_public_key": { + "blsPublicKey0": "12457351342169393659284905310882617316356538373005664536506840512800919345414", + "blsPublicKey1": "11573096151310346982175966190385407867176668720531590318594794283907348596326", + "blsPublicKey2": "13929944172721019694880576097738949215943314024940461401664534665129747139387", + "blsPublicKey3": "7375214420811287025501422512322868338311819657776589198925786170409964211914" + } + } + }, + "nodes": [ + { "nodeID": 1112, "ip": "127.0.0.1", "basePort": 1234, "schainIndex" : 1, "publicKey": "0xfa", "owner": "0x21abd6db4e347b4e8c937c1c8370e4b5ed3f0dd3db69cbdb7a38e1e50b1b82fc"} + ] + } + }, + "accounts": { + "0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, + "0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, + "0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } }, + "0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }, + "0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp", "startingBlock" : "0x2dc6c0" } }, + "0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "startingBlock" : "0x2dc6c0", "linear": { "base": 500, "word": 0 } } }, + "0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "startingBlock" : "0x2dc6c0", "linear": { "base": 40000, "word": 0 } } }, + "0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product", "startingBlock" : "0x2dc6c0" } }, + "0xca4409573a5129a72edf85d6c51e26760fc9c903": { "balance": "100000000000000000000000" }, + "0xD2001300000000000000000000000000000000D2": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x6080604052348015600f57600080fd5b506004361060325760003560e01c8063815b8ab41460375780638273f754146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050606a565b005b60686081565b005b60005a90505b815a82031015607d576070565b5050565b60005a9050609660028281609157fe5b04606a565b5056fea165627a7a72305820f5fb5a65e97cbda96c32b3a2e1497cd6b7989179b5dc29e9875bcbea5a96c4520029"}, + "0xD2001300000000000000000000000000000000D4": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80632098776714610051578063b8bd717f1461007f578063d37165fa146100ad578063fdde8d66146100db575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610109565b005b6100ab6004803603602081101561009557600080fd5b8101908080359060200190929190505050610136565b005b6100d9600480360360208110156100c357600080fd5b8101908080359060200190929190505050610170565b005b610107600480360360208110156100f157600080fd5b8101908080359060200190929190505050610191565b005b60005a90505b815a8203101561011e5761010f565b600080fd5b815a8203101561013257610123565b5050565b60005a90505b815a8203101561014b5761013c565b600060011461015957600080fd5b5a90505b815a8203101561016c5761015d565b5050565b60005a9050600081830390505b805a8303101561018c5761017d565b505050565b60005a90505b815a820310156101a657610197565b60016101b157600080fd5b5a90505b815a820310156101c4576101b5565b505056fea264697066735822122089b72532621e7d1849e444ee6efaad4fb8771258e6f79755083dce434e5ac94c64736f6c63430006000033"}, + "0xd40B3c51D0ECED279b1697DbdF45d4D19b872164": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x6080604052348015600f57600080fd5b506004361060325760003560e01c80636057361d146037578063b05784b8146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b60686088565b6040518082815260200191505060405180910390f35b8060008190555050565b6000805490509056fea2646970667358221220e5ff9593bfa9540a34cad5ecbe137dcafcfe1f93e3c4832610438d6f0ece37db64736f6c63430006060033"}, + "0xD2001300000000000000000000000000000000D3": { "balance": "0", "nonce": "0", "storage": {}, "code":"0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063ee919d501461003b578063f0fdf83414610069575b600080fd5b6100676004803603602081101561005157600080fd5b81019080803590602001909291905050506100af565b005b6100956004803603602081101561007f57600080fd5b8101908080359060200190929190505050610108565b604051808215151515815260200191505060405180910390f35b600160008083815260200190815260200160002060006101000a81548160ff021916908315150217905550600080600083815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006020528060005260406000206000915054906101000a900460ff168156fea2646970667358221220cf479cb746c4b897c88be4ad8e2612a14e27478f91928c49619c98da374a3bf864736f6c63430006000033"}, + "0xD40b89C063a23eb85d739f6fA9B14341838eeB2b": { "balance": "0", "nonce": "0", "storage": {"0x101e368776582e57ab3d116ffe2517c0a585cd5b23174b01e275c2d8329c3d83": "0x0000000000000000000000000000000000000000000000000000000000000001"}, "code":"0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80634df7e3d014610051578063d82cf7901461006f578063ee919d501461009d578063f0fdf834146100cb575b600080fd5b610059610111565b6040518082815260200191505060405180910390f35b61009b6004803603602081101561008557600080fd5b8101908080359060200190929190505050610117565b005b6100c9600480360360208110156100b357600080fd5b810190808035906020019092919050505061017d565b005b6100f7600480360360208110156100e157600080fd5b81019080803590602001909291905050506101ab565b604051808215151515815260200191505060405180910390f35b60015481565b60008082815260200190815260200160002060009054906101000a900460ff16151560011515141561017a57600080600083815260200190815260200160002060006101000a81548160ff02191690831515021790555060018054016001819055505b50565b600160008083815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006020528060005260406000206000915054906101000a900460ff168156fea264697066735822122000af6f9a0d5c9b8b642648557291c9eb0f9732d60094cf75e14bb192abd97bcc64736f6c63430006000033"} + } +} diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 1bdc069ea..070e7b2c8 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -49,8 +49,9 @@ std::string numberToHex( size_t inputNumber ) { } std::string stringToHex( std::string inputString ) { + size_t strLength = ( ( inputString.size() * 2 + 63 ) / 64 ) * 64; std::string hexString = toHex( inputString.begin(), inputString.end(), "" ); - hexString.insert( hexString.begin() + hexString.length(), 64 - hexString.length(), '0' ); + hexString.insert( hexString.begin() + hexString.length(), strLength - hexString.length(), '0' ); return hexString; } @@ -1687,7 +1688,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { ChainParams chainParams; chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); - dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "/home/oleh/work/skaled/build/test/libethereum/PrecompiledConfig.h" ) ); + dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); std::unique_ptr client; dev::WithExisting withExisting = dev::WithExisting::Trust; @@ -1707,18 +1708,18 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 26 ); - in = dev::asBytes( "0000000000000000000000000000000000000000000000000000000000000028skaleConfig.sChain.nodes.[0].schainIndex" ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 3 ); - in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); @@ -1728,25 +1729,37 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { ChainParams chainParams; chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); - PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); + dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); + + std::unique_ptr client; + dev::WithExisting withExisting = dev::WithExisting::Trust; + client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, + shared_ptr< GasPricer >(), nullptr, nullptr, getDataDir(), + withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); + + std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); + dev::eth::g_skaleHost = skaleHost; + client->injectSkaleHost( skaleHost ); + + PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - bytes in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + bytes in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); - BOOST_REQUIRE( res.second == fromHex("0x21abd6db4e347b4e8c937c1c8370e4b5ed3f0dd3db69cbdb7a38e1e50b1b82fc") ); + BOOST_REQUIRE( res.second == fromHex("0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd") ); - in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); + in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); From e9b63e9e47b2a541dd4395e096b5ce8fde3b38f2 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 31 Oct 2023 15:18:22 +0000 Subject: [PATCH 036/159] 1702 remove unnecessary changes --- libethcore/ChainOperationParams.h | 7 ++----- libethereum/ChainParams.cpp | 13 ++----------- libethereum/Precompiled.cpp | 4 ++++ test/unittests/libethereum/ClientTest.cpp | 2 +- .../mapreduce_consensus/ConsensusEngine.cpp | 2 +- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 9bbe6dcb4..db375216d 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -78,7 +78,6 @@ struct NodeInfo { uint16_t port; std::string ip6; uint16_t port6; - std::string owner; std::string sgxServerUrl; std::string keyShareName; std::string ecdsaKeyName; @@ -90,7 +89,7 @@ struct NodeInfo { NodeInfo( std::string _name = "TestNode", u256 _id = 1, std::string _ip = "127.0.0.11", uint16_t _port = 11111, std::string _ip6 = "::1", uint16_t _port6 = 11111, - std::string _owner = "", std::string _sgxServerUrl = "", std::string _ecdsaKeyName = "", + std::string _sgxServerUrl = "", std::string _ecdsaKeyName = "", std::string _keyShareName = "", const std::array< std::string, 4 >& _BLSPublicKeys = { "1085704699902305713594457076223282948137075635957851808699051999328" @@ -111,7 +110,6 @@ struct NodeInfo { port = _port; ip6 = _ip6; port6 = _port6; - owner = _owner; sgxServerUrl = _sgxServerUrl; ecdsaKeyName = _ecdsaKeyName; keyShareName = _keyShareName; @@ -133,7 +131,6 @@ struct sChainNode { u256 port6; u256 sChainIndex; std::string publicKey; - std::string owner; std::array< std::string, 4 > blsPublicKey; }; @@ -188,7 +185,7 @@ struct SChain { // HACK This creates one node and allows to run tests - BUT when loading config we need to // delete this explicitly!! sChainNode me = { u256( 1 ), "127.0.0.11", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), - "0xfa", "", { "0", "1", "0", "1" } }; + "0xfa", { "0", "1", "0", "1" } }; nodes.push_back( me ); } }; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 0d80616ee..2d154082a 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -116,13 +116,9 @@ ChainParams ChainParams::loadConfig( bool syncNode = false; bool archiveMode = false; bool syncFromCatchup = false; - std::string ip, ip6, keyShareName, sgxServerUrl, owner; + std::string ip, ip6, keyShareName, sgxServerUrl; size_t t = 0; uint64_t port = 0, port6 = 0; - try { - owner = infoObj.at( "owner" ).get_str(); - } catch ( ... ) { - } try { ip = infoObj.at( "bindIP" ).get_str(); } catch ( ... ) { @@ -191,7 +187,7 @@ ChainParams ChainParams::loadConfig( } cp.nodeInfo = { nodeName, nodeID, ip, static_cast< uint16_t >( port ), ip6, - static_cast< uint16_t >( port6 ), owner, sgxServerUrl, ecdsaKeyName, keyShareName, + static_cast< uint16_t >( port6 ), sgxServerUrl, ecdsaKeyName, keyShareName, BLSPublicKeys, commonBLSPublicKeys, syncNode, archiveMode, syncFromCatchup }; auto sChainObj = skaleObj.at( "sChain" ).get_obj(); @@ -327,11 +323,6 @@ ChainParams ChainParams::loadConfig( node.id = nodeConfObj.at( "nodeID" ).get_uint64(); node.ip = nodeConfObj.at( "ip" ).get_str(); node.port = nodeConfObj.at( "basePort" ).get_uint64(); - try { - node.owner = nodeConfObj.at( "owner" ).get_str(); - } catch ( ... ) { - node.owner = ""; - } try { node.ip6 = nodeConfObj.at( "ip6" ).get_str(); } catch ( ... ) { diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index a4211a67b..b0bd2a243 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -789,6 +789,8 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { throw std::runtime_error( "Config accessor was not initialized" ); std::string strValue; + // call to skaleConfig.sChain.nodes means call to the historic data + // need to proccess it in a different way if ( isCallToHistoricData( rawName ) ) { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); @@ -846,6 +848,8 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { throw std::runtime_error( "Config accessor was not initialized" ); std::string strValue; + // call to skaleConfig.sChain.nodes means call to the historic data + // need to proccess it in a different way if ( isCallToHistoricData( rawName ) ) { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 40c7872f9..69791b445 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -902,7 +902,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + } }, "nodes": [ - { "nodeID": 1112, "ip": "127.0.0.1", "basePort": )E"+std::to_string( rand_port ) + R"E(, "schainIndex" : 1, "publicKey": "0xfa", "owner": "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd"} + { "nodeID": 1112, "ip": "127.0.0.1", "basePort": )E"+std::to_string( rand_port ) + R"E(, "schainIndex" : 1, "publicKey": "0xfa"} ] } }, diff --git a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp index 320415246..8b78e0bd1 100644 --- a/test/unittests/mapreduce_consensus/ConsensusEngine.cpp +++ b/test/unittests/mapreduce_consensus/ConsensusEngine.cpp @@ -214,7 +214,7 @@ class ConsensusExtFaceFixture : public ConsensusExtFace { chainParams.nodeInfo.port = chainParams.nodeInfo.port6 = rand_port; chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port; - sChainNode node2{u256( 2 ), "127.0.0.12", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), "0xfa", "", {"0", "1", "0", "1"}}; + sChainNode node2{u256( 2 ), "127.0.0.12", u256( 11111 ), "::1", u256( 11111 ), u256( 1 ), "0xfa", {"0", "1", "0", "1"}}; chainParams.sChain.nodes.push_back( node2 ); ////////////////////////////////////////////// From a348f52d3445f694a345124e0657cab249b73d6a Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 1 Nov 2023 11:44:35 +0000 Subject: [PATCH 037/159] 1702 fix tests --- test/unittests/libethereum/PrecompiledTest.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 070e7b2c8..1e7f2da17 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -1692,8 +1693,10 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { std::unique_ptr client; dev::WithExisting withExisting = dev::WithExisting::Trust; + dev::TransientDirectory m_tmpDir; + setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, - shared_ptr< GasPricer >(), nullptr, nullptr, getDataDir(), + shared_ptr< GasPricer >(), nullptr, nullptr, m_tmpDir.path(), withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); @@ -1733,8 +1736,10 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { std::unique_ptr client; dev::WithExisting withExisting = dev::WithExisting::Trust; + dev::TransientDirectory m_tmpDir; + setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, - shared_ptr< GasPricer >(), nullptr, nullptr, getDataDir(), + shared_ptr< GasPricer >(), nullptr, nullptr, m_tmpDir.path(), withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); From c200761d41538c2b6ceaea7d00cc60141ab75062 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 2 Nov 2023 12:40:27 +0000 Subject: [PATCH 038/159] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3f67e25ce..7290025ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.17.0 +3.17.2 From 3815c22c3fa0ba60216c19c253a13b584cae1afe Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 3 Nov 2023 13:32:39 +0000 Subject: [PATCH 039/159] 1702 introduce PrecompiledConfigPatch --- libethcore/ChainOperationParams.h | 1 + libethereum/ChainParams.cpp | 5 +++++ libethereum/Client.cpp | 3 +++ libethereum/Precompiled.cpp | 5 +++-- libskale/CMakeLists.txt | 2 ++ libskale/PrecompiledConfigPatch.cpp | 11 ++++++++++ libskale/PrecompiledConfigPatch.h | 32 +++++++++++++++++++++++++++++ 7 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 libskale/PrecompiledConfigPatch.cpp create mode 100644 libskale/PrecompiledConfigPatch.h diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 492ffc0a7..279a3948d 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -176,6 +176,7 @@ struct SChain { time_t verifyDaSigsPatchTimestamp = 0; time_t storageDestructionPatchTimestamp = 0; time_t powCheckPatchTimestamp = 0; + time_t precompiledConfigPatchTimestamp = 0; time_t pushZeroPatchTimestamp = 0; time_t skipInvalidTransactionsPatchTimestamp = 0; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 0f9478c4e..86e0d4139 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -266,6 +266,11 @@ ChainParams ChainParams::loadConfig( sChainObj.at( "powCheckPatchTimestamp" ).get_int64() : 0; + s.precompiledConfigPatchTimestamp = + sChainObj.count( "precompiledConfigPatchTimestamp" ) ? + sChainObj.at( "precompiledConfigPatchTimestamp" ).get_int64() : + 0; + s.pushZeroPatchTimestamp = sChainObj.count( "pushZeroPatchTimestamp" ) ? sChainObj.at( "pushZeroPatchTimestamp" ).get_int64() : 0; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index bf77b920a..652d54552 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -167,6 +168,7 @@ Client::Client( ChainParams const& _params, int _networkID, PushZeroPatch::setTimestamp( chainParams().sChain.pushZeroPatchTimestamp ); SkipInvalidTransactionsPatch::setTimestamp( this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp ); + PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp ); } @@ -661,6 +663,7 @@ size_t Client::syncTransactions( POWCheckPatch::lastBlockTimestamp = blockChain().info().timestamp(); PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp(); SkipInvalidTransactionsPatch::lastBlockTimestamp = blockChain().info().timestamp(); + PrecompiledConfigPatch::lastBlockTimestamp = blockChain().info().timestamp(); DEV_WRITE_GUARDED( x_working ) { assert( !m_working.isSealed() ); diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index b0bd2a243..91804542f 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -791,7 +792,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { std::string strValue; // call to skaleConfig.sChain.nodes means call to the historic data // need to proccess it in a different way - if ( isCallToHistoricData( rawName ) ) { + if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); @@ -850,7 +851,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { std::string strValue; // call to skaleConfig.sChain.nodes means call to the historic data // need to proccess it in a different way - if ( isCallToHistoricData( rawName ) ) { + if ( isCallToHistoricData( rawName ) && PrecompiledConfigPatch::isEnabled() ) { if ( !g_skaleHost ) throw std::runtime_error( "SkaleHost accessor was not initialized" ); diff --git a/libskale/CMakeLists.txt b/libskale/CMakeLists.txt index ba774b211..aec50d6e0 100644 --- a/libskale/CMakeLists.txt +++ b/libskale/CMakeLists.txt @@ -20,6 +20,7 @@ set(sources OverlayFS.cpp StorageDestructionPatch.cpp POWCheckPatch.cpp + PrecompiledConfigPatch.cpp PushZeroPatch.cpp SkipInvalidTransactionsPatch.cpp ) @@ -40,6 +41,7 @@ set(headers AmsterdamFixPatch.h RevertableFSPatch.h POWCheckPatch.h + PrecompiledConfigPatch.h OverlayFS.h SkipInvalidTransactionsPatch.h ) diff --git a/libskale/PrecompiledConfigPatch.cpp b/libskale/PrecompiledConfigPatch.cpp new file mode 100644 index 000000000..f36557d61 --- /dev/null +++ b/libskale/PrecompiledConfigPatch.cpp @@ -0,0 +1,11 @@ +#include "PrecompiledConfigPatch.h" + +time_t PrecompiledConfigPatch::precompiledConfigPatchTimestamp; +time_t PrecompiledConfigPatch::lastBlockTimestamp; + +bool PrecompiledConfigPatch::isEnabled() { + if ( precompiledConfigPatchTimestamp == 0 ) { + return false; + } + return precompiledConfigPatchTimestamp <= lastBlockTimestamp; +} diff --git a/libskale/PrecompiledConfigPatch.h b/libskale/PrecompiledConfigPatch.h new file mode 100644 index 000000000..776dd47cc --- /dev/null +++ b/libskale/PrecompiledConfigPatch.h @@ -0,0 +1,32 @@ +#ifndef PRECOMPILEDCONFIGPATCH_H +#define PRECOMPILEDCONFIGPATCH_H + +#include +#include + +namespace dev { +namespace eth { +class Client; +} +} // namespace dev + +/* + * Context: enable precompiled contracts to read historical config data + */ +class PrecompiledConfigPatch : public SchainPatch { +public: + static bool isEnabled(); + + static void setTimestamp( time_t _timeStamp ) { + printInfo( __FILE__, _timeStamp ); + precompiledConfigPatchTimestamp = _timeStamp; + } + +private: + friend class dev::eth::Client; + static time_t precompiledConfigPatchTimestamp; + static time_t lastBlockTimestamp; +}; + + +#endif // PRECOMPILEDCONFIGPATCH_H From f013fac176f4e5d711fdd9d7e786990aca499cd5 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 3 Nov 2023 17:14:44 +0000 Subject: [PATCH 040/159] #1526 Make net_version returns decimal number --- libweb3jsonrpc/Net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Net.cpp b/libweb3jsonrpc/Net.cpp index 8145dba5d..26ff582e6 100644 --- a/libweb3jsonrpc/Net.cpp +++ b/libweb3jsonrpc/Net.cpp @@ -35,7 +35,7 @@ Net::Net( const dev::eth::ChainParams& _chainParams ) : m_chainParams( _chainPar // TODO Ask here real values from consensus/broadcast std::string Net::net_version() { - return toJS( m_chainParams.chainID ); + return toString( m_chainParams.chainID ); } std::string Net::net_peerCount() { From ee9c48a88945d1c53678b7b7001476d92bb3bdeb Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:04:15 +0000 Subject: [PATCH 041/159] #1702 renamed owner to nodeAddress --- libethcore/ChainOperationParams.h | 2 +- libethereum/ChainParams.cpp | 4 ++-- libethereum/Client.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 279a3948d..5ac129ec6 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -140,7 +140,7 @@ struct GroupNode { u256 id; u256 schainIndex; std::string publicKey; - std::string owner; + std::string address; }; /// skale diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 86e0d4139..837530bee 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -296,8 +296,8 @@ ChainParams ChainParams::loadConfig( u256 sChainIndex = groupNodeConfObj[0].get_uint64(); u256 id = groupNodeConfObj[1].get_uint64(); std::string publicKey = groupNodeConfObj[2].get_str(); - std::string owner = groupNodeConfObj[3].get_str(); - groupNodes.push_back( { id, sChainIndex, publicKey, owner } ); + std::string address = groupNodeConfObj[3].get_str(); + groupNodes.push_back( { id, sChainIndex, publicKey, address } ); } std::sort( groupNodes.begin(), groupNodes.end(), []( const GroupNode& lhs, const GroupNode& rhs ) { diff --git a/libethereum/Client.h b/libethereum/Client.h index 90f491282..6579818b2 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -312,7 +312,7 @@ class Client : public ClientBase, protected Worker { // get node owner for historic node in chain std::string getHistoricNodeOwner( unsigned _idx ) const { - return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].owner; + return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].address; } void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); } From aa4c0d86febc8d871b9ba03913c975999f0a6367 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:07:55 +0000 Subject: [PATCH 042/159] #1702 changed [] to at() for safe vector access --- libethereum/ChainParams.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 837530bee..930bbf1a5 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -293,10 +293,10 @@ ChainParams ChainParams::loadConfig( auto groupNodesObj = nodeGroupObj["nodes"].get_obj(); for ( const auto& groupNodeConf : groupNodesObj ) { auto groupNodeConfObj = groupNodeConf.second.get_array(); - u256 sChainIndex = groupNodeConfObj[0].get_uint64(); - u256 id = groupNodeConfObj[1].get_uint64(); - std::string publicKey = groupNodeConfObj[2].get_str(); - std::string address = groupNodeConfObj[3].get_str(); + u256 sChainIndex = groupNodeConfObj.at(0).get_uint64(); + u256 id = groupNodeConfObj.at(1).get_uint64(); + std::string publicKey = groupNodeConfObj.at(2).get_str(); + std::string address = groupNodeConfObj.at(3).get_str(); groupNodes.push_back( { id, sChainIndex, publicKey, address } ); } std::sort( groupNodes.begin(), groupNodes.end(), From 95215c78d3554a79b2732f2d6cc5f4c16a015119 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:15:07 +0000 Subject: [PATCH 043/159] #1702 added param validation --- libethereum/ChainParams.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 930bbf1a5..8015741d1 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -297,6 +297,12 @@ ChainParams ChainParams::loadConfig( u256 id = groupNodeConfObj.at(1).get_uint64(); std::string publicKey = groupNodeConfObj.at(2).get_str(); std::string address = groupNodeConfObj.at(3).get_str(); + if (publicKey.empty()) { + BOOST_THROW_EXCEPTION(std::runtime_error("Empty public key in config")); + } + if (address.empty()) { + BOOST_THROW_EXCEPTION(std::runtime_error("Empty address in config")); + } groupNodes.push_back( { id, sChainIndex, publicKey, address } ); } std::sort( groupNodes.begin(), groupNodes.end(), From 4d55443750feb25c6d425eb71643bdc370f2e675 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:22:40 +0000 Subject: [PATCH 044/159] #1702 added a log record if node info is empty in config --- libethereum/Client.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 652d54552..0dd5831e7 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -315,8 +315,12 @@ void Client::init( WithExisting _forceAction, u256 _networkId ) { if ( m_dbPath.size() ) Defaults::setDBPath( m_dbPath ); - if ( ChainParams().sChain.nodeGroups.size() > 0 ) + if ( ChainParams().sChain.nodeGroups.size() > 0 ) { initHistoricGroupIndex(); + } else { + LOG( m_logger ) << "Empty node groups in config. " + "This is OK in tests but not OK in production"; + } // init snapshots for not newly created chains if ( number() ) { From 7f136c5c049966b1373936d281e9d4341d865318 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:27:41 +0000 Subject: [PATCH 045/159] #1702 changed assertion to runtime error --- libethereum/Client.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 0dd5831e7..c2298f5f2 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -319,7 +319,7 @@ void Client::init( WithExisting _forceAction, u256 _networkId ) { initHistoricGroupIndex(); } else { LOG( m_logger ) << "Empty node groups in config. " - "This is OK in tests but not OK in production"; + "This is OK in tests but not OK in production"; } // init snapshots for not newly created chains @@ -1095,7 +1095,9 @@ Block Client::blockByNumber( BlockNumber _h ) const { auto readState = m_state.createStateReadOnlyCopy(); readState.mutableHistoricState().setRootByBlockNumber( _h ); - DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), hash, readState ); } + DEV_GUARDED( m_blockImportMutex ) { + return Block( bc(), hash, readState ); + } assert( false ); return Block( bc() ); } catch ( Exception& ex ) { @@ -1109,7 +1111,9 @@ Block Client::blockByNumber( BlockNumber _h ) const { Block Client::latestBlock() const { // TODO Why it returns not-filled block??! (see Block ctor) try { - DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), bc().currentHash(), m_state ); } + DEV_GUARDED( m_blockImportMutex ) { + return Block( bc(), bc().currentHash(), m_state ); + } assert( false ); return Block( bc() ); } catch ( Exception& ex ) { @@ -1257,7 +1261,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) { historicBlock.mutableState().mutableHistoricState().addBalance( - _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); + _from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) ); } ret = historicBlock.executeHistoricCall( bc().lastBlockHashes(), t ); @@ -1281,7 +1285,8 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, t.forceChainId( chainParams().chainID ); t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) - temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); + temp.mutableState().addBalance( + _from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); } catch ( InvalidNonce const& in ) { LOG( m_logger ) << "exception in client call(1):" @@ -1309,7 +1314,11 @@ void Client::initHistoricGroupIndex() { chainParams().sChain.nodeGroups.end(), [¤tBlockTimestamp]( const dev::eth::NodeGroup& ng ) { return currentBlockTimestamp <= ng.finishTs; } ); - assert( it != chainParams().sChain.nodeGroups.end() ); + + if ( it == chainParams().sChain.nodeGroups.end() ) { + BOOST_THROW_EXCEPTION( + std::runtime_error( "Assertion failed: it == chainParams().sChain.nodeGroups.end()" ) ); + } if ( it != chainParams().sChain.nodeGroups.begin() ) { auto prevIt = std::prev( it ); From ea28913eeee2500bb9e376ac2a4a15cc42391023 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:30:19 +0000 Subject: [PATCH 046/159] #1702 changed assertion to runtime error --- libethereum/Client.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index c2298f5f2..b67f6b9b8 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1335,7 +1335,10 @@ void Client::updateHistoricGroupIndex() { uint64_t currentFinishTs = chainParams().sChain.nodeGroups[historicGroupIndex].finishTs; if ( blockTimestamp >= currentFinishTs ) ++historicGroupIndex; - assert( historicGroupIndex < chainParams().sChain.nodeGroups.size() ); + if ( historicGroupIndex >= chainParams().sChain.nodeGroups.size() ) { + BOOST_THROW_EXCEPTION( std::runtime_error( + "Assertion failed: historicGroupIndex >= chainParams().sChain.nodeGroups.size())" ) ); + } } // new block watch From 3652a82cba16eaf01c901b09ade04859b58df455 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:41:53 +0000 Subject: [PATCH 047/159] #1702 changed to standard boost library --- libethereum/Precompiled.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 91804542f..dd0337608 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -758,7 +759,8 @@ static dev::u256 stat_parse_u256_hex_or_dec( const std::string& strValue ) { } static bool isCallToHistoricData( const std::string& callData ) { - return skutils::tools::wildcmp( "skaleConfig.sChain.nodes.*", callData.c_str() ); + // in C++ 20 there is string::starts_with, but we do not use C++ 20 yet + boost::algorithm::starts_with(callData, "skaleConfig.sChain.nodes."); } static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { From 68798a76a529d9c92d33a7919b8d8f2d30d65033 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 6 Nov 2023 13:42:37 +0000 Subject: [PATCH 048/159] Add unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 5ef568135..9e85c5d1a 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -40,7 +40,7 @@ #include #include #include -// SKALE #include +#include #include #include #include @@ -329,7 +329,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { else client->setAuthor( chainParams.sChain.blockAuthor ); - using FullServer = ModularServer< rpc::EthFace, /* rpc::NetFace,*/ rpc::Web3Face, + using FullServer = ModularServer< rpc::EthFace, rpc::NetFace, rpc::Web3Face, rpc::AdminEthFace /*, rpc::AdminNetFace*/, rpc::DebugFace, rpc::TestFace >; accountHolder.reset( new FixedAccountHolder( [&]() { return client.get(); }, {} ) ); @@ -343,7 +343,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { gasPricer = make_shared< eth::TrivialGasPricer >( 0, DefaultGasPrice ); - rpcServer.reset( new FullServer( ethFace /*, new rpc::Net(*web3)*/, + 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 ), @@ -502,6 +502,23 @@ BOOST_AUTO_TEST_CASE( jsonrpc_number ) { // BOOST_CHECK_EQUAL(web3->isNetworkStarted(), false); //} +BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) +{ + std::string _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + + // Set chainID = 65535 + ret["params"]["chainID"] = "0xffff"; + + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + JsonRpcFixture fixture( config ); + + auto version = jsToU256(fixture.rpcClient->net_version()); + BOOST_CHECK_EQUAL( version, 65535 ); +} + BOOST_AUTO_TEST_CASE( jsonrpc_setMining ) { JsonRpcFixture fixture; fixture.rpcClient->admin_eth_setMining( true, fixture.adminSession ); From 238665d54b4fda65327ebe8a591242e2ea8a0449 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 6 Nov 2023 15:38:42 +0000 Subject: [PATCH 049/159] #1526 Update test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 9e85c5d1a..22abf959a 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -515,8 +515,8 @@ BOOST_AUTO_TEST_CASE( jsonrpc_netVersion ) std::string config = fastWriter.write( ret ); JsonRpcFixture fixture( config ); - auto version = jsToU256(fixture.rpcClient->net_version()); - BOOST_CHECK_EQUAL( version, 65535 ); + auto version = fixture.rpcClient->net_version(); + BOOST_CHECK_EQUAL( version, "65535" ); } BOOST_AUTO_TEST_CASE( jsonrpc_setMining ) { From 41ddce97888ed4f4cfc5ab93b3b68df3d22e20ef Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 6 Nov 2023 15:51:42 +0000 Subject: [PATCH 050/159] 1702 fix build --- libethereum/ChainParams.cpp | 16 ++++++++-------- libethereum/Client.cpp | 13 ++++--------- libethereum/Precompiled.cpp | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 8015741d1..72d8a2eb3 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -293,15 +293,15 @@ ChainParams ChainParams::loadConfig( auto groupNodesObj = nodeGroupObj["nodes"].get_obj(); for ( const auto& groupNodeConf : groupNodesObj ) { auto groupNodeConfObj = groupNodeConf.second.get_array(); - u256 sChainIndex = groupNodeConfObj.at(0).get_uint64(); - u256 id = groupNodeConfObj.at(1).get_uint64(); - std::string publicKey = groupNodeConfObj.at(2).get_str(); - std::string address = groupNodeConfObj.at(3).get_str(); - if (publicKey.empty()) { - BOOST_THROW_EXCEPTION(std::runtime_error("Empty public key in config")); + u256 sChainIndex = groupNodeConfObj.at( 0 ).get_uint64(); + u256 id = groupNodeConfObj.at( 1 ).get_uint64(); + std::string publicKey = groupNodeConfObj.at( 2 ).get_str(); + std::string address = groupNodeConfObj.at( 3 ).get_str(); + if ( publicKey.empty() ) { + BOOST_THROW_EXCEPTION( std::runtime_error( "Empty public key in config" ) ); } - if (address.empty()) { - BOOST_THROW_EXCEPTION(std::runtime_error("Empty address in config")); + if ( address.empty() ) { + BOOST_THROW_EXCEPTION( std::runtime_error( "Empty address in config" ) ); } groupNodes.push_back( { id, sChainIndex, publicKey, address } ); } diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index b67f6b9b8..2ba3f5290 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1095,9 +1095,7 @@ Block Client::blockByNumber( BlockNumber _h ) const { auto readState = m_state.createStateReadOnlyCopy(); readState.mutableHistoricState().setRootByBlockNumber( _h ); - DEV_GUARDED( m_blockImportMutex ) { - return Block( bc(), hash, readState ); - } + DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), hash, readState ); } assert( false ); return Block( bc() ); } catch ( Exception& ex ) { @@ -1111,9 +1109,7 @@ Block Client::blockByNumber( BlockNumber _h ) const { Block Client::latestBlock() const { // TODO Why it returns not-filled block??! (see Block ctor) try { - DEV_GUARDED( m_blockImportMutex ) { - return Block( bc(), bc().currentHash(), m_state ); - } + DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), bc().currentHash(), m_state ); } assert( false ); return Block( bc() ); } catch ( Exception& ex ) { @@ -1261,7 +1257,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) { historicBlock.mutableState().mutableHistoricState().addBalance( - _from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) ); + _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); } ret = historicBlock.executeHistoricCall( bc().lastBlockHashes(), t ); @@ -1285,8 +1281,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, t.forceChainId( chainParams().chainID ); t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) - temp.mutableState().addBalance( - _from, ( u256 ) ( t.gas() * t.gasPrice() + t.value() ) ); + temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); } catch ( InvalidNonce const& in ) { LOG( m_logger ) << "exception in client call(1):" diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index dd0337608..0c4f24570 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -760,7 +760,7 @@ static dev::u256 stat_parse_u256_hex_or_dec( const std::string& strValue ) { static bool isCallToHistoricData( const std::string& callData ) { // in C++ 20 there is string::starts_with, but we do not use C++ 20 yet - boost::algorithm::starts_with(callData, "skaleConfig.sChain.nodes."); + return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." ); } static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { From 399e9b1457ff4d71f511f783989bfba9204ebcd4 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 6 Nov 2023 15:55:04 +0000 Subject: [PATCH 051/159] 1702 deny access to some config fields from precompileds for security reasons --- libethereum/Precompiled.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 0c4f24570..257f60343 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -679,19 +679,21 @@ static const std::list< std::string > g_listReadableConfigParts{ "sealEngine", //"genesis.*" //"params.*", - "skaleConfig.nodeInfo.wallets.ima.commonBLSPublicKey*", - "skaleConfig.nodeInfo.wallets.ima.BLSPublicKey*", + // skaled-1702 + // remove these config field from public access for security reasons + // "skaleConfig.nodeInfo.wallets.ima.commonBLSPublicKey*", + // "skaleConfig.nodeInfo.wallets.ima.BLSPublicKey*", - "skaleConfig.nodeInfo.nodeName", "skaleConfig.nodeInfo.nodeID", - "skaleConfig.nodeInfo.basePort*", "skaleConfig.nodeInfo.*RpcPort*", - "skaleConfig.nodeInfo.acceptors", "skaleConfig.nodeInfo.max-connections", - "skaleConfig.nodeInfo.max-http-queues", "skaleConfig.nodeInfo.ws-mode", + // "skaleConfig.nodeInfo.nodeName", "skaleConfig.nodeInfo.nodeID", + // "skaleConfig.nodeInfo.basePort*", "skaleConfig.nodeInfo.*RpcPort*", + // "skaleConfig.nodeInfo.acceptors", "skaleConfig.nodeInfo.max-connections", + // "skaleConfig.nodeInfo.max-http-queues", "skaleConfig.nodeInfo.ws-mode", - "skaleConfig.contractSettings.*", + // "skaleConfig.contractSettings.*", - "skaleConfig.sChain.emptyBlockIntervalMs", + // "skaleConfig.sChain.emptyBlockIntervalMs", - "skaleConfig.sChain.schainName", "skaleConfig.sChain.schainID", + // "skaleConfig.sChain.schainName", "skaleConfig.sChain.schainID", "skaleConfig.sChain.nodes.*" }; From cfbd4359aeeff778238fac381e2be37ff21f32c0 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 7 Nov 2023 11:32:53 +0000 Subject: [PATCH 052/159] 1702 fix tests --- libethereum/Client.cpp | 2 +- libethereum/ValidationSchemes.cpp | 2 + test/unittests/libethereum/ClientTest.cpp | 3 +- .../libethereum/PrecompiledConfig.json | 1 + .../unittests/libethereum/PrecompiledTest.cpp | 55 +++++++++++++------ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 2ba3f5290..0822ba107 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -315,7 +315,7 @@ void Client::init( WithExisting _forceAction, u256 _networkId ) { if ( m_dbPath.size() ) Defaults::setDBPath( m_dbPath ); - if ( ChainParams().sChain.nodeGroups.size() > 0 ) { + if ( chainParams().sChain.nodeGroups.size() > 0 ) { initHistoricGroupIndex(); } else { LOG( m_logger ) << "Empty node groups in config. " diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index fdf83fdeb..75bd07af1 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -272,6 +272,8 @@ void validateConfigJson( js::mObject const& _obj ) { { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, { "nodeGroups", { { js::obj_type }, JsonFieldPresence::Optional } }, { "skipInvalidTransactionsPatchTimestamp", + { { js::int_type }, JsonFieldPresence::Optional } }, + { "precompiledConfigPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } } } ); js::mArray const& nodes = sChain.at( "nodes" ).get_array(); diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 69791b445..791ae56c4 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -865,6 +865,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "schainName": "TestChain", "schainID": 1, "emptyBlockIntervalMs": -1, + "precompiledConfigPatchTimestamp": 1, "nodeGroups": { "1": { "nodes": { @@ -919,7 +920,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + } )E"; -BOOST_AUTO_TEST_CASE( initAndUpdateIMABLSPUblicKey ) { +BOOST_AUTO_TEST_CASE( initAndUpdateHistoricConfigFields ) { TestClientFixture fixture( c_genesisInfoSkaleIMABLSPublicKeyTest ); ClientTest* testClient = asClientTest( fixture.ethereum() ); diff --git a/test/unittests/libethereum/PrecompiledConfig.json b/test/unittests/libethereum/PrecompiledConfig.json index afea6f9b0..d5889d2b5 100644 --- a/test/unittests/libethereum/PrecompiledConfig.json +++ b/test/unittests/libethereum/PrecompiledConfig.json @@ -44,6 +44,7 @@ "schainName": "TestChain", "schainID": 1, "contractStorageLimit": 32000, + "precompiledConfigPatchTimestamp": 1, "emptyBlockIntervalMs": -1, "nodeGroups": { "1": { diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 1e7f2da17..8de629387 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -26,12 +26,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include @@ -1624,12 +1626,13 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + "schainName": "TestChain", "schainID": 1, "contractStorageLimit": 32000, + "precompiledConfigPatchTimestamp": 1, "emptyBlockIntervalMs": -1, "nodeGroups": { "1": { "nodes": { "30": [ - 0, + 13, 30, "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" @@ -1688,20 +1691,28 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { ChainParams chainParams; chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); + chainParams.sealEngineName = NoProof::name(); + chainParams.allowFutureBlocks = true; dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); std::unique_ptr client; - dev::WithExisting withExisting = dev::WithExisting::Trust; dev::TransientDirectory m_tmpDir; + auto monitor = make_shared< InstanceMonitor >("test"); setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); - client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, - shared_ptr< GasPricer >(), nullptr, nullptr, m_tmpDir.path(), - withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); + client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, + shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); - std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); - dev::eth::g_skaleHost = skaleHost; - client->injectSkaleHost( skaleHost ); + client->injectSkaleHost(); + client->startWorking(); + + client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); + + ClientTest* testClient = asClientTest( client.get() ); + + testClient->mineBlocks( 1 ); + testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); + dev::eth::g_skaleHost = testClient->skaleHost(); PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); @@ -1709,13 +1720,13 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); - BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 26 ); + BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 30 ); in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); - BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 3 ); + BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); @@ -1731,20 +1742,28 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { ChainParams chainParams; chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); + chainParams.sealEngineName = NoProof::name(); + chainParams.allowFutureBlocks = true; dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); std::unique_ptr client; - dev::WithExisting withExisting = dev::WithExisting::Trust; dev::TransientDirectory m_tmpDir; + auto monitor = make_shared< InstanceMonitor >("test"); setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); - client.reset( new eth::Client( chainParams, ( int ) chainParams.networkID, - shared_ptr< GasPricer >(), nullptr, nullptr, m_tmpDir.path(), - withExisting, dev::eth::TransactionQueue::Limits{ 1, 1, 1, 1 } ) ); + client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, + shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); + + client->injectSkaleHost(); + client->startWorking(); + + client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); + + ClientTest* testClient = asClientTest( client.get() ); - std::shared_ptr< SkaleHost > skaleHost = std::make_shared< SkaleHost >( *client, nullptr, nullptr, "", false ); - dev::eth::g_skaleHost = skaleHost; - client->injectSkaleHost( skaleHost ); + testClient->mineBlocks( 1 ); + testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); + dev::eth::g_skaleHost = testClient->skaleHost(); PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); @@ -1752,7 +1771,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); - BOOST_REQUIRE( res.second == fromHex("0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd") ); + BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); From 80618dd3dbb07f6b73eb202635824eafe42a2805 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 7 Nov 2023 18:53:56 +0000 Subject: [PATCH 053/159] #1702 improve code quality --- libethereum/Precompiled.cpp | 89 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 257f60343..8dc4ed7d1 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -675,27 +676,7 @@ ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -static const std::list< std::string > g_listReadableConfigParts{ "sealEngine", - //"genesis.*" - //"params.*", - - // skaled-1702 - // remove these config field from public access for security reasons - // "skaleConfig.nodeInfo.wallets.ima.commonBLSPublicKey*", - // "skaleConfig.nodeInfo.wallets.ima.BLSPublicKey*", - - // "skaleConfig.nodeInfo.nodeName", "skaleConfig.nodeInfo.nodeID", - // "skaleConfig.nodeInfo.basePort*", "skaleConfig.nodeInfo.*RpcPort*", - // "skaleConfig.nodeInfo.acceptors", "skaleConfig.nodeInfo.max-connections", - // "skaleConfig.nodeInfo.max-http-queues", "skaleConfig.nodeInfo.ws-mode", - - // "skaleConfig.contractSettings.*", - - // "skaleConfig.sChain.emptyBlockIntervalMs", - - // "skaleConfig.sChain.schainName", "skaleConfig.sChain.schainID", - - "skaleConfig.sChain.nodes.*" }; +static const std::list< std::string > g_listReadableConfigParts{ "skaleConfig.sChain.nodes." }; static bool stat_is_accessible_json_path( const std::string& strPath ) { if ( strPath.empty() ) @@ -704,7 +685,7 @@ static bool stat_is_accessible_json_path( const std::string& strPath ) { itEnd = g_listReadableConfigParts.cend(); for ( ; itWalk != itEnd; ++itWalk ) { const std::string strWildCard = ( *itWalk ); - if ( skutils::tools::wildcmp( strWildCard.c_str(), strPath.c_str() ) ) + if ( boost::algorithm::starts_with( strPath, strWildCard ) ) return true; } return false; @@ -766,14 +747,31 @@ static bool isCallToHistoricData( const std::string& callData ) { } static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { - size_t numberLength = callData.find( ']' ) - callData.find( '[' ) - 1; - unsigned id = std::stoul( callData.substr( callData.find( '[' ) + 1, numberLength ) ); + auto idPosBegin = callData.find( '[' ); + auto idPosEnd = callData.find( ']' ); + if ( idPosBegin == std::string::npos || idPosEnd == std::string::npos || + idPosBegin > idPosEnd ) { + // means the input is incorrect + return { "unknown field", 0 }; + } + if ( callData.substr( 0, idPosBegin ) != "skaleConfig.sChain.nodes." ) { + // invalid input + return { "unknown field", 0 }; + } + for ( size_t pos = idPosBegin + 1; pos != idPosEnd; ++pos ) { + if ( !std::isdigit( callData[pos] ) ) { + // invalid input + return { "unknown field", 0 }; + } + } + size_t numberLength = idPosEnd - idPosBegin - 1; + unsigned id = std::stoul( callData.substr( idPosBegin + 1, numberLength ) ); std::string fieldName; - if ( callData.find( "id" ) != std::string::npos ) { + if ( boost::algorithm::ends_with( callData.c_str(), "id" ) ) { fieldName = "id"; - } else if ( callData.find( "schainIndex" ) != std::string::npos ) { + } else if ( boost::algorithm::ends_with( callData.c_str(), "schainIndex" ) ) { fieldName = "schainIndex"; - } else if ( callData.find( "owner" ) != std::string::npos ) { + } else if ( boost::algorithm::ends_with( callData.c_str(), "owner" ) ) { fieldName = "owner"; } else { fieldName = "unknown field"; @@ -781,6 +779,21 @@ static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std:: return { fieldName, id }; } +/* + * this precompiled contract is designed to get access to specific integer config values + * and works as key / values map + * input: bytes - length + path to config variable + * output: bytes - config variable value + * + * example: + * to request value for input=skaleConfig.sChain.nodes.[0].id + * one should pass the following + * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) + * + * variables available through this precompiled contract: + * 1. id - node id for INDEX node in schain group for current block number + * 2. schainIndex - schain index for INDEX node in schain group for current block number + */ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { try { size_t lengthName; @@ -818,11 +831,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); } - // dev::u256 uValue( strValue.c_str() ); - dev::u256 uValue = stat_parse_u256_hex_or_dec( strValue ); - // std::cout << "------------ Loaded config var \"" - // << rawName << "\" value is " << uValue - // << "\n"; + dev::u256 uValue = jsToInt( strValue ); bytes response = toBigEndian( uValue ); return { true, response }; } catch ( std::exception& ex ) { @@ -840,6 +849,19 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } +/* + * this precompiled contract is designed to get access to specific config values that are ETH + * addresses and works as key / values map input: bytes - length + path to config variable output: + * bytes - config variable value + * + * example: + * to request value for input=skaleConfig.sChain.nodes.[1].owner + * one should pass the following + * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) + * + * variables available through this precompiled contract: + * 1. owner - address for INDEX node in schain group for current block number + */ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { try { size_t lengthName; @@ -875,8 +897,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); } - dev::u256 uValue( strValue.c_str() ); - + dev::u256 uValue( strValue ); bytes response = toBigEndian( uValue ); return { true, response }; } catch ( std::exception& ex ) { From 582b526d033a9bbc21d1823a38b4714c2f91f8aa Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 8 Nov 2023 13:33:08 +0000 Subject: [PATCH 054/159] #1702 use common approach to access config variables --- libethereum/Precompiled.cpp | 62 +++++++++---------- .../unittests/libethereum/PrecompiledTest.cpp | 16 ++--- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 8dc4ed7d1..64c4a724b 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -746,32 +747,18 @@ static bool isCallToHistoricData( const std::string& callData ) { return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." ); } -static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { - auto idPosBegin = callData.find( '[' ); - auto idPosEnd = callData.find( ']' ); - if ( idPosBegin == std::string::npos || idPosEnd == std::string::npos || - idPosBegin > idPosEnd ) { - // means the input is incorrect - return { "unknown field", 0 }; - } - if ( callData.substr( 0, idPosBegin ) != "skaleConfig.sChain.nodes." ) { - // invalid input - return { "unknown field", 0 }; - } - for ( size_t pos = idPosBegin + 1; pos != idPosEnd; ++pos ) { - if ( !std::isdigit( callData[pos] ) ) { - // invalid input - return { "unknown field", 0 }; - } - } - size_t numberLength = idPosEnd - idPosBegin - 1; - unsigned id = std::stoul( callData.substr( idPosBegin + 1, numberLength ) ); +static std::pair< std::string, unsigned > parseHistoricFieldReuqest( std::string callData ) { + std::vector< std::string > splitted; + boost::split( splitted, callData, boost::is_any_of( "." ) ); + // first 3 elements are skaleConfig, sChain, nodes - it was checked before + unsigned id = std::stoul( splitted[3] ); std::string fieldName; - if ( boost::algorithm::ends_with( callData.c_str(), "id" ) ) { + boost::trim_if( splitted[4], []( char c ) { return c == '\0'; } ); + if ( splitted[4] == "id" ) { fieldName = "id"; - } else if ( boost::algorithm::ends_with( callData.c_str(), "schainIndex" ) ) { + } else if ( splitted[4] == "schainIndex" ) { fieldName = "schainIndex"; - } else if ( boost::algorithm::ends_with( callData.c_str(), "owner" ) ) { + } else if ( splitted[4] == "owner" ) { fieldName = "owner"; } else { fieldName = "unknown field"; @@ -785,14 +772,19 @@ static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std:: * input: bytes - length + path to config variable * output: bytes - config variable value * - * example: - * to request value for input=skaleConfig.sChain.nodes.[0].id - * one should pass the following - * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) - * * variables available through this precompiled contract: * 1. id - node id for INDEX node in schain group for current block number * 2. schainIndex - schain index for INDEX node in schain group for current block number + * to access those variables one should use the following scheme: + * prefix=skaleConfig.sChain.nodes - to access corresponding structure inside skaled + * index - node index user wants to get access to + * field - the field user wants to request + * + * example: + * to request the value for 1-st node (1 based) for the node id field the input should be + * input=skaleConfig.sChain.nodes.0.id (inside skaled node indexes are 0 based) + * so one should pass the following as calldata: + * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) */ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { try { @@ -854,13 +846,19 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { * addresses and works as key / values map input: bytes - length + path to config variable output: * bytes - config variable value * + * variables available through this precompiled contract: + * 1. owner - address for INDEX node in schain group for current block number + * to access those variables one should use the following scheme: + * prefix=skaleConfig.sChain.nodes - to access corresponding structure inside skaled + * index - node index user wants to get access to + * field - the field user wants to request + * * example: - * to request value for input=skaleConfig.sChain.nodes.[1].owner - * one should pass the following + * to request the value for 2-nd node (1 based) for the owner field the input should be + * input=skaleConfig.sChain.nodes.1.owner (inside skaled node indexes are 0 based) + * so one should pass the following as calldata * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) * - * variables available through this precompiled contract: - * 1. owner - address for INDEX node in schain group for current block number */ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { try { diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 8de629387..f380d6745 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1716,24 +1716,24 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); - bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); + bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.id" ) ); auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 30 ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.owner" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); @@ -1767,23 +1767,23 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - bytes in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].owner" ) ); + bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.owner" ) ); auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); - in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.[0].id" ) ); + in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.id" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].schainIndex" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.[0].unknownField" ) ); + in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ) ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); From ea694fc79379e4144f7c297cfdba71ded0d786c8 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 8 Nov 2023 15:35:08 +0000 Subject: [PATCH 055/159] #1702 improve code quality --- libethereum/Precompiled.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 64c4a724b..339829186 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -747,21 +747,19 @@ static bool isCallToHistoricData( const std::string& callData ) { return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." ); } -static std::pair< std::string, unsigned > parseHistoricFieldReuqest( std::string callData ) { +static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string callData ) { std::vector< std::string > splitted; boost::split( splitted, callData, boost::is_any_of( "." ) ); // first 3 elements are skaleConfig, sChain, nodes - it was checked before - unsigned id = std::stoul( splitted[3] ); + unsigned id = std::stoul( splitted.at( 3 ) ); std::string fieldName; - boost::trim_if( splitted[4], []( char c ) { return c == '\0'; } ); - if ( splitted[4] == "id" ) { - fieldName = "id"; - } else if ( splitted[4] == "schainIndex" ) { - fieldName = "schainIndex"; - } else if ( splitted[4] == "owner" ) { - fieldName = "owner"; + boost::trim_if( splitted.at( 4 ), []( char c ) { return c == '\0'; } ); + std::set< std::string > allowedValues{ "id", "schainIndex", "owner" }; + fieldName = splitted.at( 4 ); + if ( allowedValues.count( fieldName ) ) { + return { fieldName, id }; } else { - fieldName = "unknown field"; + BOOST_THROW_EXCEPTION( std::runtime_error( "Unknown field:" + fieldName ) ); } return { fieldName, id }; } @@ -807,7 +805,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { std::string field; unsigned id; - std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); + std::tie( field, id ) = parseHistoricFieldRequest( rawName ); if ( field == "id" ) { strValue = g_skaleHost->getHistoricNodeId( id ); } else if ( field == "schainIndex" ) { @@ -881,7 +879,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { std::string field; unsigned id; - std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); + std::tie( field, id ) = parseHistoricFieldRequest( rawName ); if ( field == "owner" ) { strValue = g_skaleHost->getHistoricNodeOwner( id ); } else { From ca16ebf0a361abad1c20c94431dcc1cc16ddb344 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 Nov 2023 13:35:21 +0000 Subject: [PATCH 056/159] #1702 improve input proccessing for precompileds --- libethereum/Precompiled.cpp | 14 ++++++--- .../unittests/libethereum/PrecompiledTest.cpp | 31 ++++++++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 339829186..fbc2be280 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -251,10 +251,16 @@ static Logger& getLogger( int a_severity = VerbosityTrace ) { static void convertBytesToString( bytesConstRef _in, size_t _startPosition, std::string& _out, size_t& _stringLength ) { + if ( _in.size() < UINT256_SIZE ) { + throw std::runtime_error( "Input is too short - invalid input in convertBytesToString()" ); + } bigint const sstringLength( parseBigEndianRightPadded( _in, _startPosition, UINT256_SIZE ) ); _stringLength = sstringLength.convert_to< size_t >(); + if ( _startPosition + UINT256_SIZE + _stringLength > _in.size() ) { + throw std::runtime_error( "Invalid input in convertBytesToString()" ); + } vector_ref< const unsigned char > byteFilename = - _in.cropped( _startPosition + 32, _stringLength ); + _in.cropped( _startPosition + UINT256_SIZE, _stringLength ); _out = std::string( ( char* ) byteFilename.data(), _stringLength ); } @@ -753,7 +759,6 @@ static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string // first 3 elements are skaleConfig, sChain, nodes - it was checked before unsigned id = std::stoul( splitted.at( 3 ) ); std::string fieldName; - boost::trim_if( splitted.at( 4 ), []( char c ) { return c == '\0'; } ); std::set< std::string > allowedValues{ "id", "schainIndex", "owner" }; fieldName = splitted.at( 4 ); if ( allowedValues.count( fieldName ) ) { @@ -782,7 +787,7 @@ static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string * to request the value for 1-st node (1 based) for the node id field the input should be * input=skaleConfig.sChain.nodes.0.id (inside skaled node indexes are 0 based) * so one should pass the following as calldata: - * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) + * toBytes( input.length + toBytes(input) ) */ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { try { @@ -855,8 +860,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { * to request the value for 2-nd node (1 based) for the owner field the input should be * input=skaleConfig.sChain.nodes.1.owner (inside skaled node indexes are 0 based) * so one should pass the following as calldata - * toBytes( ( ( input.length + 1 ) / 32 ) * 32) + toBytes(input) - * + * toBytes( input.length + toBytes(input) ) */ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { try { diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index f380d6745..4ede56bb3 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1715,25 +1715,32 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { dev::eth::g_skaleHost = testClient->skaleHost(); PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableUint256" ); + std::string input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); + input = input.substr(0, 58); // remove 0s in the end - bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.id" ) ); + bytes in = fromHex( numberToHex( 29 ) + input ); auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 30 ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); + input = input.substr(0, 76); // remove 0s in the end + in = fromHex( numberToHex( 38 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); - in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.owner" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); + in = fromHex( numberToHex( 32 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); + input = input.substr(0, 78); // remove 0s in the end + in = fromHex( numberToHex( 39 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); @@ -1767,23 +1774,31 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - bytes in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.owner" ) ); + std::string input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); + bytes in = fromHex( numberToHex( 32 ) + input ); auto res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); - in = fromHex( numberToHex( 32 ) + stringToHex( "skaleConfig.sChain.nodes.0.id" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); + input = input.substr(0, 58); // remove 0s in the end + + in = fromHex( numberToHex( 29 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); + input = input.substr(0, 76); // remove 0s in the end + in = fromHex( numberToHex( 38 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); - in = fromHex( numberToHex( 64 ) + stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); + input = input.substr(0, 78); // remove 0s in the end + in = fromHex( numberToHex( 39 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); From 49956134bfea1c270c9a83c40a8181946d432f0d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 Nov 2023 13:45:58 +0000 Subject: [PATCH 057/159] #1702 add more checks --- libethereum/Precompiled.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index fbc2be280..a4b7123f5 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -255,6 +255,10 @@ static void convertBytesToString( throw std::runtime_error( "Input is too short - invalid input in convertBytesToString()" ); } bigint const sstringLength( parseBigEndianRightPadded( _in, _startPosition, UINT256_SIZE ) ); + if ( sstringLength < 0 ) { + throw std::runtime_error( + "Negative string length - invalid input in convertBytesToString()" ); + } _stringLength = sstringLength.convert_to< size_t >(); if ( _startPosition + UINT256_SIZE + _stringLength > _in.size() ) { throw std::runtime_error( "Invalid input in convertBytesToString()" ); From edd62d4671c07a748776dd9688d12de8dbb84c39 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 13 Nov 2023 17:44:45 +0000 Subject: [PATCH 058/159] #1702 improve tests --- .../unittests/libethereum/PrecompiledTest.cpp | 97 +++++++++++++------ 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 4ede56bb3..06ecba280 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1688,7 +1688,7 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + } )E"; -BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { +BOOST_AUTO_TEST_CASE( getConfigVariable ) { ChainParams chainParams; chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); chainParams.sealEngineName = NoProof::name(); @@ -1744,39 +1744,12 @@ BOOST_AUTO_TEST_CASE( getConfigVariableUint256 ) { res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); -} - -BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { - ChainParams chainParams; - chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); - chainParams.sealEngineName = NoProof::name(); - chainParams.allowFutureBlocks = true; - - dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); - - std::unique_ptr client; - dev::TransientDirectory m_tmpDir; - auto monitor = make_shared< InstanceMonitor >("test"); - setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); - client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, - shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); - - client->injectSkaleHost(); - client->startWorking(); - client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); - - ClientTest* testClient = asClientTest( client.get() ); + exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - testClient->mineBlocks( 1 ); - testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); - dev::eth::g_skaleHost = testClient->skaleHost(); - - PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); - - std::string input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); - bytes in = fromHex( numberToHex( 32 ) + input ); - auto res = exec( bytesConstRef( in.data(), in.size() ) ); + input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); + in = fromHex( numberToHex( 32 ) + input ); + res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); @@ -1804,6 +1777,66 @@ BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { BOOST_REQUIRE( !res.first ); } +// temporary merge tests for getConfigVariable +// because of the specifics in test design +//BOOST_AUTO_TEST_CASE( getConfigVariableAddress ) { +// ChainParams chainParams; +// chainParams = chainParams.loadConfig( genesisInfoSkaleConfigTest ); +// chainParams.sealEngineName = NoProof::name(); +// chainParams.allowFutureBlocks = true; + +// dev::eth::g_configAccesssor.reset( new skutils::json_config_file_accessor( "../../test/unittests/libethereum/PrecompiledConfig.json" ) ); + +// std::unique_ptr client; +// dev::TransientDirectory m_tmpDir; +// auto monitor = make_shared< InstanceMonitor >("test"); +// setenv("DATA_DIR", m_tmpDir.path().c_str(), 1); +// client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, +// shared_ptr< GasPricer >(), nullptr, monitor, m_tmpDir.path(), dev::WithExisting::Kill ) ); + +// client->injectSkaleHost(); +// client->startWorking(); + +// client->setAuthor( Address("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") ); + +// ClientTest* testClient = asClientTest( client.get() ); + +// testClient->mineBlocks( 1 ); +// testClient->importTransactionsAsBlock( dev::eth::Transactions(), 1000, 4294967294 ); +// dev::eth::g_skaleHost = testClient->skaleHost(); + +// PrecompiledExecutor exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); + +// std::string input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); +// bytes in = fromHex( numberToHex( 32 ) + input ); +// auto res = exec( bytesConstRef( in.data(), in.size() ) ); + +// BOOST_REQUIRE( res.first ); +// BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); + +// input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); +// input = input.substr(0, 58); // remove 0s in the end + +// in = fromHex( numberToHex( 29 ) + input ); +// res = exec( bytesConstRef( in.data(), in.size() ) ); + +// BOOST_REQUIRE( !res.first ); + +// input = stringToHex( "skaleConfig.sChain.nodes.0.schainIndex" ); +// input = input.substr(0, 76); // remove 0s in the end +// in = fromHex( numberToHex( 38 ) + input ); +// res = exec( bytesConstRef( in.data(), in.size() ) ); + +// BOOST_REQUIRE( !res.first ); + +// input = stringToHex( "skaleConfig.sChain.nodes.0.unknownField" ); +// input = input.substr(0, 78); // remove 0s in the end +// in = fromHex( numberToHex( 39 ) + input ); +// res = exec( bytesConstRef( in.data(), in.size() ) ); + +// BOOST_REQUIRE( !res.first ); +//} + struct FilestorageFixture : public TestOutputHelperFixture { FilestorageFixture() { ownerAddress = Address( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ); From e47968b9039a7516033d6649699f1db8db7a1981 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 15 Nov 2023 19:50:05 +0000 Subject: [PATCH 059/159] SKALED-1623 Remove coloring --- libdevcore/Common.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index 26a99db7f..e15bb6ae7 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -50,18 +50,15 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { std::string strMessagePrefix; if ( nSignalNo > 0 ) { strMessagePrefix = ( ExitHandler::shouldExit() && s_nStopSignal > 0 ) ? - cc::error( "\nStop flag was already raised on. " ) + - cc::fatal( "WILL FORCE TERMINATE." ) + - cc::error( " Caught (second) signal. " ) : - cc::error( "\nCaught (first) signal. " ); + string( "\nStop flag was already raised on. " ) + + "WILL FORCE TERMINATE." + " Caught (second) signal. " : + "\nCaught (first) signal. "; } else { strMessagePrefix = ExitHandler::shouldExit() ? - cc::error( "\nInternal exit requested while already exiting. " ) : - cc::error( "\nInternal exit initiated. " ); + string( "\nInternal exit requested while already exiting. " ) : + "\nInternal exit initiated. "; } - std::cerr << strMessagePrefix << cc::error( skutils::signal::signal2str( nSignalNo ) ) - << "\n\n"; - std::cerr.flush(); + std::cerr << strMessagePrefix << skutils::signal::signal2str( nSignalNo ) << "\n\n"; switch ( nSignalNo ) { case SIGINT: @@ -109,10 +106,10 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { auto start_time = std::chrono::steady_clock::now(); std::thread( [nSignalNo, start_time]() { - std::cerr << ( "\n" + cc::fatal( "SELF-KILL:" ) + " " + cc::error( "Will sleep " ) + - cc::size10( ExitHandler::KILL_TIMEOUT ) + - cc::error( " seconds before force exit..." ) + "\n\n" ); - std::cerr.flush(); + std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " + "Will sleep " + + cc::size10( ExitHandler::KILL_TIMEOUT ) + + " seconds before force exit..." ) + + "\n\n"; clog( VerbosityInfo, "exit" ) << "THREADS timer started"; @@ -140,11 +137,10 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { std::this_thread::sleep_for( 100ms ); } - std::cerr << ( "\n" + cc::fatal( "SELF-KILL:" ) + " " + - cc::error( "Will force exit after sleeping " ) + + std::cerr << ( "\n" + string( "SELF-KILL:" ) + " " + + "Will force exit after sleeping " + cc::size10( ExitHandler::KILL_TIMEOUT ) + cc::error( " second(s)" ) + "\n\n" ); - std::cerr.flush(); // TODO deduplicate this with main() before return ExitHandler::exit_code_t ec = ExitHandler::requestedExitCode(); @@ -162,8 +158,7 @@ void ExitHandler::exitHandler( int nSignalNo, ExitHandler::exit_code_t ec ) { // TODO deduplicate with first if() if ( ExitHandler::shouldExit() && s_nStopSignal > 0 && nSignalNo > 0 ) { - std::cerr << ( "\n" + cc::fatal( "SIGNAL-HANDLER:" ) + " " + - cc::error( "Will force exit now..." ) + "\n\n" ); + std::cerr << ( "\n" + string( "SIGNAL-HANDLER:" ) + " " + "Will force exit now...\n\n" ); _exit( 13 ); } From 22eed1549b4ae8c21d7ffa58a81f680d771ccb47 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 20 Nov 2023 19:11:26 +0200 Subject: [PATCH 060/159] SKALED-1623 Use new branch in skale-ci --- .github/workflows/functional-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index 14d743434..4042e3a05 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -24,6 +24,7 @@ with: token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} repository: skalenetwork/skale-ci-integration_tests + ref: v3.18.0 submodules: recursive - name: Set up Node uses: actions/setup-node@v3.4.0 From 4b510812f6d6ccd9a5577786db5c08b9bcffffc1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 11:47:18 +0000 Subject: [PATCH 061/159] #1702 pass historic publicKey instead of address --- libethcore/ChainOperationParams.h | 1 - libethereum/ChainParams.cpp | 6 +- libethereum/Client.h | 4 +- libethereum/Precompiled.cpp | 91 ++++++++++--------- libethereum/SkaleHost.cpp | 4 +- libethereum/SkaleHost.h | 4 +- test/unittests/libethereum/ClientTest.cpp | 12 +-- .../libethereum/PrecompiledConfig.json | 6 +- .../unittests/libethereum/PrecompiledTest.cpp | 10 +- 9 files changed, 64 insertions(+), 74 deletions(-) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 5ac129ec6..3e442229d 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -140,7 +140,6 @@ struct GroupNode { u256 id; u256 schainIndex; std::string publicKey; - std::string address; }; /// skale diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 72d8a2eb3..fec3da5a5 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -296,14 +296,10 @@ ChainParams ChainParams::loadConfig( u256 sChainIndex = groupNodeConfObj.at( 0 ).get_uint64(); u256 id = groupNodeConfObj.at( 1 ).get_uint64(); std::string publicKey = groupNodeConfObj.at( 2 ).get_str(); - std::string address = groupNodeConfObj.at( 3 ).get_str(); if ( publicKey.empty() ) { BOOST_THROW_EXCEPTION( std::runtime_error( "Empty public key in config" ) ); } - if ( address.empty() ) { - BOOST_THROW_EXCEPTION( std::runtime_error( "Empty address in config" ) ); - } - groupNodes.push_back( { id, sChainIndex, publicKey, address } ); + groupNodes.push_back( { id, sChainIndex, publicKey } ); } std::sort( groupNodes.begin(), groupNodes.end(), []( const GroupNode& lhs, const GroupNode& rhs ) { diff --git a/libethereum/Client.h b/libethereum/Client.h index 6579818b2..6ad196a0d 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -311,8 +311,8 @@ class Client : public ClientBase, protected Worker { } // get node owner for historic node in chain - std::string getHistoricNodeOwner( unsigned _idx ) const { - return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].address; + std::string getHistoricNodePublicKey( unsigned _idx ) const { + return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].publicKey; } void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); } diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index a4b7123f5..9bc432a45 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -763,7 +763,7 @@ static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string // first 3 elements are skaleConfig, sChain, nodes - it was checked before unsigned id = std::stoul( splitted.at( 3 ) ); std::string fieldName; - std::set< std::string > allowedValues{ "id", "schainIndex", "owner" }; + std::set< std::string > allowedValues{ "id", "schainIndex", "publicKey" }; fieldName = splitted.at( 4 ); if ( allowedValues.count( fieldName ) ) { return { fieldName, id }; @@ -848,25 +848,61 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } +ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { + try { + size_t lengthName; + std::string rawName; + convertBytesToString( _in, 0, rawName, lengthName ); + if ( !stat_is_accessible_json_path( rawName ) ) + throw std::runtime_error( + "Security poicy violation, inaccessible configuration JSON path: " + rawName ); + + if ( !g_configAccesssor ) + throw std::runtime_error( "Config accessor was not initialized" ); + + nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); + nlohmann::json joValue = + skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); + std::string strValue = skutils::tools::trim_copy( + joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); + + dev::u256 uValue( strValue ); + bytes response = toBigEndian( uValue ); + return { true, response }; + } catch ( std::exception& ex ) { + std::string strError = ex.what(); + if ( strError.empty() ) + strError = "exception without description"; + LOG( getLogger( VerbosityError ) ) + << "Exception in precompiled/getConfigVariableAddress(): " << strError << "\n"; + } catch ( ... ) { + LOG( getLogger( VerbosityError ) ) + << "Unknown exception in precompiled/getConfigVariableAddress()\n"; + } + u256 code = 0; + bytes response = toBigEndian( code ); + return { false, response }; // 1st false - means bad error occur +} + /* - * this precompiled contract is designed to get access to specific config values that are ETH - * addresses and works as key / values map input: bytes - length + path to config variable output: + * this precompiled contract is designed to get access to specific config values that are + * strings and works as key / values map input: bytes - length + path to config variable output: * bytes - config variable value * * variables available through this precompiled contract: - * 1. owner - address for INDEX node in schain group for current block number + * 1. publicKey - ETH public key for INDEX node in schain group for current block number * to access those variables one should use the following scheme: * prefix=skaleConfig.sChain.nodes - to access corresponding structure inside skaled * index - node index user wants to get access to * field - the field user wants to request * * example: - * to request the value for 2-nd node (1 based) for the owner field the input should be - * input=skaleConfig.sChain.nodes.1.owner (inside skaled node indexes are 0 based) + * to request the value for 2-nd node (1 based) for the publicKey field the input should be + * input=skaleConfig.sChain.nodes.1.publicKey (inside skaled node indexes are 0 based) * so one should pass the following as calldata * toBytes( input.length + toBytes(input) ) */ -ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { +ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { try { size_t lengthName; std::string rawName; @@ -877,7 +913,6 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { if ( !g_configAccesssor ) throw std::runtime_error( "Config accessor was not initialized" ); - std::string strValue; // call to skaleConfig.sChain.nodes means call to the historic data // need to proccess it in a different way @@ -888,8 +923,8 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { std::string field; unsigned id; std::tie( field, id ) = parseHistoricFieldRequest( rawName ); - if ( field == "owner" ) { - strValue = g_skaleHost->getHistoricNodeOwner( id ); + if ( field == "publicKey" ) { + strValue = g_skaleHost->getHistoricNodePublicKey( id ); } else { throw std::runtime_error( "Incorrect config field" ); } @@ -900,41 +935,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { strValue = skutils::tools::trim_copy( joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); } - - dev::u256 uValue( strValue ); - bytes response = toBigEndian( uValue ); - return { true, response }; - } catch ( std::exception& ex ) { - std::string strError = ex.what(); - if ( strError.empty() ) - strError = "exception without description"; - LOG( getLogger( VerbosityError ) ) - << "Exception in precompiled/getConfigVariableAddress(): " << strError << "\n"; - } catch ( ... ) { - LOG( getLogger( VerbosityError ) ) - << "Unknown exception in precompiled/getConfigVariableAddress()\n"; - } - u256 code = 0; - bytes response = toBigEndian( code ); - return { false, response }; // 1st false - means bad error occur -} - -ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { - try { - size_t lengthName; - std::string rawName; - convertBytesToString( _in, 0, rawName, lengthName ); - if ( !stat_is_accessible_json_path( rawName ) ) - throw std::runtime_error( - "Security poicy violation, inaccessible configuration JSON path: " + rawName ); - - if ( !g_configAccesssor ) - throw std::runtime_error( "Config accessor was not initialized" ); - nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); - nlohmann::json joValue = - skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); - std::string strValue = joValue.is_string() ? joValue.get< std::string >() : joValue.dump(); - bytes response = stat_string_to_bytes_with_length( strValue ); + bytes response = dev::asBytes( strValue ); return { true, response }; } catch ( std::exception& ex ) { std::string strError = ex.what(); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 53a318180..3db110bd3 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -958,8 +958,8 @@ std::string SkaleHost::getHistoricNodeIndex( unsigned _index ) const { return m_client.getHistoricNodeIndex( _index ); } -std::string SkaleHost::getHistoricNodeOwner( unsigned _idx ) const { - return m_client.getHistoricNodeOwner( _idx ); +std::string SkaleHost::getHistoricNodePublicKey( unsigned _idx ) const { + return m_client.getHistoricNodePublicKey( _idx ); } uint64_t SkaleHost::submitOracleRequest( diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index b5ae631c9..82a4c6357 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -132,8 +132,8 @@ class SkaleHost { // get schain index for historic node in chain std::string getHistoricNodeIndex( unsigned _idx ) const; - // get node owner for historic node in chain - std::string getHistoricNodeOwner( unsigned _idx ) const; + // get public key for historic node in chain + std::string getHistoricNodePublicKey( unsigned _idx ) const; uint64_t submitOracleRequest( const string& _spec, string& _receipt, string& _errorMessage ); uint64_t checkOracleResult( const string& _receipt, string& _result ); diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 791ae56c4..1ba92556c 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -815,7 +815,7 @@ BOOST_AUTO_TEST_CASE( consumptionWithReverts ) { BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE( IMABLSPublicKey ) +BOOST_AUTO_TEST_SUITE( getHistoricNodesData ) static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + R"E( @@ -872,8 +872,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "30": [ 0, 30, - "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", - "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b" ] }, "finish_ts": null, @@ -889,8 +888,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "26": [ 3, 26, - "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", - "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba" ] }, "finish_ts": 4294967290, @@ -927,7 +925,7 @@ BOOST_AUTO_TEST_CASE( initAndUpdateHistoricConfigFields ) { std::array< std::string, 4 > imaBLSPublicKeyOnStartUp = { "12457351342169393659284905310882617316356538373005664536506840512800919345414", "11573096151310346982175966190385407867176668720531590318594794283907348596326", "13929944172721019694880576097738949215943314024940461401664534665129747139387", "7375214420811287025501422512322868338311819657776589198925786170409964211914" }; BOOST_REQUIRE( testClient->getIMABLSPublicKey() == imaBLSPublicKeyOnStartUp ); - BOOST_REQUIRE( testClient->getHistoricNodeOwner( 0 ) == "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" ); + BOOST_REQUIRE( testClient->getHistoricNodePublicKey( 0 ) == "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba" ); BOOST_REQUIRE( testClient->getHistoricNodeId( 0 ) == "26" ); BOOST_REQUIRE( testClient->getHistoricNodeIndex( 0 ) == "3" ); @@ -938,7 +936,7 @@ BOOST_AUTO_TEST_CASE( initAndUpdateHistoricConfigFields ) { std::array< std::string, 4 > imaBLSPublicKeyAfterBlock = { "10860211539819517237363395256510340030868592687836950245163587507107792195621", "2419969454136313127863904023626922181546178935031521540751337209075607503568", "3399776985251727272800732947224655319335094876742988846345707000254666193993", "16982202412630419037827505223148517434545454619191931299977913428346639096984" }; BOOST_REQUIRE( testClient->getIMABLSPublicKey() == imaBLSPublicKeyAfterBlock ); - BOOST_REQUIRE( testClient->getHistoricNodeOwner( 0 ) == "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" ); + BOOST_REQUIRE( testClient->getHistoricNodePublicKey( 0 ) == "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b" ); BOOST_REQUIRE( testClient->getHistoricNodeId( 0 ) == "30" ); BOOST_REQUIRE( testClient->getHistoricNodeIndex( 0 ) == "0" ); } diff --git a/test/unittests/libethereum/PrecompiledConfig.json b/test/unittests/libethereum/PrecompiledConfig.json index d5889d2b5..356aeced1 100644 --- a/test/unittests/libethereum/PrecompiledConfig.json +++ b/test/unittests/libethereum/PrecompiledConfig.json @@ -52,8 +52,7 @@ "30": [ 0, 30, - "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", - "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b" ] }, "finish_ts": null, @@ -69,8 +68,7 @@ "26": [ 3, 26, - "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", - "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba" ] }, "finish_ts": 4294967290, diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 06ecba280..cc1638d26 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1635,7 +1635,6 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + 13, 30, "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", - "0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe" ] }, "finish_ts": null, @@ -1652,7 +1651,6 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + 3, 26, "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", - "0x47bbe8db4e347b4e8c937c1c8350e4b7ed30adb3db69bbdb7a38c1f40a1b82fd" ] }, "finish_ts": 4294967290, @@ -1732,7 +1730,7 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( res.first ); BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); - input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); + input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); in = fromHex( numberToHex( 32 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); @@ -1745,14 +1743,14 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( !res.first ); - exec = PrecompiledRegistrar::executor( "getConfigVariableAddress" ); + exec = PrecompiledRegistrar::executor( "getConfigVariableString" ); - input = stringToHex( "skaleConfig.sChain.nodes.0.owner" ); + input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); in = fromHex( numberToHex( 32 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); - BOOST_REQUIRE( res.second == fromHex("0x23bbe8db4e347b4e8c937c1c8350e4b5ed33adb3db69cbdb7a38e1f40a1b82fe") ); + BOOST_REQUIRE( res.second == fromHex("0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b") ); input = stringToHex( "skaleConfig.sChain.nodes.0.id" ); input = input.substr(0, 58); // remove 0s in the end From a5040906ce34b54105eb2d498ab477890d86e45a Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 13:58:30 +0000 Subject: [PATCH 062/159] #1702 fix tests --- libethereum/Precompiled.cpp | 5 +++-- test/unittests/libethereum/PrecompiledTest.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 9bc432a45..aecc33209 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -687,7 +687,8 @@ ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -static const std::list< std::string > g_listReadableConfigParts{ "skaleConfig.sChain.nodes." }; +static const std::list< std::string > g_listReadableConfigParts{ "skaleConfig.sChain.nodes.", + "skaleConfig.nodeInfo.wallets.ima.n" }; static bool stat_is_accessible_json_path( const std::string& strPath ) { if ( strPath.empty() ) @@ -935,7 +936,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableString )( bytesConstRef _in ) { strValue = skutils::tools::trim_copy( joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); } - bytes response = dev::asBytes( strValue ); + bytes response = dev::fromHex( strValue ); return { true, response }; } catch ( std::exception& ex ) { std::string strError = ex.what(); diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index cc1638d26..2ccea50d1 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1634,7 +1634,7 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + "30": [ 13, 30, - "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b", + "0x6180cde2cbbcc6b6a17efec4503a7d4316f8612f411ee171587089f770335f484003ad236c534b9afa82befc1f69533723abdb6ec2601e582b72dcfd7919338b" ] }, "finish_ts": null, @@ -1650,7 +1650,7 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + "26": [ 3, 26, - "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba", + "0x3a581d62b12232dade30c3710215a271984841657449d1f474295a13737b778266f57e298f123ae80cbab7cc35ead1b62a387556f94b326d5c65d4a7aa2abcba" ] }, "finish_ts": 4294967290, @@ -1731,7 +1731,8 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 13 ); input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); - in = fromHex( numberToHex( 32 ) + input ); + input = input.substr(0, 72); // remove 0s in the end + in = fromHex( numberToHex( 36 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( !res.first ); @@ -1746,7 +1747,8 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { exec = PrecompiledRegistrar::executor( "getConfigVariableString" ); input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); - in = fromHex( numberToHex( 32 ) + input ); + input = input.substr(0, 72); // remove 0s in the end + in = fromHex( numberToHex( 36 ) + input ); res = exec( bytesConstRef( in.data(), in.size() ) ); BOOST_REQUIRE( res.first ); From 1a673802d1ed58567e2df27b294cf479036e13a2 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 16:27:43 +0000 Subject: [PATCH 063/159] #1702 add more tests --- .../libethereum/PrecompiledConfig.json | 7 +++++- .../unittests/libethereum/PrecompiledTest.cpp | 22 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/test/unittests/libethereum/PrecompiledConfig.json b/test/unittests/libethereum/PrecompiledConfig.json index 356aeced1..b7b4901f0 100644 --- a/test/unittests/libethereum/PrecompiledConfig.json +++ b/test/unittests/libethereum/PrecompiledConfig.json @@ -38,7 +38,12 @@ "basePort": 1234, "logLevel": "trace", "logLevelProposal": "trace", - "ecdsaKeyName": "NEK:fa112" + "ecdsaKeyName": "NEK:fa112", + "wallets": { + "ima": { + "n": 1 + } + } }, "sChain": { "schainName": "TestChain", diff --git a/test/unittests/libethereum/PrecompiledTest.cpp b/test/unittests/libethereum/PrecompiledTest.cpp index 2ccea50d1..20498f3d9 100644 --- a/test/unittests/libethereum/PrecompiledTest.cpp +++ b/test/unittests/libethereum/PrecompiledTest.cpp @@ -1620,7 +1620,12 @@ static std::string const genesisInfoSkaleConfigTest = std::string() + "basePort": 1234, "logLevel": "trace", "logLevelProposal": "trace", - "ecdsaKeyName": "NEK:fa112" + "ecdsaKeyName": "NEK:fa112", + "wallets": { + "ima": { + "n": 1 + } + } }, "sChain": { "schainName": "TestChain", @@ -1744,6 +1749,21 @@ BOOST_AUTO_TEST_CASE( getConfigVariable ) { BOOST_REQUIRE( !res.first ); + input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.n" ); + input = input.substr(0, 68); // remove 0s in the end + in = fromHex( numberToHex( 34 ) + input ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( res.first ); + BOOST_REQUIRE( dev::fromBigEndian( res.second ) == 1 ); + + input = stringToHex( "skaleConfig.nodeInfo.wallets.ima.t" ); + input = input.substr(0, 68); // remove 0s in the end + in = fromHex( numberToHex( 34 ) + input ); + res = exec( bytesConstRef( in.data(), in.size() ) ); + + BOOST_REQUIRE( !res.first ); + exec = PrecompiledRegistrar::executor( "getConfigVariableString" ); input = stringToHex( "skaleConfig.sChain.nodes.0.publicKey" ); From 7700738e8c331c1d077d6ba63657cf4504a55438 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 16:50:56 +0000 Subject: [PATCH 064/159] #1702 change [] to at() --- libethereum/Client.cpp | 2 +- libethereum/Client.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 0822ba107..00c90351c 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1327,7 +1327,7 @@ void Client::initHistoricGroupIndex() { void Client::updateHistoricGroupIndex() { uint64_t blockTimestamp = blockInfo( hashFromNumber( number() ) ).timestamp(); - uint64_t currentFinishTs = chainParams().sChain.nodeGroups[historicGroupIndex].finishTs; + uint64_t currentFinishTs = chainParams().sChain.nodeGroups.at( historicGroupIndex ).finishTs; if ( blockTimestamp >= currentFinishTs ) ++historicGroupIndex; if ( historicGroupIndex >= chainParams().sChain.nodeGroups.size() ) { diff --git a/libethereum/Client.h b/libethereum/Client.h index 6ad196a0d..4a1b3fb8d 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -297,22 +297,25 @@ class Client : public ClientBase, protected Worker { } std::array< std::string, 4 > getIMABLSPublicKey() const { - return chainParams().sChain.nodeGroups[historicGroupIndex].blsPublicKey; + return chainParams().sChain.nodeGroups.at( historicGroupIndex ).blsPublicKey; } // get node id for historic node in chain std::string getHistoricNodeId( unsigned _id ) const { - return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_id].id.str(); + return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes[_id].id.str(); } // get schain index for historic node in chain std::string getHistoricNodeIndex( unsigned _idx ) const { - return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].schainIndex.str(); + return chainParams() + .sChain.nodeGroups.at( historicGroupIndex ) + .nodes[_idx] + .schainIndex.str(); } // get node owner for historic node in chain std::string getHistoricNodePublicKey( unsigned _idx ) const { - return chainParams().sChain.nodeGroups[historicGroupIndex].nodes[_idx].publicKey; + return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes[_idx].publicKey; } void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); } From c8921f68be1ccedd2b44f54d6619ab6d201f0277 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 17:56:11 +0000 Subject: [PATCH 065/159] #1702 change [] to at() --- libethereum/Client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/Client.h b/libethereum/Client.h index 4a1b3fb8d..415e4d126 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -302,7 +302,7 @@ class Client : public ClientBase, protected Worker { // get node id for historic node in chain std::string getHistoricNodeId( unsigned _id ) const { - return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes[_id].id.str(); + return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes.at( _id ).id.str(); } // get schain index for historic node in chain @@ -315,7 +315,7 @@ class Client : public ClientBase, protected Worker { // get node owner for historic node in chain std::string getHistoricNodePublicKey( unsigned _idx ) const { - return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes[_idx].publicKey; + return chainParams().sChain.nodeGroups.at( historicGroupIndex ).nodes.at( _idx ).publicKey; } void doStateDbCompaction() const { m_state.getOriginalDb()->doCompaction(); } From 23a54370afb437f9fdd19fc084acb5de26fc587d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 22 Nov 2023 17:56:45 +0000 Subject: [PATCH 066/159] #1702 change [] to at() --- libethereum/Client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Client.h b/libethereum/Client.h index 415e4d126..3bf2015c4 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -309,7 +309,7 @@ class Client : public ClientBase, protected Worker { std::string getHistoricNodeIndex( unsigned _idx ) const { return chainParams() .sChain.nodeGroups.at( historicGroupIndex ) - .nodes[_idx] + .nodes.at( _idx ) .schainIndex.str(); } From 9339f775b0375188aaf6db15ff07c7ed76d24978 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 23 Nov 2023 12:17:46 +0000 Subject: [PATCH 067/159] fix build all option --- storage_benchmark/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/storage_benchmark/CMakeLists.txt b/storage_benchmark/CMakeLists.txt index 8180d42dc..67b410f4b 100644 --- a/storage_benchmark/CMakeLists.txt +++ b/storage_benchmark/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries( historic skutils devcore + skale "${DEPS_INSTALL_ROOT}/lib/libunwind.a" "${DEPS_INSTALL_ROOT}/lib/liblzma.a" ) From 0893864e37492a5bd8f1ca424318021d4324baaf Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 23 Nov 2023 16:26:34 +0000 Subject: [PATCH 068/159] #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 069/159] 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 e3c44ce096197c0be7e1690faa3a239a811cf633 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:06:28 +0000 Subject: [PATCH 070/159] #813 update consensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 5a9b85d8f..952e3890d 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 5a9b85d8f171e1ba5f7dfe244cff70e0e39aa5f4 +Subproject commit 952e3890d620d55d56e32dc0fbd26637f23d0694 From 55fc623af4d66317105e96f9e740aa6e624450b9 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:33:34 +0000 Subject: [PATCH 071/159] #813 update consensus --- test/unittests/libethereum/SkaleHost.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 1e5590e4a..7870cd7c9 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -89,13 +89,18 @@ class ConsensusTestStub : public ConsensusInterface { } uint64_t checkOracleResult( const string& - /*_receipt*/, string& /*_result */) { + /*_receipt*/, string& /*_result */) override { return 0; } - map< string, uint64_t > getConsensusDbUsage() const { + map< string, uint64_t > getConsensusDbUsage() const override { return map< string, uint64_t >(); }; + + virtual ConsensusInterface::SyncInfo getSyncInfo() override { + return ConsensusInterface::SyncInfo{}; + }; + }; class ConsensusTestStubFactory : public ConsensusFactory { From 6960ca5dc80c290a84575913e5c3bd303feb2ed1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 4 Dec 2023 11:00:21 +0000 Subject: [PATCH 072/159] #1433 delete partially downloaded snapshots --- skaled/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skaled/main.cpp b/skaled/main.cpp index d33635a2f..4cd4077d4 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -274,6 +274,8 @@ void downloadSnapshot( unsigned block_number, std::shared_ptr< SnapshotManager > throw std::runtime_error( strErrorDescription ); } } catch ( ... ) { + // remove partially downloaded snapshot + boost::filesystem::remove( saveTo ); std::throw_with_nested( std::runtime_error( cc::error( "Exception while downloading snapshot" ) ) ); } From b3bd08be561f033a89ba8809f3cc906edaeb11ae Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 5 Dec 2023 09:41:40 +0000 Subject: [PATCH 073/159] #1433 fix logs --- skaled/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/skaled/main.cpp b/skaled/main.cpp index 4cd4077d4..381cda01f 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -276,8 +276,7 @@ void downloadSnapshot( unsigned block_number, std::shared_ptr< SnapshotManager > } catch ( ... ) { // remove partially downloaded snapshot boost::filesystem::remove( saveTo ); - std::throw_with_nested( - std::runtime_error( cc::error( "Exception while downloading snapshot" ) ) ); + std::throw_with_nested( std::runtime_error( "Exception while downloading snapshot" ) ); } clog( VerbosityInfo, "downloadSnapshot" ) << cc::success( "Snapshot download success for block " ) From 0c807eac73acaa3d90dd38a2bad57694359cf38d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 5 Dec 2023 16:29:57 +0000 Subject: [PATCH 074/159] #1199 eth syncing --- libethereum/Client.cpp | 5 +---- libethereum/SkaleHost.cpp | 11 +++++++++++ libethereum/SkaleHost.h | 2 ++ libweb3jsonrpc/Eth.cpp | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 00c90351c..14ad8e367 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1128,10 +1128,7 @@ Transactions Client::pending() const { } SyncStatus Client::syncStatus() const { - // TODO implement this when syncing will be needed - SyncStatus s; - s.startBlockNumber = s.currentBlockNumber = s.highestBlockNumber = 0; - return s; + return m_skaleHost->syncStatus(); } TransactionSkeleton Client::populateTransactionWithDefaults( TransactionSkeleton const& _t ) const { diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 0cbb4241f..216c5c1bf 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -942,6 +942,17 @@ u256 SkaleHost::getBlockRandom() const { return m_consensus->getRandomForBlockId( m_client.number() ); } +dev::eth::SyncStatus SkaleHost::syncStatus() const { + auto syncInfo = m_consensus->getSyncInfo(); + dev::eth::SyncStatus syncStatus; + syncStatus.state = syncInfo.isSyncing ? dev::eth::SyncState::Blocks : dev::eth::SyncState::Idle; + syncStatus.startBlockNumber = syncInfo.startingBlock; + syncStatus.currentBlockNumber = syncInfo.currentBlock; + syncStatus.highestBlockNumber = syncInfo.highestBlock; + syncStatus.majorSyncing = syncInfo.isSyncing; + return syncStatus; +} + std::map< std::string, uint64_t > SkaleHost::getConsensusDbUsage() const { return m_consensus->getConsensusDbUsage(); } diff --git a/libethereum/SkaleHost.h b/libethereum/SkaleHost.h index 82a4c6357..a92fc5462 100644 --- a/libethereum/SkaleHost.h +++ b/libethereum/SkaleHost.h @@ -51,6 +51,7 @@ namespace dev { namespace eth { +struct SyncStatus; class Client; class TransactionQueue; class BlockHeader; @@ -123,6 +124,7 @@ class SkaleHost { dev::u256 getGasPrice() const; dev::u256 getBlockRandom() const; + dev::eth::SyncStatus syncStatus() const; std::map< std::string, uint64_t > getConsensusDbUsage() const; std::array< std::string, 4 > getIMABLSPublicKey() const; diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 135b08584..4a7d20bd4 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -893,7 +893,7 @@ Json::Value Eth::eth_getWork() { Json::Value Eth::eth_syncing() { dev::eth::SyncStatus sync = client()->syncStatus(); - if ( sync.state == SyncState::Idle || !sync.majorSyncing ) + if ( !sync.majorSyncing ) return Json::Value( false ); Json::Value info( Json::objectValue ); From 164b7ca127640d6041ec7d1395063fe745ce0aff Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 5 Dec 2023 16:43:03 +0000 Subject: [PATCH 075/159] #1199 add comments --- libethereum/SkaleHost.cpp | 2 ++ libweb3jsonrpc/Eth.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 216c5c1bf..9ebea7d1a 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -945,6 +945,8 @@ u256 SkaleHost::getBlockRandom() const { dev::eth::SyncStatus SkaleHost::syncStatus() const { auto syncInfo = m_consensus->getSyncInfo(); dev::eth::SyncStatus syncStatus; + // SKALE: catchup downloads blocks with transactions, then the node executes them + // we don't download state changes separately syncStatus.state = syncInfo.isSyncing ? dev::eth::SyncState::Blocks : dev::eth::SyncState::Idle; syncStatus.startBlockNumber = syncInfo.startingBlock; syncStatus.currentBlockNumber = syncInfo.currentBlock; diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 4a7d20bd4..988022a29 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -892,6 +892,7 @@ Json::Value Eth::eth_getWork() { } Json::Value Eth::eth_syncing() { + // ask consensus whether the node is in catchup mode dev::eth::SyncStatus sync = client()->syncStatus(); if ( !sync.majorSyncing ) return Json::Value( false ); From 21d04f204a3788d0085234259508ad64c62f94b9 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 6 Dec 2023 17:06:17 +0000 Subject: [PATCH 076/159] SKALED-1600 Use correct fork in gas estimation --- libethereum/Block.cpp | 5 +- libethereum/Client.cpp | 4 +- libethereum/ClientBase.cpp | 6 +- libethereum/SkaleHost.cpp | 2 +- libethereum/Transaction.cpp | 9 ++- libethereum/Transaction.h | 9 ++- libweb3jsonrpc/EthFace.h | 3 +- test/tools/libtesteth/ImportTest.cpp | 2 +- test/unittests/libethereum/ClientTest.cpp | 42 ++++++++-- test/unittests/libethereum/SkaleHost.cpp | 10 +-- .../libweb3jsonrpc/WebThreeStubClient.cpp | 3 +- .../libweb3jsonrpc/WebThreeStubClient.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 81 ++++++++++++++++--- 13 files changed, 140 insertions(+), 38 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index 28e17ad0f..d98705d88 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -351,7 +351,7 @@ pair< TransactionReceipts, bool > Block::sync( // caller if we hit the limit for ( Transaction& transaction : transactions ) { - transaction.checkOutExternalGas( _bc.chainParams().externalGasDifficulty ); + transaction.checkOutExternalGas( _bc.chainParams(), _bc.number() ); } assert( _bc.currentHash() == m_currentBlock.parentHash() ); @@ -631,8 +631,7 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) { // << " (state #" // << state().getNonce( tr.from() ) << ") value = " << tr.value() << // endl; - const_cast< Transaction& >( tr ).checkOutExternalGas( - _bc.chainParams().externalGasDifficulty ); + const_cast< Transaction& >( tr ).checkOutExternalGas( _bc.chainParams(), _bc.number() ); execute( _bc.lastBlockHashes(), tr ); // cerr << "Now: " // << "State #" << state().getNonce( tr.from() ) << endl; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 00c90351c..8543b821e 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1189,7 +1189,7 @@ h256 Client::importTransaction( Transaction const& _t ) { // the latest block in the client's blockchain. This can throw but // we'll catch the exception at the RPC level. - const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams().externalGasDifficulty ); + const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); // throws in case of error State state; @@ -1279,7 +1279,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.checkOutExternalGas( ~u256( 0 ) ); + t.ignoreExternalGas(); if ( _ff == FudgeFactor::Lenient ) temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 6d646f45a..35a031695 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -89,7 +89,7 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl t = Transaction( _value, _gasPrice, _gas, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainId() ); - t.checkOutExternalGas( ~u256( 0 ) ); + t.ignoreExternalGas(); EnvInfo const env( _latestBlock.info(), bc().lastBlockHashes(), 0, _gas ); // Make a copy of state!! It will be deleted after step! State tempState = _latestBlock.mutableState(); @@ -115,7 +115,9 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from int64_t upperBound = _maxGas; if ( upperBound == Invalid256 || upperBound > c_maxGasEstimate ) upperBound = c_maxGasEstimate; - int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, EVMSchedule() ); + int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, + bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ); + Block bk = latestBlock(); if ( upperBound > bk.info().gasLimit() ) { upperBound = bk.info().gasLimit().convert_to< int64_t >(); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 0cbb4241f..ba19ceb6e 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -665,7 +665,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // ).detach(); } else { Transaction t( data, CheckTransaction::Everything, true ); - t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty ); + t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Will import consensus-born txn!"; m_debugTracer.tracepoint( "import_consensus_born" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 1645c30c3..4e381df9d 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -180,17 +180,18 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( u256 const& _difficulty ) { - assert( _difficulty > 0 ); +void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { + u256 const& difficulty = _cp.externalGasDifficulty; + assert( difficulty > 0 ); if ( !m_externalGasIsChecked && !isInvalid() ) { h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); if ( !hash ) { hash = h256( 1 ); } - u256 externalGas = ~u256( 0 ) / u256( hash ) / _difficulty; + u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty; if ( externalGas > 0 ) ctrace << "Mined gas: " << externalGas << endl; - if ( externalGas >= baseGasRequired( ConstantinopleSchedule ) ) { + if ( externalGas >= baseGasRequired( _cp.scheduleForBlockNumber( _bn ) ) ) { m_externalGas = externalGas; } m_externalGasIsChecked = true; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 6764bce5a..5cc8cf1eb 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -29,6 +29,8 @@ #include #include +#include "ChainParams.h" + namespace dev { namespace eth { @@ -120,7 +122,12 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( u256 const& _difficulty ); + void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ); + + void ignoreExternalGas() { + m_externalGasIsChecked = true; + m_externalGas = 0; + } private: bool m_externalGasIsChecked = false; diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 648d4424c..6bd085699 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -212,7 +212,8 @@ class EthFace : public ServerInterface< EthFace > { jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::EthFace::eth_syncingI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_estimateGas", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_STRING, "param1", jsonrpc::JSON_OBJECT, NULL ), + jsonrpc::JSON_STRING, "param1", jsonrpc::JSON_OBJECT, "param2", + jsonrpc::JSON_STRING, NULL ), &dev::rpc::EthFace::eth_estimateGasI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_chainId", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ), diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index 8400ed13c..3b4df86c3 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -225,7 +225,7 @@ bytes ImportTest::executeTest( bool _isFilling ) { continue; for ( auto& tr : m_transactions ) { - tr.transaction.checkOutExternalGas( 100 ); +// tr.transaction.checkOutExternalGas( 100 ); Options const& opt = Options::get(); if ( opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd ) continue; diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 1ba92556c..09160c7fe 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -339,7 +339,11 @@ static std::string const c_configString = R"( "allowFutureBlocks": true, "homesteadForkBlock": "0x00", "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00" + "EIP158ForkBlock": "0x00", + "byzantiumForkBlock": "0x00", + "constantinopleForkBlock": "0x00", + "constantinopleFixForkBlock": "0x00", + "istanbulForkBlock": "0x00" }, "genesis": { "nonce": "0x0000000000000042", @@ -375,6 +379,7 @@ static std::string const c_genesisInfoSkaleTest = std::string() + "byzantiumForkBlock": "0x00", "constantinopleForkBlock": "0x00", "constantinopleFixForkBlock": "0x00", + "istanbulForkBlock": "0x00", "networkID" : "12313219", "chainID": "0x01", "maximumExtraDataSize": "0x20", @@ -439,6 +444,25 @@ static std::string const c_genesisInfoSkaleTest = std::string() + BOOST_AUTO_TEST_SUITE( EstimateGas ) +BOOST_AUTO_TEST_CASE( transactionWithData ) { + TestClientFixture fixture( c_genesisInfoSkaleTest ); + ClientTest* testClient = asClientTest( fixture.ethereum() ); + + dev::eth::simulateMining( *( fixture.ethereum() ), 10 ); + + Address addr( "0xca4409573a5129a72edf85d6c51e26760fc9c903" ); + + bytes data = + jsToBytes( "0x11223344556600770000" ); + + u256 estimate = testClient + ->estimateGas( addr, 0, addr, data, 10000000, 1000000, + GasEstimationCallback() ) + .first; + + BOOST_CHECK_EQUAL( estimate, u256( 21000+7*16+3*4 ) ); +} + BOOST_AUTO_TEST_CASE( constantConsumption ) { TestClientFixture fixture( c_genesisInfoSkaleTest ); ClientTest* testClient = asClientTest( fixture.ethereum() ); @@ -475,7 +499,8 @@ BOOST_AUTO_TEST_CASE( constantConsumption ) { GasEstimationCallback() ) .first; - BOOST_CHECK_EQUAL( estimate, u256( 71800 ) ); + // 71488 checked in reall call under Istanbul fork + BOOST_CHECK_EQUAL( estimate, u256( 71488 ) ); } BOOST_AUTO_TEST_CASE( linearConsumption ) { @@ -513,7 +538,7 @@ BOOST_AUTO_TEST_CASE( linearConsumption ) { GasEstimationCallback() ) .first; - BOOST_CHECK_EQUAL( estimate, u256( 2367016 ) ); + BOOST_CHECK_EQUAL( estimate, u256( 2366934 ) ); } BOOST_AUTO_TEST_CASE( exceedsGasLimit ) { @@ -589,7 +614,7 @@ BOOST_AUTO_TEST_CASE( runsInterference ) { GasEstimationCallback() ) .first; - BOOST_CHECK_EQUAL( estimate, u256( 41684 ) ); + BOOST_CHECK_EQUAL( estimate, u256( 41424 ) ); } BOOST_AUTO_TEST_CASE( consumptionWithRefunds ) { @@ -810,7 +835,7 @@ BOOST_AUTO_TEST_CASE( consumptionWithReverts ) { GasEstimationCallback() ) .first; - BOOST_CHECK_EQUAL( estimate, u256( 121944 ) ); + BOOST_CHECK_EQUAL( estimate, u256( 121632 ) ); } BOOST_AUTO_TEST_SUITE_END() @@ -829,6 +854,7 @@ static std::string const c_genesisInfoSkaleIMABLSPublicKeyTest = std::string() + "byzantiumForkBlock": "0x00", "constantinopleForkBlock": "0x00", "constantinopleFixForkBlock": "0x00", + "istanbulForkBlock": "0x00", "networkID" : "12313219", "chainID": "0x01", "maximumExtraDataSize": "0x20", @@ -953,7 +979,11 @@ static std::string const c_skaleConfigString = R"E( "allowFutureBlocks": true, "homesteadForkBlock": "0x00", "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00" + "EIP158ForkBlock": "0x00", + "byzantiumForkBlock": "0x00", + "constantinopleForkBlock": "0x00", + "constantinopleFixForkBlock": "0x00", + "istanbulForkBlock": "0x00" }, "genesis": { "nonce": "0x0000000000000042", diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 1e5590e4a..2b2ab83ee 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -118,7 +118,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { chainParams.allowFutureBlocks = true; chainParams.difficulty = chainParams.minimumDifficulty; chainParams.gasLimit = chainParams.maxGasLimit; - chainParams.byzantiumForkBlock = 0; + chainParams.istanbulForkBlock = 0; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -908,7 +908,7 @@ BOOST_AUTO_TEST_CASE( transactionDropReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -965,7 +965,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue, // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -1022,7 +1022,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPrice // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -1085,7 +1085,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPriceReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); RLPStream stream1; tx1.streamRLP( stream1 ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index 597104bf2..ff0dfaeb4 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -396,9 +396,10 @@ std::string WebThreeStubClient::eth_sendTransaction( const Json::Value& param1 ) jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); } -std::string WebThreeStubClient::eth_estimateGas( const Json::Value& param1 ) { +std::string WebThreeStubClient::eth_estimateGas( const Json::Value& param1, const std::string& param2 ) { Json::Value p; p.append( param1 ); + p.append( param2 ); Json::Value result = this->CallMethod( "eth_estimateGas", p ); if ( result.isString() ) return result.asString(); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index d6acd634c..5f56db895 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -57,7 +57,7 @@ class WebThreeStubClient : public jsonrpc::Client { std::string eth_call( const Json::Value& param1, const std::string& param2 ) noexcept( false ); std::string eth_callEIP1898( const Json::Value& param1, const Json::Value& param2 ) noexcept( false ); bool eth_flush() noexcept( false ); - std::string eth_estimateGas( const Json::Value& param1 ) noexcept( false ); + std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "latest" ) noexcept( false ); Json::Value eth_getBlockByHash( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getBlockByNumber( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getTransactionByHash( const std::string& param1 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 1da3f94a9..a9d904d8d 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -78,6 +78,7 @@ static std::string const c_genesisConfigString = "EIP158ForkBlock": "0x00", "byzantiumForkBlock": "0x00", "constantinopleForkBlock": "0x00", + "istanbulForkBlock": "0x00", "skaleDisableChainIdCheck": true, "externalGasDifficulty": "0x1" }, @@ -280,6 +281,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { chainParams.byzantiumForkBlock = 0; chainParams.EIP158ForkBlock = 0; chainParams.constantinopleForkBlock = 0; + chainParams.istanbulForkBlock = 0; chainParams.externalGasDifficulty = 1; chainParams.sChain.contractStorageLimit = 128; // 615 + 1430 is experimentally-derived block size + average extras size @@ -1246,7 +1248,7 @@ BOOST_AUTO_TEST_CASE( eth_estimateGas ) { testPositive["to"] = "0xD2001300000000000000000000000000000000D4"; testPositive["data"] = "0xfdde8d66000000000000000000000000000000000000000000000000000000000000c350"; response = fixture.rpcClient->eth_estimateGas( testPositive ); - BOOST_CHECK( response == "0x1dc58" ); + BOOST_CHECK_EQUAL( response, "0x1db20" ); } BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_gasLimitExceeded ) { @@ -1536,6 +1538,46 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { responseString, "0x000000000000000000000000112233445566778899aabbccddeeff0011223344" ); } +BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { + JsonRpcFixture fixture; + dev::eth::simulateMining( *( fixture.client ), 1 ); + + auto senderAddress = fixture.coinbase.address(); + + Json::Value transact; + transact["from"] = toJS( senderAddress ); + transact["to"] = toJS( senderAddress ); + // 1k + ostringstream ss("0x"); + for(int i=0; i<1024/16; ++i) + ss << "112233445566778899aabbccddeeff11"; + transact["data"] = ss.str(); + + string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); + u256 gasEstimate = jsToU256(gasEstimateStr); + + BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*16)); + + u256 powGasPrice = 0; + do { + const u256 GAS_PER_HASH = 1; + u256 candidate = h256::random(); + h256 hash = dev::sha3( senderAddress ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); + u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; + if ( externalGas >= gasEstimate && externalGas < gasEstimate + gasEstimate/10 ) { + powGasPrice = candidate; + } + } while ( !powGasPrice ); + // Account balance is too low will mean that PoW didn't work out + transact["gasPrice"] = toJS( powGasPrice ); + + string txHash = fixture.rpcClient->eth_sendTransaction( transact ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); +} + BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); @@ -1579,22 +1621,26 @@ BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { string balanceString = fixture.rpcClient->eth_getBalance( toJS( address2 ), "latest" ); BOOST_REQUIRE_EQUAL( toJS( 0 ), balanceString ); + Json::Value transact; + transact["from"] = toJS( address2 ); + transact["to"] = contractAddress; + transact["data"] = "0x15b2eec30000000000000000000000000000000000000000000000000000000000000003"; + + string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); + u256 gasEstimate = jsToU256(gasEstimateStr); + u256 powGasPrice = 0; do { const u256 GAS_PER_HASH = 1; u256 candidate = h256::random(); h256 hash = dev::sha3( address2 ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; - if ( externalGas >= 21000 + 21000 ) { + if ( externalGas >= gasEstimate && externalGas < gasEstimate + gasEstimate/10 ) { powGasPrice = candidate; } } while ( !powGasPrice ); - - Json::Value transact; - transact["from"] = toJS( address2 ); - transact["to"] = contractAddress; transact["gasPrice"] = toJS( powGasPrice ); - transact["data"] = "0x15b2eec30000000000000000000000000000000000000000000000000000000000000003"; + fixture.rpcClient->eth_sendTransaction( transact ); dev::eth::mineTransaction( *( fixture.client ), 1 ); @@ -1848,7 +1894,8 @@ contract TestEstimateGas { txStore1["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000001"; txStore1["from"] = toJS( senderAddress ); txStore1["gasPrice"] = fixture.rpcClient->eth_gasPrice(); - string txHash = fixture.rpcClient->eth_call( txStore1, "latest" ); + fixture.rpcClient->eth_sendTransaction( txStore1 ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); Json::Value estimateGasCall; // call clear(0) estimateGasCall["to"] = contractAddress; @@ -1858,11 +1905,25 @@ contract TestEstimateGas { string estimatedGas = fixture.rpcClient->eth_estimateGas( estimateGasCall ); dev::bytes data = dev::jsToBytes( estimateGasCall["data"].asString() ); - BOOST_REQUIRE( dev::jsToU256( estimatedGas ) > dev::eth::TransactionBase::baseGasRequired( false, &data, fixture.client->chainParams().scheduleForBlockNumber( fixture.client->number() ) ) ); - BOOST_REQUIRE( dev::jsToU256( estimatedGas ) == 21871 ); + + // try to send with this gas + estimateGasCall["gas"] = toJS( jsToInt( estimatedGas ) ); + string clearHash = fixture.rpcClient->eth_sendTransaction( estimateGasCall ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + Json::Value clearReceipt = fixture.rpcClient->eth_getTransactionReceipt( clearHash ); + BOOST_REQUIRE_EQUAL(clearReceipt["status"], "0x1"); + BOOST_REQUIRE_LT(jsToInt(clearReceipt["gasUsed"].asString()), 21000); + + // try to lower gas + estimateGasCall["gas"] = toJS( jsToInt( estimatedGas ) - 1 ); + clearHash = fixture.rpcClient->eth_sendTransaction( estimateGasCall ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + clearReceipt = fixture.rpcClient->eth_getTransactionReceipt( clearHash ); + BOOST_REQUIRE_EQUAL(clearReceipt["status"], "0x0"); + BOOST_REQUIRE_GT(jsToInt(clearReceipt["gasUsed"].asString()), 21000); } BOOST_AUTO_TEST_CASE( storage_limit_contract ) { From 640b77b960285362531626e1327dece311b9f05d Mon Sep 17 00:00:00 2001 From: Oleh Date: Wed, 6 Dec 2023 18:56:22 +0000 Subject: [PATCH 077/159] #1199 add more exceptions --- libethereum/Client.cpp | 2 ++ libethereum/SkaleHost.cpp | 2 ++ libweb3jsonrpc/Eth.cpp | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 14ad8e367..61c897ec9 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1128,6 +1128,8 @@ Transactions Client::pending() const { } SyncStatus Client::syncStatus() const { + if ( !m_skaleHost ) + BOOST_THROW_EXCEPTION( std::runtime_error( "SkaleHost was not initialized" ) ); return m_skaleHost->syncStatus(); } diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 9ebea7d1a..0350fef51 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -943,6 +943,8 @@ u256 SkaleHost::getBlockRandom() const { } dev::eth::SyncStatus SkaleHost::syncStatus() const { + if ( !m_consensus ) + BOOST_THROW_EXCEPTION( std::runtime_error( "Consensus was not initialized" ) ); auto syncInfo = m_consensus->getSyncInfo(); dev::eth::SyncStatus syncStatus; // SKALE: catchup downloads blocks with transactions, then the node executes them diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 988022a29..5b75e1180 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -892,16 +892,22 @@ Json::Value Eth::eth_getWork() { } Json::Value Eth::eth_syncing() { - // ask consensus whether the node is in catchup mode - dev::eth::SyncStatus sync = client()->syncStatus(); - if ( !sync.majorSyncing ) - return Json::Value( false ); - - Json::Value info( Json::objectValue ); - info["startingBlock"] = sync.startBlockNumber; - info["highestBlock"] = sync.highestBlockNumber; - info["currentBlock"] = sync.currentBlockNumber; - return info; + try { + // ask consensus whether the node is in catchup mode + if ( !client() ) + BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) ); + dev::eth::SyncStatus sync = client()->syncStatus(); + if ( !sync.majorSyncing ) + return Json::Value( false ); + + Json::Value info( Json::objectValue ); + info["startingBlock"] = sync.startBlockNumber; + info["highestBlock"] = sync.highestBlockNumber; + info["currentBlock"] = sync.currentBlockNumber; + return info; + } catch ( const Exception& e ) { + BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( e.what() ) ); + } } string Eth::eth_chainId() { From b721cecde87c327c245b01e046bd48a044e41e6b Mon Sep 17 00:00:00 2001 From: Oleh Date: Wed, 6 Dec 2023 19:02:14 +0000 Subject: [PATCH 078/159] #1199 add more exceptions --- libweb3jsonrpc/Eth.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 5b75e1180..79bc92948 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -893,10 +893,12 @@ Json::Value Eth::eth_getWork() { Json::Value Eth::eth_syncing() { try { - // ask consensus whether the node is in catchup mode - if ( !client() ) + auto client = client(); + if ( !client ) BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) ); - dev::eth::SyncStatus sync = client()->syncStatus(); + + // ask consensus whether the node is in catchup mode + dev::eth::SyncStatus sync = client->syncStatus(); if ( !sync.majorSyncing ) return Json::Value( false ); From 35f4f655275b443daa03250370da63fbdc099c58 Mon Sep 17 00:00:00 2001 From: Oleh Date: Wed, 6 Dec 2023 19:05:37 +0000 Subject: [PATCH 079/159] #1199 format --- libweb3jsonrpc/Eth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 79bc92948..11cddf207 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -896,7 +896,7 @@ Json::Value Eth::eth_syncing() { auto client = client(); if ( !client ) BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) ); - + // ask consensus whether the node is in catchup mode dev::eth::SyncStatus sync = client->syncStatus(); if ( !sync.majorSyncing ) From 1af8e4d9527597d7a0c9e35d24797f2661c68cd9 Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 7 Dec 2023 10:13:48 +0000 Subject: [PATCH 080/159] #1199 fix build --- libweb3jsonrpc/Eth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 11cddf207..9686c5301 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -893,7 +893,7 @@ Json::Value Eth::eth_getWork() { Json::Value Eth::eth_syncing() { try { - auto client = client(); + auto client = this->client(); if ( !client ) BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) ); From 88bdc87df101e47fffcaf3f93f258ec127a09ae9 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 7 Dec 2023 18:02:50 +0000 Subject: [PATCH 081/159] SKALED-1600 Make 2nd parameter of estimateGas optional --- libweb3jsonrpc/EthFace.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 6bd085699..540f93baa 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -212,14 +212,12 @@ class EthFace : public ServerInterface< EthFace > { jsonrpc::JSON_OBJECT, NULL ), &dev::rpc::EthFace::eth_syncingI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_estimateGas", jsonrpc::PARAMS_BY_POSITION, - jsonrpc::JSON_STRING, "param1", jsonrpc::JSON_OBJECT, "param2", jsonrpc::JSON_STRING, NULL ), &dev::rpc::EthFace::eth_estimateGasI ); this->bindAndAddMethod( jsonrpc::Procedure( "eth_chainId", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ), &dev::rpc::EthFace::eth_chainIdI ); } - inline virtual void eth_protocolVersionI( const Json::Value& request, Json::Value& response ) { ( void ) request; response = this->eth_protocolVersion(); @@ -420,6 +418,9 @@ class EthFace : public ServerInterface< EthFace > { response = this->eth_syncing(); } inline virtual void eth_estimateGasI( const Json::Value& request, Json::Value& response ) { + if ( !request.isArray() || request.empty() ) + BOOST_THROW_EXCEPTION( + jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS ) ); response = this->eth_estimateGas( request[0u] ); } inline virtual void eth_chainIdI( const Json::Value& request, Json::Value& response ) { From d467308eacde3c9d4c7bbf92cb0c81f265e600ce Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 7 Dec 2023 18:26:33 +0000 Subject: [PATCH 082/159] SKALED-1600 Exclude changes related to external gas and add unit test for estimateGas parameters --- libethereum/Block.cpp | 5 ++- libethereum/Client.cpp | 4 +- libethereum/ClientBase.cpp | 3 +- libethereum/SkaleHost.cpp | 2 +- libethereum/Transaction.cpp | 9 ++-- libethereum/Transaction.h | 9 +--- test/tools/libtesteth/ImportTest.cpp | 2 +- test/unittests/libethereum/SkaleHost.cpp | 10 ++--- .../libweb3jsonrpc/WebThreeStubClient.cpp | 3 +- .../libweb3jsonrpc/WebThreeStubClient.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 44 ++----------------- 11 files changed, 25 insertions(+), 68 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index d98705d88..28e17ad0f 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -351,7 +351,7 @@ pair< TransactionReceipts, bool > Block::sync( // caller if we hit the limit for ( Transaction& transaction : transactions ) { - transaction.checkOutExternalGas( _bc.chainParams(), _bc.number() ); + transaction.checkOutExternalGas( _bc.chainParams().externalGasDifficulty ); } assert( _bc.currentHash() == m_currentBlock.parentHash() ); @@ -631,7 +631,8 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) { // << " (state #" // << state().getNonce( tr.from() ) << ") value = " << tr.value() << // endl; - const_cast< Transaction& >( tr ).checkOutExternalGas( _bc.chainParams(), _bc.number() ); + const_cast< Transaction& >( tr ).checkOutExternalGas( + _bc.chainParams().externalGasDifficulty ); execute( _bc.lastBlockHashes(), tr ); // cerr << "Now: " // << "State #" << state().getNonce( tr.from() ) << endl; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8543b821e..00c90351c 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1189,7 +1189,7 @@ h256 Client::importTransaction( Transaction const& _t ) { // the latest block in the client's blockchain. This can throw but // we'll catch the exception at the RPC level. - const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); + const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams().externalGasDifficulty ); // throws in case of error State state; @@ -1279,7 +1279,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.ignoreExternalGas(); + t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 35a031695..842556765 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -89,7 +89,7 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl t = Transaction( _value, _gasPrice, _gas, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainId() ); - t.ignoreExternalGas(); + t.checkOutExternalGas( ~u256( 0 ) ); EnvInfo const env( _latestBlock.info(), bc().lastBlockHashes(), 0, _gas ); // Make a copy of state!! It will be deleted after step! State tempState = _latestBlock.mutableState(); @@ -117,7 +117,6 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from upperBound = c_maxGasEstimate; int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ); - Block bk = latestBlock(); if ( upperBound > bk.info().gasLimit() ) { upperBound = bk.info().gasLimit().convert_to< int64_t >(); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index ba19ceb6e..0cbb4241f 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -665,7 +665,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // ).detach(); } else { Transaction t( data, CheckTransaction::Everything, true ); - t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); + 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" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 4e381df9d..1645c30c3 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -180,18 +180,17 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { - u256 const& difficulty = _cp.externalGasDifficulty; - assert( difficulty > 0 ); +void Transaction::checkOutExternalGas( u256 const& _difficulty ) { + assert( _difficulty > 0 ); if ( !m_externalGasIsChecked && !isInvalid() ) { h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); if ( !hash ) { hash = h256( 1 ); } - u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty; + u256 externalGas = ~u256( 0 ) / u256( hash ) / _difficulty; if ( externalGas > 0 ) ctrace << "Mined gas: " << externalGas << endl; - if ( externalGas >= baseGasRequired( _cp.scheduleForBlockNumber( _bn ) ) ) { + if ( externalGas >= baseGasRequired( ConstantinopleSchedule ) ) { m_externalGas = externalGas; } m_externalGasIsChecked = true; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 5cc8cf1eb..6764bce5a 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -29,8 +29,6 @@ #include #include -#include "ChainParams.h" - namespace dev { namespace eth { @@ -122,12 +120,7 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ); - - void ignoreExternalGas() { - m_externalGasIsChecked = true; - m_externalGas = 0; - } + void checkOutExternalGas( u256 const& _difficulty ); private: bool m_externalGasIsChecked = false; diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index 3b4df86c3..8400ed13c 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -225,7 +225,7 @@ bytes ImportTest::executeTest( bool _isFilling ) { continue; for ( auto& tr : m_transactions ) { -// tr.transaction.checkOutExternalGas( 100 ); + tr.transaction.checkOutExternalGas( 100 ); Options const& opt = Options::get(); if ( opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd ) continue; diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 2b2ab83ee..1e5590e4a 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -118,7 +118,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { chainParams.allowFutureBlocks = true; chainParams.difficulty = chainParams.minimumDifficulty; chainParams.gasLimit = chainParams.maxGasLimit; - chainParams.istanbulForkBlock = 0; + chainParams.byzantiumForkBlock = 0; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -908,7 +908,7 @@ BOOST_AUTO_TEST_CASE( transactionDropReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -965,7 +965,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue, // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -1022,7 +1022,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPrice // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -1085,7 +1085,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPriceReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); RLPStream stream1; tx1.streamRLP( stream1 ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index ff0dfaeb4..acdebbf42 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -399,7 +399,8 @@ std::string WebThreeStubClient::eth_sendTransaction( const Json::Value& param1 ) std::string WebThreeStubClient::eth_estimateGas( const Json::Value& param1, const std::string& param2 ) { Json::Value p; p.append( param1 ); - p.append( param2 ); + if(!param2.empty()) + p.append( param2 ); Json::Value result = this->CallMethod( "eth_estimateGas", p ); if ( result.isString() ) return result.asString(); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index 5f56db895..a97f41d25 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -57,7 +57,7 @@ class WebThreeStubClient : public jsonrpc::Client { std::string eth_call( const Json::Value& param1, const std::string& param2 ) noexcept( false ); std::string eth_callEIP1898( const Json::Value& param1, const Json::Value& param2 ) noexcept( false ); bool eth_flush() noexcept( false ); - std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "latest" ) noexcept( false ); + std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "" ) noexcept( false ); Json::Value eth_getBlockByHash( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getBlockByNumber( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getTransactionByHash( const std::string& param1 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index a9d904d8d..c98c9c205 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1248,7 +1248,11 @@ BOOST_AUTO_TEST_CASE( eth_estimateGas ) { testPositive["to"] = "0xD2001300000000000000000000000000000000D4"; testPositive["data"] = "0xfdde8d66000000000000000000000000000000000000000000000000000000000000c350"; response = fixture.rpcClient->eth_estimateGas( testPositive ); + string response2 = fixture.rpcClient->eth_estimateGas( testPositive, "latest" ); + string response3 = fixture.rpcClient->eth_estimateGas( testPositive, "1" ); BOOST_CHECK_EQUAL( response, "0x1db20" ); + BOOST_CHECK_EQUAL( response2, "0x1db20" ); + BOOST_CHECK_EQUAL( response3, "0x1db20" ); } BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_gasLimitExceeded ) { @@ -1538,46 +1542,6 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { responseString, "0x000000000000000000000000112233445566778899aabbccddeeff0011223344" ); } -BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { - JsonRpcFixture fixture; - dev::eth::simulateMining( *( fixture.client ), 1 ); - - auto senderAddress = fixture.coinbase.address(); - - Json::Value transact; - transact["from"] = toJS( senderAddress ); - transact["to"] = toJS( senderAddress ); - // 1k - ostringstream ss("0x"); - for(int i=0; i<1024/16; ++i) - ss << "112233445566778899aabbccddeeff11"; - transact["data"] = ss.str(); - - string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); - u256 gasEstimate = jsToU256(gasEstimateStr); - - BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*16)); - - u256 powGasPrice = 0; - do { - const u256 GAS_PER_HASH = 1; - u256 candidate = h256::random(); - h256 hash = dev::sha3( senderAddress ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); - u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; - if ( externalGas >= gasEstimate && externalGas < gasEstimate + gasEstimate/10 ) { - powGasPrice = candidate; - } - } while ( !powGasPrice ); - // Account balance is too low will mean that PoW didn't work out - transact["gasPrice"] = toJS( powGasPrice ); - - string txHash = fixture.rpcClient->eth_sendTransaction( transact ); - dev::eth::mineTransaction( *( fixture.client ), 1 ); - - Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); -} - BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); From 1a962d8055d43386c584729c635a59eac5333661 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 7 Dec 2023 18:30:48 +0000 Subject: [PATCH 083/159] SKALED-1600 Formatting --- libweb3jsonrpc/EthFace.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libweb3jsonrpc/EthFace.h b/libweb3jsonrpc/EthFace.h index 540f93baa..b7bafedd3 100644 --- a/libweb3jsonrpc/EthFace.h +++ b/libweb3jsonrpc/EthFace.h @@ -218,6 +218,7 @@ class EthFace : public ServerInterface< EthFace > { jsonrpc::JSON_STRING, NULL ), &dev::rpc::EthFace::eth_chainIdI ); } + inline virtual void eth_protocolVersionI( const Json::Value& request, Json::Value& response ) { ( void ) request; response = this->eth_protocolVersion(); From 0fd8783a20360c8af2bb4ca62a5129569f926c56 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 12 Dec 2023 12:36:11 +0000 Subject: [PATCH 084/159] IS 779 add logs --- libethereum/Client.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 61c897ec9..87c4be0b3 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1411,11 +1411,30 @@ const dev::h256 Client::empty_str_hash = #ifdef HISTORIC_STATE u256 Client::historicStateBalanceAt( Address _a, BlockNumber _block ) const { + boost::chrono::high_resolution_clock::time_point t1; + boost::chrono::high_resolution_clock::time_point t2; + + t1 = boost::chrono::high_resolution_clock::now(); auto block = blockByNumber( _block ); + t2 = boost::chrono::high_resolution_clock::now(); + auto blockByNumberTimeMs = + boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); + std::cout << "BLOCK BY NUMBER MS: " << blockByNumberTimeMs << '\n'; + t1 = boost::chrono::high_resolution_clock::now(); auto aState = block.mutableState().mutableHistoricState(); - - return aState.balance( _a ); + t2 = boost::chrono::high_resolution_clock::now(); + auto mutableHistoricStateMs = + boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); + std::cout << "MUTABLE HISTORIC STATE MS: " << mutableHistoricStateMs << '\n'; + + t1 = boost::chrono::high_resolution_clock::now(); + auto retVal = aState.balance( _a ); + t2 = boost::chrono::high_resolution_clock::now(); + auto balanceMs = boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); + std::cout << "BALANCE MS: " << balanceMs << '\n'; + + return retVal; } u256 Client::historicStateCountAt( Address _a, BlockNumber _block ) const { From 26118bf00d786b10ef5d3c01b18d2043a990c83b Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 12 Dec 2023 16:17:56 +0000 Subject: [PATCH 085/159] Revert "SKALED-1600 Exclude changes related to external gas and add unit test for estimateGas parameters" This reverts commit d467308eacde3c9d4c7bbf92cb0c81f265e600ce. --- libethereum/Block.cpp | 5 +-- libethereum/Client.cpp | 4 +- libethereum/ClientBase.cpp | 3 +- libethereum/SkaleHost.cpp | 2 +- libethereum/Transaction.cpp | 9 ++-- libethereum/Transaction.h | 9 +++- test/tools/libtesteth/ImportTest.cpp | 2 +- test/unittests/libethereum/SkaleHost.cpp | 10 ++--- .../libweb3jsonrpc/WebThreeStubClient.cpp | 3 +- .../libweb3jsonrpc/WebThreeStubClient.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 44 +++++++++++++++++-- 11 files changed, 68 insertions(+), 25 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index 28e17ad0f..d98705d88 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -351,7 +351,7 @@ pair< TransactionReceipts, bool > Block::sync( // caller if we hit the limit for ( Transaction& transaction : transactions ) { - transaction.checkOutExternalGas( _bc.chainParams().externalGasDifficulty ); + transaction.checkOutExternalGas( _bc.chainParams(), _bc.number() ); } assert( _bc.currentHash() == m_currentBlock.parentHash() ); @@ -631,8 +631,7 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) { // << " (state #" // << state().getNonce( tr.from() ) << ") value = " << tr.value() << // endl; - const_cast< Transaction& >( tr ).checkOutExternalGas( - _bc.chainParams().externalGasDifficulty ); + const_cast< Transaction& >( tr ).checkOutExternalGas( _bc.chainParams(), _bc.number() ); execute( _bc.lastBlockHashes(), tr ); // cerr << "Now: " // << "State #" << state().getNonce( tr.from() ) << endl; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 61c897ec9..704a97fbe 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1188,7 +1188,7 @@ h256 Client::importTransaction( Transaction const& _t ) { // the latest block in the client's blockchain. This can throw but // we'll catch the exception at the RPC level. - const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams().externalGasDifficulty ); + const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); // throws in case of error State state; @@ -1278,7 +1278,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.checkOutExternalGas( ~u256( 0 ) ); + t.ignoreExternalGas(); if ( _ff == FudgeFactor::Lenient ) temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 842556765..35a031695 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -89,7 +89,7 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl t = Transaction( _value, _gasPrice, _gas, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainId() ); - t.checkOutExternalGas( ~u256( 0 ) ); + t.ignoreExternalGas(); EnvInfo const env( _latestBlock.info(), bc().lastBlockHashes(), 0, _gas ); // Make a copy of state!! It will be deleted after step! State tempState = _latestBlock.mutableState(); @@ -117,6 +117,7 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from upperBound = c_maxGasEstimate; int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ); + Block bk = latestBlock(); if ( upperBound > bk.info().gasLimit() ) { upperBound = bk.info().gasLimit().convert_to< int64_t >(); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 0350fef51..4dd42ace4 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -665,7 +665,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // ).detach(); } else { Transaction t( data, CheckTransaction::Everything, true ); - t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty ); + t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Will import consensus-born txn!"; m_debugTracer.tracepoint( "import_consensus_born" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 1645c30c3..4e381df9d 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -180,17 +180,18 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( u256 const& _difficulty ) { - assert( _difficulty > 0 ); +void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { + u256 const& difficulty = _cp.externalGasDifficulty; + assert( difficulty > 0 ); if ( !m_externalGasIsChecked && !isInvalid() ) { h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); if ( !hash ) { hash = h256( 1 ); } - u256 externalGas = ~u256( 0 ) / u256( hash ) / _difficulty; + u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty; if ( externalGas > 0 ) ctrace << "Mined gas: " << externalGas << endl; - if ( externalGas >= baseGasRequired( ConstantinopleSchedule ) ) { + if ( externalGas >= baseGasRequired( _cp.scheduleForBlockNumber( _bn ) ) ) { m_externalGas = externalGas; } m_externalGasIsChecked = true; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 6764bce5a..5cc8cf1eb 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -29,6 +29,8 @@ #include #include +#include "ChainParams.h" + namespace dev { namespace eth { @@ -120,7 +122,12 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( u256 const& _difficulty ); + void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ); + + void ignoreExternalGas() { + m_externalGasIsChecked = true; + m_externalGas = 0; + } private: bool m_externalGasIsChecked = false; diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index 8400ed13c..3b4df86c3 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -225,7 +225,7 @@ bytes ImportTest::executeTest( bool _isFilling ) { continue; for ( auto& tr : m_transactions ) { - tr.transaction.checkOutExternalGas( 100 ); +// tr.transaction.checkOutExternalGas( 100 ); Options const& opt = Options::get(); if ( opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd ) continue; diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 7870cd7c9..84243ab98 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -123,7 +123,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { chainParams.allowFutureBlocks = true; chainParams.difficulty = chainParams.minimumDifficulty; chainParams.gasLimit = chainParams.maxGasLimit; - chainParams.byzantiumForkBlock = 0; + chainParams.istanbulForkBlock = 0; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -913,7 +913,7 @@ BOOST_AUTO_TEST_CASE( transactionDropReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -970,7 +970,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue, // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -1027,7 +1027,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPrice // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); // submit it! tq->import( tx1 ); @@ -1090,7 +1090,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPriceReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams().difficulty ); + tx1.checkOutExternalGas( client->chainParams(), client->number() ); RLPStream stream1; tx1.streamRLP( stream1 ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index acdebbf42..ff0dfaeb4 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -399,8 +399,7 @@ std::string WebThreeStubClient::eth_sendTransaction( const Json::Value& param1 ) std::string WebThreeStubClient::eth_estimateGas( const Json::Value& param1, const std::string& param2 ) { Json::Value p; p.append( param1 ); - if(!param2.empty()) - p.append( param2 ); + p.append( param2 ); Json::Value result = this->CallMethod( "eth_estimateGas", p ); if ( result.isString() ) return result.asString(); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index a97f41d25..5f56db895 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -57,7 +57,7 @@ class WebThreeStubClient : public jsonrpc::Client { std::string eth_call( const Json::Value& param1, const std::string& param2 ) noexcept( false ); std::string eth_callEIP1898( const Json::Value& param1, const Json::Value& param2 ) noexcept( false ); bool eth_flush() noexcept( false ); - std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "" ) noexcept( false ); + std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "latest" ) noexcept( false ); Json::Value eth_getBlockByHash( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getBlockByNumber( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getTransactionByHash( const std::string& param1 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 28ece1a25..ddd1a23ae 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1265,11 +1265,7 @@ BOOST_AUTO_TEST_CASE( eth_estimateGas ) { testPositive["to"] = "0xD2001300000000000000000000000000000000D4"; testPositive["data"] = "0xfdde8d66000000000000000000000000000000000000000000000000000000000000c350"; response = fixture.rpcClient->eth_estimateGas( testPositive ); - string response2 = fixture.rpcClient->eth_estimateGas( testPositive, "latest" ); - string response3 = fixture.rpcClient->eth_estimateGas( testPositive, "1" ); BOOST_CHECK_EQUAL( response, "0x1db20" ); - BOOST_CHECK_EQUAL( response2, "0x1db20" ); - BOOST_CHECK_EQUAL( response3, "0x1db20" ); } BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_gasLimitExceeded ) { @@ -1559,6 +1555,46 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { responseString, "0x000000000000000000000000112233445566778899aabbccddeeff0011223344" ); } +BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { + JsonRpcFixture fixture; + dev::eth::simulateMining( *( fixture.client ), 1 ); + + auto senderAddress = fixture.coinbase.address(); + + Json::Value transact; + transact["from"] = toJS( senderAddress ); + transact["to"] = toJS( senderAddress ); + // 1k + ostringstream ss("0x"); + for(int i=0; i<1024/16; ++i) + ss << "112233445566778899aabbccddeeff11"; + transact["data"] = ss.str(); + + string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); + u256 gasEstimate = jsToU256(gasEstimateStr); + + BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*16)); + + u256 powGasPrice = 0; + do { + const u256 GAS_PER_HASH = 1; + u256 candidate = h256::random(); + h256 hash = dev::sha3( senderAddress ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); + u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; + if ( externalGas >= gasEstimate && externalGas < gasEstimate + gasEstimate/10 ) { + powGasPrice = candidate; + } + } while ( !powGasPrice ); + // Account balance is too low will mean that PoW didn't work out + transact["gasPrice"] = toJS( powGasPrice ); + + string txHash = fixture.rpcClient->eth_sendTransaction( transact ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); +} + BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); From 9d5b16c2578bf2832b0d68ac220001ba5a89c468 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 12 Dec 2023 17:43:26 +0000 Subject: [PATCH 086/159] SKALED-1745 Initial implementation of correct fork in external gsa --- test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp | 3 ++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index ff0dfaeb4..acdebbf42 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -399,7 +399,8 @@ std::string WebThreeStubClient::eth_sendTransaction( const Json::Value& param1 ) std::string WebThreeStubClient::eth_estimateGas( const Json::Value& param1, const std::string& param2 ) { Json::Value p; p.append( param1 ); - p.append( param2 ); + if(!param2.empty()) + p.append( param2 ); Json::Value result = this->CallMethod( "eth_estimateGas", p ); if ( result.isString() ) return result.asString(); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index ddd1a23ae..d0a9f9083 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1265,7 +1265,11 @@ BOOST_AUTO_TEST_CASE( eth_estimateGas ) { testPositive["to"] = "0xD2001300000000000000000000000000000000D4"; testPositive["data"] = "0xfdde8d66000000000000000000000000000000000000000000000000000000000000c350"; response = fixture.rpcClient->eth_estimateGas( testPositive ); + string response2 = fixture.rpcClient->eth_estimateGas( testPositive, "latest" ); + string response3 = fixture.rpcClient->eth_estimateGas( testPositive, "1" ); BOOST_CHECK_EQUAL( response, "0x1db20" ); + BOOST_CHECK_EQUAL( response2, "0x1db20" ); + BOOST_CHECK_EQUAL( response3, "0x1db20" ); } BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_gasLimitExceeded ) { From 430e686c6d25f66a6192d1708ef150ccd175ce73 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 13 Dec 2023 16:05:50 +0000 Subject: [PATCH 087/159] 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 3bf2015c4..ba6c74064 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -127,6 +127,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 0ef884262..1fa2a6a9d 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -314,3 +314,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 f5337001d..6d85b9d7d 100644 --- a/libweb3jsonrpc/Debug.h +++ b/libweb3jsonrpc/Debug.h @@ -60,6 +60,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 const& m_eth; SkaleDebugInterface* m_debugInterface = nullptr; diff --git a/libweb3jsonrpc/DebugFace.h b/libweb3jsonrpc/DebugFace.h index ebcc07fe2..ade7094b0 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( @@ -206,6 +214,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 d387c774bbe949d357d833ce16461e0d4e51ea35 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 13 Dec 2023 18:08:34 +0000 Subject: [PATCH 088/159] #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 089/159] #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 e7259307b949a5b197b24003c261a286447083c5 Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 14 Dec 2023 16:43:08 +0000 Subject: [PATCH 090/159] Reload rotation timestamp in isTimeToRotate --- libethereum/InstanceMonitor.cpp | 15 ++++++--------- libethereum/InstanceMonitor.h | 9 ++------- .../unittests/libethereum/InstanceMonitorTest.cpp | 9 ++++----- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index e2a6585db..b94a74bdc 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -46,23 +46,20 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); rotationInfoFile << rotationJson; - m_finishTimestamp = _finishTimestamp; - LOG( m_logger ) << "Set rotation time to " << m_finishTimestamp; + LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; } bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { if ( !fs::exists( m_rotationInfoFilePath ) ) { return false; } - return m_finishTimestamp <= _finishTimestamp; + return getRotationTimestamp() <= _finishTimestamp; } -void InstanceMonitor::restoreRotationParams() { - if ( fs::exists( m_rotationInfoFilePath ) ) { - std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); - auto rotationJson = nlohmann::json::parse( rotationInfoFile ); - m_finishTimestamp = rotationJson["timestamp"].get< uint64_t >(); - } +uint64_t InstanceMonitor::getRotationTimestamp() { + std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); + auto rotationJson = nlohmann::json::parse( rotationInfoFile ); + return rotationJson["timestamp"].get< uint64_t >(); } void InstanceMonitor::reportExitTimeReached( bool _reached ) { diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 84867ddcc..621e94f23 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -36,23 +36,18 @@ class InstanceMonitor { public: explicit InstanceMonitor( const boost::filesystem::path& _rotationInfoFileDirPath, std::shared_ptr< StatusAndControl > _statusAndControl = nullptr ) - : m_finishTimestamp( 0 ), - m_rotationInfoFilePath( _rotationInfoFileDirPath / rotation_info_file_name ), + : m_rotationInfoFilePath( _rotationInfoFileDirPath / rotation_info_file_name ), m_statusAndControl( _statusAndControl ) { - restoreRotationParams(); reportExitTimeReached( false ); } void prepareRotation(); void initRotationParams( uint64_t _finishTimestamp ); bool isTimeToRotate( uint64_t _finishTimestamp ); + uint64_t getRotationTimestamp(); protected: - void restoreRotationParams(); - [[nodiscard]] uint64_t finishTimestamp() const { return m_finishTimestamp; } - [[nodiscard]] fs::path rotationInfoFilePath() const { return m_rotationInfoFilePath; } - uint64_t m_finishTimestamp; const fs::path m_rotationInfoFilePath; std::shared_ptr< StatusAndControl > m_statusAndControl; diff --git a/test/unittests/libethereum/InstanceMonitorTest.cpp b/test/unittests/libethereum/InstanceMonitorTest.cpp index 760cf3f58..9a4cd50e5 100644 --- a/test/unittests/libethereum/InstanceMonitorTest.cpp +++ b/test/unittests/libethereum/InstanceMonitorTest.cpp @@ -17,10 +17,6 @@ class InstanceMonitorMock: public InstanceMonitor { public: explicit InstanceMonitorMock(fs::path const &rotationFlagFilePath, std::shared_ptr statusAndControl) : InstanceMonitor(rotationFlagFilePath, statusAndControl) {}; - uint64_t getFinishTimestamp() { - return this->finishTimestamp(); - }; - fs::path getRotationInfoFilePath() { return this->rotationInfoFilePath(); } @@ -70,7 +66,7 @@ BOOST_AUTO_TEST_CASE( test_initRotationParams ) { uint64_t ts = 100; BOOST_REQUIRE( !fs::exists(instanceMonitor->getRotationInfoFilePath() ) ); instanceMonitor->initRotationParams(ts); - BOOST_CHECK_EQUAL(instanceMonitor->getFinishTimestamp(), ts); + BOOST_CHECK_EQUAL(instanceMonitor->getRotationTimestamp(), ts); BOOST_REQUIRE( fs::exists(instanceMonitor->getRotationInfoFilePath() ) ); @@ -98,6 +94,9 @@ BOOST_AUTO_TEST_CASE( test_isTimeToRotate_true ) { instanceMonitor->initRotationParams(50); BOOST_REQUIRE( instanceMonitor->isTimeToRotate( currentTime ) ); + + currentTime = 49; + BOOST_REQUIRE( !instanceMonitor->isTimeToRotate( currentTime ) ); } BOOST_AUTO_TEST_CASE( test_rotation ) { From a3d1389f807b8eaa2335cc6bb9732d99e7672e95 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 14 Dec 2023 16:58:58 +0000 Subject: [PATCH 091/159] IS 779 remove mutex --- libethereum/Client.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 87c4be0b3..f3d4189ce 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1095,7 +1095,9 @@ Block Client::blockByNumber( BlockNumber _h ) const { auto readState = m_state.createStateReadOnlyCopy(); readState.mutableHistoricState().setRootByBlockNumber( _h ); - DEV_GUARDED( m_blockImportMutex ) { return Block( bc(), hash, readState ); } + // removed m_blockImportMutex here + // this function doesn't interact with latest block so the mutex isn't needed + return Block( bc(), hash, readState ); assert( false ); return Block( bc() ); } catch ( Exception& ex ) { From b483366577f2887636b1f8ae41a87aceebe3b29f Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 14 Dec 2023 17:43:49 +0000 Subject: [PATCH 092/159] #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 093/159] #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 094/159] #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 095/159] #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 5d8a88d6b6237e0e2862d15a322f4dbed83f612c Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 14 Dec 2023 21:50:11 +0000 Subject: [PATCH 096/159] Rename getRotationTimestamp -> rotationTimestamp --- libethereum/InstanceMonitor.cpp | 4 ++-- libethereum/InstanceMonitor.h | 2 +- test/unittests/libethereum/InstanceMonitorTest.cpp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index b94a74bdc..b101c1876 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -53,10 +53,10 @@ bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { if ( !fs::exists( m_rotationInfoFilePath ) ) { return false; } - return getRotationTimestamp() <= _finishTimestamp; + return rotationTimestamp() <= _finishTimestamp; } -uint64_t InstanceMonitor::getRotationTimestamp() { +uint64_t InstanceMonitor::rotationTimestamp() const { std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); auto rotationJson = nlohmann::json::parse( rotationInfoFile ); return rotationJson["timestamp"].get< uint64_t >(); diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 621e94f23..8e6b23ab3 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -43,9 +43,9 @@ class InstanceMonitor { void prepareRotation(); void initRotationParams( uint64_t _finishTimestamp ); bool isTimeToRotate( uint64_t _finishTimestamp ); - uint64_t getRotationTimestamp(); protected: + [[nodiscard]] uint64_t rotationTimestamp() const; [[nodiscard]] fs::path rotationInfoFilePath() const { return m_rotationInfoFilePath; } const fs::path m_rotationInfoFilePath; diff --git a/test/unittests/libethereum/InstanceMonitorTest.cpp b/test/unittests/libethereum/InstanceMonitorTest.cpp index 9a4cd50e5..bd1ebee0e 100644 --- a/test/unittests/libethereum/InstanceMonitorTest.cpp +++ b/test/unittests/libethereum/InstanceMonitorTest.cpp @@ -28,6 +28,10 @@ class InstanceMonitorMock: public InstanceMonitor { void removeFlagFileTest(){ this->reportExitTimeReached( false ); } + + uint64_t getRotationTimestamp() const { + return this->rotationTimestamp(); + } }; class InstanceMonitorTestFixture : public TestOutputHelperFixture { From 4940f263d2ffc157dfed24fe106bc59f0ce008f8 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 15 Dec 2023 13:07:07 +0000 Subject: [PATCH 097/159] IS 779 remove debug logs --- libethereum/Client.cpp | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index f3d4189ce..8bf8af377 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1413,30 +1413,11 @@ const dev::h256 Client::empty_str_hash = #ifdef HISTORIC_STATE u256 Client::historicStateBalanceAt( Address _a, BlockNumber _block ) const { - boost::chrono::high_resolution_clock::time_point t1; - boost::chrono::high_resolution_clock::time_point t2; - - t1 = boost::chrono::high_resolution_clock::now(); auto block = blockByNumber( _block ); - t2 = boost::chrono::high_resolution_clock::now(); - auto blockByNumberTimeMs = - boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); - std::cout << "BLOCK BY NUMBER MS: " << blockByNumberTimeMs << '\n'; - t1 = boost::chrono::high_resolution_clock::now(); auto aState = block.mutableState().mutableHistoricState(); - t2 = boost::chrono::high_resolution_clock::now(); - auto mutableHistoricStateMs = - boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); - std::cout << "MUTABLE HISTORIC STATE MS: " << mutableHistoricStateMs << '\n'; - - t1 = boost::chrono::high_resolution_clock::now(); - auto retVal = aState.balance( _a ); - t2 = boost::chrono::high_resolution_clock::now(); - auto balanceMs = boost::chrono::duration_cast< boost::chrono::milliseconds >( t2 - t1 ).count(); - std::cout << "BALANCE MS: " << balanceMs << '\n'; - - return retVal; + + return aState.balance( _a ); } u256 Client::historicStateCountAt( Address _a, BlockNumber _block ) const { From 778a37db28b94b7dca23b9dc4e202c0b04df6a63 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 15 Dec 2023 16:17:55 +0000 Subject: [PATCH 098/159] Not finished CorrectForkInPowPatch --- libskale/CorrectForkInPowPatch.cpp | 11 +++++++++++ libskale/CorrectForkInPowPatch.h | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 libskale/CorrectForkInPowPatch.cpp create mode 100644 libskale/CorrectForkInPowPatch.h diff --git a/libskale/CorrectForkInPowPatch.cpp b/libskale/CorrectForkInPowPatch.cpp new file mode 100644 index 000000000..2d5df7442 --- /dev/null +++ b/libskale/CorrectForkInPowPatch.cpp @@ -0,0 +1,11 @@ +#include "CorrectForkInPowPatch.h" + +time_t CorrectForkInPowPatch::activationTimestamp; +time_t CorrectForkInPowPatch::lastBlockTimestamp; + +bool CorrectForkInPowPatch::isEnabled() { + if ( activationTimestamp == 0 ) { + return false; + } + return activationTimestamp <= lastBlockTimestamp; +} diff --git a/libskale/CorrectForkInPowPatch.h b/libskale/CorrectForkInPowPatch.h new file mode 100644 index 000000000..513c85840 --- /dev/null +++ b/libskale/CorrectForkInPowPatch.h @@ -0,0 +1,25 @@ +#ifndef CORRECTFORKINPOWPATCH_H +#define CORRECTFORKINPOWPATCH_H + +#include + +#include + +/* + * Context: use current, and not Constantinople, fork in Transaction::checkOutExternalGas() + */ +class CorrectForkInPowPatch : public SchainPatch { +public: + static bool isEnabled(); + + static void setTimestamp( time_t _timeStamp ) { + printInfo( __FILE__, _timeStamp ); + activationTimestamp = _timeStamp; + } + +private: + static time_t activationTimestamp; + static time_t lastBlockTimestamp; +}; + +#endif // CORRECTFORKINPOWPATCH_H From c1ea3cd244b554c5cf2535b6d082251182a6dabb Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 15 Dec 2023 20:04:03 +0000 Subject: [PATCH 099/159] SKALED-1745 Add CorrectForkInPowPatch --- libethcore/ChainOperationParams.h | 1 + libethereum/ChainParams.cpp | 5 +++++ libethereum/Client.cpp | 2 ++ libethereum/ValidationSchemes.cpp | 2 ++ libskale/CMakeLists.txt | 2 ++ 5 files changed, 12 insertions(+) diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 3e442229d..678619900 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -178,6 +178,7 @@ struct SChain { time_t precompiledConfigPatchTimestamp = 0; time_t pushZeroPatchTimestamp = 0; time_t skipInvalidTransactionsPatchTimestamp = 0; + time_t correctForkInPowPatchTimestamp = 0; SChain() { name = "TestChain"; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index fec3da5a5..52d3fade1 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -280,6 +280,11 @@ ChainParams ChainParams::loadConfig( sChainObj.at( "skipInvalidTransactionsPatchTimestamp" ).get_int64() : 0; + s.correctForkInPowPatchTimestamp = + sChainObj.count( "correctForkInPowPatchTimestamp" ) ? + sChainObj.at( "correctForkInPowPatchTimestamp" ).get_int64() : + 0; + if ( sChainObj.count( "nodeGroups" ) ) { std::vector< NodeGroup > nodeGroups; for ( const auto& nodeGroupConf : sChainObj["nodeGroups"].get_obj() ) { diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 704a97fbe..8a031864f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -169,6 +170,7 @@ Client::Client( ChainParams const& _params, int _networkID, SkipInvalidTransactionsPatch::setTimestamp( this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp ); PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp ); + CorrectForkInPowPatch::setTimestamp( chainParams().sChain.correctForkInPowPatchTimestamp ); } diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index 75bd07af1..1f7243e31 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -274,6 +274,8 @@ void validateConfigJson( js::mObject const& _obj ) { { "skipInvalidTransactionsPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "precompiledConfigPatchTimestamp", + { { js::int_type }, JsonFieldPresence::Optional } }, + { "correctForkInPowPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } } } ); js::mArray const& nodes = sChain.at( "nodes" ).get_array(); diff --git a/libskale/CMakeLists.txt b/libskale/CMakeLists.txt index aec50d6e0..1a0fb8ff1 100644 --- a/libskale/CMakeLists.txt +++ b/libskale/CMakeLists.txt @@ -23,6 +23,7 @@ set(sources PrecompiledConfigPatch.cpp PushZeroPatch.cpp SkipInvalidTransactionsPatch.cpp + CorrectForkInPowPatch.cpp ) set(headers @@ -44,6 +45,7 @@ set(headers PrecompiledConfigPatch.h OverlayFS.h SkipInvalidTransactionsPatch.h + CorrectForkInPowPatch.h ) add_library(skale ${sources} ${headers}) From 76b963c80ba9e34442a4d753c82033c1801fab76 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Mon, 18 Dec 2023 20:06:33 +0000 Subject: [PATCH 100/159] #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 101/159] #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 102/159] #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 9a54941ed398d1d900017e63bcd2526cbd240707 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 11:55:51 +0000 Subject: [PATCH 103/159] SKALED-1745 Patch --- libethereum/Client.cpp | 3 +++ libethereum/Transaction.cpp | 13 +++++++++++-- libskale/CorrectForkInPowPatch.cpp | 1 + libskale/CorrectForkInPowPatch.h | 10 ++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8a031864f..230450f6a 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -670,6 +670,9 @@ size_t Client::syncTransactions( PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp(); SkipInvalidTransactionsPatch::lastBlockTimestamp = blockChain().info().timestamp(); PrecompiledConfigPatch::lastBlockTimestamp = blockChain().info().timestamp(); + CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp(); + CorrectForkInPowPatch::lastBlockNumber = blockChain().number(); + DEV_WRITE_GUARDED( x_working ) { assert( !m_working.isSealed() ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 4e381df9d..2d73ec229 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace std; using namespace dev; @@ -191,9 +192,17 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty; if ( externalGas > 0 ) ctrace << "Mined gas: " << externalGas << endl; - if ( externalGas >= baseGasRequired( _cp.scheduleForBlockNumber( _bn ) ) ) { + + EVMSchedule scheduleForUse = ConstantinopleSchedule; + if ( CorrectForkInPowPatch::isEnabled() ) + scheduleForUse = _cp.scheduleForBlockNumber( _bn ); + + // !! never call checkOutExternalGas with non-last block! + assert( _bn == CorrectForkInPowPatch::getLastBlockNumber() ); + + if ( externalGas >= baseGasRequired( scheduleForUse ) ) m_externalGas = externalGas; - } + m_externalGasIsChecked = true; } } diff --git a/libskale/CorrectForkInPowPatch.cpp b/libskale/CorrectForkInPowPatch.cpp index 2d5df7442..aec18bc29 100644 --- a/libskale/CorrectForkInPowPatch.cpp +++ b/libskale/CorrectForkInPowPatch.cpp @@ -2,6 +2,7 @@ time_t CorrectForkInPowPatch::activationTimestamp; time_t CorrectForkInPowPatch::lastBlockTimestamp; +unsigned CorrectForkInPowPatch::lastBlockNumber; bool CorrectForkInPowPatch::isEnabled() { if ( activationTimestamp == 0 ) { diff --git a/libskale/CorrectForkInPowPatch.h b/libskale/CorrectForkInPowPatch.h index 513c85840..243e49999 100644 --- a/libskale/CorrectForkInPowPatch.h +++ b/libskale/CorrectForkInPowPatch.h @@ -5,6 +5,12 @@ #include +namespace dev { +namespace eth { +class Client; +} +} // namespace dev + /* * Context: use current, and not Constantinople, fork in Transaction::checkOutExternalGas() */ @@ -17,9 +23,13 @@ class CorrectForkInPowPatch : public SchainPatch { activationTimestamp = _timeStamp; } + static unsigned getLastBlockNumber() { return lastBlockNumber; } + private: + friend class dev::eth::Client; static time_t activationTimestamp; static time_t lastBlockTimestamp; + static unsigned lastBlockNumber; }; #endif // CORRECTFORKINPOWPATCH_H From fb82296e764242745dd285effa8aa5433b928f6b Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 16:42:55 +0000 Subject: [PATCH 104/159] SKALED-1745 Patch for correct fork in PoW --- libethereum/Client.cpp | 10 ++++++++-- libethereum/Transaction.cpp | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 230450f6a..822572bcd 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -602,6 +602,10 @@ size_t Client::importTransactionsAsBlock( sealUnconditionally( false ); importWorkingBlock(); + // this needs to be updated as soon as possible, as it's used in new transactions validation + CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp(); + CorrectForkInPowPatch::lastBlockNumber = blockChain().number(); + if ( !UnsafeRegion::isActive() ) { LOG( m_loggerDetail ) << "Total unsafe time so far = " << std::chrono::duration_cast< std::chrono::seconds >( @@ -1193,8 +1197,6 @@ h256 Client::importTransaction( Transaction const& _t ) { // the latest block in the client's blockchain. This can throw but // we'll catch the exception at the RPC level. - const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); - // throws in case of error State state; u256 gasBidPrice; @@ -1202,6 +1204,10 @@ h256 Client::importTransaction( Transaction const& _t ) { DEV_GUARDED( m_blockImportMutex ) { state = this->state().createStateReadOnlyCopy(); gasBidPrice = this->gasBidPrice(); + + // We need to check external gas under mutex to be sure about current block bumber + // correctness + const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); } Executive::verifyTransaction( _t, diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 2d73ec229..755582aa1 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -198,7 +198,9 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { scheduleForUse = _cp.scheduleForBlockNumber( _bn ); // !! never call checkOutExternalGas with non-last block! - assert( _bn == CorrectForkInPowPatch::getLastBlockNumber() ); + if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) + BOOST_THROW_EXCEPTION( std::runtime_error( + "Internal error: checkOutExternalGas() has invalid block number" ) ); if ( externalGas >= baseGasRequired( scheduleForUse ) ) m_externalGas = externalGas; From 66b14bfd5f3e24327dfa8a11a27287ce50b47307 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 19 Dec 2023 17:34:38 +0000 Subject: [PATCH 105/159] SKALED-1431 remove data from transactions --- libweb3jsonrpc/Debug.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index 1fa2a6a9d..14e2e3fcd 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -316,5 +316,8 @@ uint64_t Debug::debug_doBlocksDbCompaction() { } Json::Value Debug::debug_getFutureTransactions() { - return toJson( m_eth.DEBUG_getFutureTransactions() ); + auto res = toJson( m_eth.DEBUG_getFutureTransactions() ); + for ( auto& t : res ) + t.removeMember( "data" ); + return res; } From 85c1b31ed9ca1d8415d53b2a35a4723e7dcfb185 Mon Sep 17 00:00:00 2001 From: badrogger Date: Tue, 19 Dec 2023 19:39:07 +0000 Subject: [PATCH 106/159] Add logs --- libethereum/InstanceMonitor.cpp | 8 +++++--- libethereum/InstanceMonitor.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index b101c1876..bad99e37f 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -49,17 +49,19 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; } -bool InstanceMonitor::isTimeToRotate( uint64_t _finishTimestamp ) { +bool InstanceMonitor::isTimeToRotate( uint64_t _blockTimestamp ) const { if ( !fs::exists( m_rotationInfoFilePath ) ) { return false; } - return rotationTimestamp() <= _finishTimestamp; + return rotationTimestamp() <= _blockTimestamp; } uint64_t InstanceMonitor::rotationTimestamp() const { std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); auto rotationJson = nlohmann::json::parse( rotationInfoFile ); - return rotationJson["timestamp"].get< uint64_t >(); + auto timestamp = rotationJson["timestamp"].get< uint64_t >(); + LOG( m_logger ) << "Rotation scheduled for " << timestamp; + return timestamp; } void InstanceMonitor::reportExitTimeReached( bool _reached ) { diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 8e6b23ab3..8470a2bbf 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -42,7 +42,7 @@ class InstanceMonitor { } void prepareRotation(); void initRotationParams( uint64_t _finishTimestamp ); - bool isTimeToRotate( uint64_t _finishTimestamp ); + bool isTimeToRotate( uint64_t _blockTimestamp ) const; protected: [[nodiscard]] uint64_t rotationTimestamp() const; @@ -56,5 +56,5 @@ class InstanceMonitor { void reportExitTimeReached( bool _reached ); private: - dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; + mutable dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; }; From d68d6a7088a142451f9e65f915d92e03951d9415 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 20 Dec 2023 18:44:24 +0000 Subject: [PATCH 107/159] SKALED-1745 Unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index d0a9f9083..bb8b97713 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -246,7 +246,7 @@ 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, int _emptyBlockIntervalMs = -1 ) { dev::p2p::NetworkPreferences nprefs; ChainParams chainParams; @@ -287,6 +287,9 @@ struct JsonRpcFixture : public TestOutputHelperFixture { // 615 + 1430 is experimentally-derived block size + average extras size chainParams.sChain.dbStorageLimit = 320.5*( 615 + 1430 ); chainParams.sChain.contractStoragePatchTimestamp = 1; + powPatchActivationTimestamp = time(nullptr) + 10; + chainParams.sChain.correctForkInPowPatchTimestamp = powPatchActivationTimestamp; // 10 guessed seconds + chainParams.sChain.emptyBlockIntervalMs = _emptyBlockIntervalMs; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -412,6 +415,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { unique_ptr< WebThreeStubClient > rpcClient; std::string adminSession; SkaleServerOverride* skale_server_connector; + time_t powPatchActivationTimestamp; }; struct RestrictedAddressFixture : public JsonRpcFixture { @@ -1560,7 +1564,8 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { } BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { - JsonRpcFixture fixture; + // 1s empty block interval + JsonRpcFixture fixture( "", true, true, false, false, 1000 ); dev::eth::simulateMining( *( fixture.client ), 1 ); auto senderAddress = fixture.coinbase.address(); @@ -1592,7 +1597,26 @@ BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { // Account balance is too low will mean that PoW didn't work out transact["gasPrice"] = toJS( powGasPrice ); - string txHash = fixture.rpcClient->eth_sendTransaction( transact ); + // wait for patch turning on and see how it happens + string txHash; + BlockHeader badInfo, goodInfo; + for(;;) { + try { + txHash = fixture.rpcClient->eth_sendTransaction( transact ); + goodInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); + break; + } catch(const std::exception& ex) { + // error should be "balance is too low" + assert(string(ex.what()).find("balance is too low") != string::npos); + badInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); + dev::eth::mineTransaction( *( fixture.client ), 1 ); // empty block + } // catch + } + + BOOST_REQUIRE_LT(badInfo.timestamp(), fixture.powPatchActivationTimestamp); + BOOST_REQUIRE_GE(goodInfo.timestamp(), fixture.powPatchActivationTimestamp); + BOOST_REQUIRE_EQUAL(badInfo.number()+1, goodInfo.number()); + dev::eth::mineTransaction( *( fixture.client ), 1 ); Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); From dac25b6318b329d321b682bfc20d2fb71cd5cd75 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 21 Dec 2023 16:16:05 +0000 Subject: [PATCH 108/159] SKALED-1745 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..ae545e245 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; + dev::eth::ChainParams m_chainParams; }; } // namespace rpc diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index bb8b97713..dbea2a921 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -287,7 +287,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { // 615 + 1430 is experimentally-derived block size + average extras size chainParams.sChain.dbStorageLimit = 320.5*( 615 + 1430 ); chainParams.sChain.contractStoragePatchTimestamp = 1; - powPatchActivationTimestamp = time(nullptr) + 10; + powPatchActivationTimestamp = time(nullptr) + 20; chainParams.sChain.correctForkInPowPatchTimestamp = powPatchActivationTimestamp; // 10 guessed seconds chainParams.sChain.emptyBlockIntervalMs = _emptyBlockIntervalMs; // add random extra data to randomize genesis hash and get random DB path, From dd6fdae20cc6fd624794e371204f2f2807fbc1fb Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 21 Dec 2023 17:32:46 +0000 Subject: [PATCH 109/159] Fix Net tests --- 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 3147f3456e3e305495b6b1179d526dfab09c4d73 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Thu, 21 Dec 2023 21:26:44 +0000 Subject: [PATCH 110/159] 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 9e259e969e66fc2fe2e2003eb7fb580f5e0cba95 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Sat, 23 Dec 2023 01:56:18 +0000 Subject: [PATCH 111/159] SKALED-1745 Fix unit tests --- libethereum/Transaction.cpp | 4 +++- libskale/CorrectForkInPowPatch.h | 6 ++++++ test/tools/libtesteth/BlockChainHelper.cpp | 10 ++++++++++ test/tools/libtesteth/TestOutputHelper.cpp | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 755582aa1..a8a105bd3 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -198,9 +198,11 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { scheduleForUse = _cp.scheduleForBlockNumber( _bn ); // !! never call checkOutExternalGas with non-last block! - if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) + if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) { + ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber(); BOOST_THROW_EXCEPTION( std::runtime_error( "Internal error: checkOutExternalGas() has invalid block number" ) ); + } if ( externalGas >= baseGasRequired( scheduleForUse ) ) m_externalGas = externalGas; diff --git a/libskale/CorrectForkInPowPatch.h b/libskale/CorrectForkInPowPatch.h index 243e49999..94c0f766e 100644 --- a/libskale/CorrectForkInPowPatch.h +++ b/libskale/CorrectForkInPowPatch.h @@ -9,6 +9,10 @@ namespace dev { namespace eth { class Client; } +namespace test { +class TestBlockChain; +class TestOutputHelperFixture; +} // namespace test } // namespace dev /* @@ -27,6 +31,8 @@ class CorrectForkInPowPatch : public SchainPatch { private: friend class dev::eth::Client; + friend class dev::test::TestBlockChain; + friend class dev::test::TestOutputHelperFixture; static time_t activationTimestamp; static time_t lastBlockTimestamp; static unsigned lastBlockNumber; diff --git a/test/tools/libtesteth/BlockChainHelper.cpp b/test/tools/libtesteth/BlockChainHelper.cpp index fbdaf71be..757ac6169 100644 --- a/test/tools/libtesteth/BlockChainHelper.cpp +++ b/test/tools/libtesteth/BlockChainHelper.cpp @@ -21,6 +21,8 @@ * that manage block/transaction import and test mining */ +#include + #include #include #include @@ -473,6 +475,10 @@ void TestBlockChain::reset( TestBlock const& _genesisBlock ) { } bool TestBlockChain::addBlock( TestBlock const& _block ) { + + CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp(); + CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number(); + while ( true ) { try { _block.verify( *this ); // check that block header match TestBlock contents @@ -494,6 +500,10 @@ bool TestBlockChain::addBlock( TestBlock const& _block ) { State st( block.state() ); m_lastBlock.setState( st ); + + CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp(); + CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number(); + return true; } diff --git a/test/tools/libtesteth/TestOutputHelper.cpp b/test/tools/libtesteth/TestOutputHelper.cpp index c863fa0fd..f5ec7cdf2 100644 --- a/test/tools/libtesteth/TestOutputHelper.cpp +++ b/test/tools/libtesteth/TestOutputHelper.cpp @@ -20,6 +20,7 @@ * Fixture class for boost output when running testeth */ +#include #include #include #include @@ -102,6 +103,8 @@ void TestOutputHelper::printTestExecStats() { } TestOutputHelperFixture::TestOutputHelperFixture() { TestOutputHelper::get().initTest(); + CorrectForkInPowPatch::lastBlockTimestamp = 1; + CorrectForkInPowPatch::lastBlockNumber = 0; } TestOutputHelperFixture::~TestOutputHelperFixture() { From 94255ca2d2bbd3cf51395ae9db76c6423609a4bf Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Sat, 23 Dec 2023 13:51:07 +0000 Subject: [PATCH 112/159] SKALED-1745 Test rename --- .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 From f6ce8089557f9bbfc57c036d215215fb19982a22 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Sat, 23 Dec 2023 15:03:16 +0000 Subject: [PATCH 113/159] SKALED-1745 Fix tests in historic build --- libethereum/Client.cpp | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 822572bcd..78c3d515a 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1264,7 +1264,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.checkOutExternalGas( ~u256( 0 ) ); + t.ignoreExternalGas(); if ( _ff == FudgeFactor::Lenient ) { historicBlock.mutableState().mutableHistoricState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index dbea2a921..3e8b941db 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3340,7 +3340,7 @@ BOOST_AUTO_TEST_CASE( test_transactions ) { Transaction valid( fromHex( "0xf86c808504a817c80083015f90943d7112ee86223baf0a506b9d2a77595cbbba51d1872386f26fc10000801ca0655757fd0650a65a373c48a4dc0f3d6ac5c3831aa0cc2cb863a5909dc6c25f72a071882ee8633466a243c0ea64dadb3120c1ca7a5cc7433c6c0b1c861a85322265" ), CheckTransaction::None ); - valid.checkOutExternalGas( 1 ); + valid.ignoreExternalGas(); client->importTransactionsAsBlock(Transactions{invalid, valid}, 1); @@ -3368,7 +3368,7 @@ BOOST_AUTO_TEST_CASE( test_exceptions ) { Transaction valid( fromHex( "0xf86c808504a817c80083015f90943d7112ee86223baf0a506b9d2a77595cbbba51d1872386f26fc10000801ca0655757fd0650a65a373c48a4dc0f3d6ac5c3831aa0cc2cb863a5909dc6c25f72a071882ee8633466a243c0ea64dadb3120c1ca7a5cc7433c6c0b1c861a85322265" ), CheckTransaction::None ); - valid.checkOutExternalGas( 1 ); + valid.ignoreExternalGas(); client->importTransactionsAsBlock(Transactions{invalid, valid}, 1); From a2d536317bd910dd75f59f653bf21010cb3a98a8 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 26 Dec 2023 12:51:48 +0000 Subject: [PATCH 114/159] 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 From c05c9b6ed6043ec44af37f11acc4e48114e5f902 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 28 Dec 2023 12:49:47 +0000 Subject: [PATCH 115/159] SKALED-1745 check external gas again after consensus --- libethereum/SkaleHost.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 4dd42ace4..fdd24b9a0 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -652,6 +652,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // TODO clear occasionally this cache?! if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { Transaction t = m_m_transaction_cache.at( sha.asArray() ); + t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); From b88c1758fc9502b2cca07b38cc1b29582f52654d Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 28 Dec 2023 13:29:48 +0000 Subject: [PATCH 116/159] SKALED-1745 Comments changes --- libethereum/Transaction.cpp | 2 +- test/tools/libtesteth/ImportTest.cpp | 41 ++-------------------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index a8a105bd3..6b9a9aa74 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -197,7 +197,7 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { if ( CorrectForkInPowPatch::isEnabled() ) scheduleForUse = _cp.scheduleForBlockNumber( _bn ); - // !! never call checkOutExternalGas with non-last block! + // never call checkOutExternalGas with non-last block if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) { ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber(); BOOST_THROW_EXCEPTION( std::runtime_error( diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index 3b4df86c3..7ecf2283d 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -111,36 +111,9 @@ void ImportTest::makeBlockchainTestFromStateTest( set< eth::Network > const& _ne TrExpectSection* search2 = &search; checkGeneralTestSectionSearch( exp.get_obj(), stateIndexesToPrint, "", search2 ); throw std::logic_error( "Skale state does not support addresses list" ); - // if (search.second.first.addresses().size() != 0) // if match in - // the expect sections - // // for this tr - // found - // { - // // replace expected mining reward (in state tests it is 0) - // json_spirit::mObject obj = - // fillJsonWithState(search2->second.first, - // search2->second.second); - // for (auto& adr : obj) - // { - // if (adr.first == toHexPrefixed(m_envInfo->author()) && - // adr.second.get_obj().count("balance")) - // { - // u256 expectCoinbaseBalance = - // toInt(adr.second.get_obj()["balance"]); - // expectCoinbaseBalance += blockReward; - // adr.second.get_obj()["balance"] = - // toCompactHexPrefixed(expectCoinbaseBalance); - // } - // } - - // json_spirit::mObject expetSectionObj; - // expetSectionObj["network"] = test::netIdToString(net); - // expetSectionObj["result"] = obj; - // expetSectionArray.push_back(expetSectionObj); - // break; - // } + } // for exp - } // for net + } // for net testObj["expect"] = expetSectionArray; @@ -225,7 +198,6 @@ bytes ImportTest::executeTest( bool _isFilling ) { continue; for ( auto& tr : m_transactions ) { -// tr.transaction.checkOutExternalGas( 100 ); Options const& opt = Options::get(); if ( opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd ) continue; @@ -739,15 +711,6 @@ bool ImportTest::checkGeneralTestSectionSearch( json_spirit::mObject const& _exp _errorTransactions.push_back( i ); } } else if ( _expects.count( "hash" ) ) { - // checking filled state test against client - // BOOST_CHECK_MESSAGE(_expects.at("hash").get_str() == - // toHexPrefixed(tr.postState.globalRoot().asBytes()), - // TestOutputHelper::get().testName() + " on " + - // test::netIdToString(tr.netId) + - // ": Expected another postState hash! expected: " + - // _expects.at("hash").get_str() + " actual: " + - // toHexPrefixed(tr.postState.globalRoot().asBytes()) + - // " in " + trInfo); if ( _expects.count( "logs" ) ) BOOST_CHECK_MESSAGE( _expects.at( "logs" ).get_str() == exportLog( tr.output.second.log() ), From 2feff86fa4ba066484d00730fc97465c9134d045 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 28 Dec 2023 16:14:46 +0000 Subject: [PATCH 117/159] SKALED-1745 Cancel second PoW gas check --- libethereum/SkaleHost.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index fdd24b9a0..4dd42ace4 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -652,7 +652,6 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // TODO clear occasionally this cache?! if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { Transaction t = m_m_transaction_cache.at( sha.asArray() ); - t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); From 460ebb05b48e80ffc410e1d4205dbaa2a0bb3f33 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 29 Dec 2023 15:48:03 +0000 Subject: [PATCH 118/159] SKALED-1714 testeth on historic build --- .github/workflows/test.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49803f389..2c955ca7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -215,7 +215,7 @@ jobs: sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/BtrfsTestSuitePassed sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/HashSnapshotTestSuitePassed sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/ClientSnapshotsSuitePassed - cd .. + cd ../.. - name: Testeth verbosity 4 run : | # Since a tests failed, we are rerunning the failed test with higher verbosity @@ -266,23 +266,22 @@ jobs: ls /tmp/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 ls /tmp/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 ls /tmp/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 - cd .. - + - name: Create lcov report run: | - lcov --capture --directory . --output-file coverage.info + lcov --capture --directory build/test --output-file coverage.info lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files lcov --remove coverage.info 'deps/*' --output-file coverage.info # filter dependency files lcov --remove coverage.info 'libconsensus/deps/*' --output-file coverage.info # filter dependency files lcov --remove coverage.info 'libconsensus/libBLS/deps/*' --output-file coverage.info # filter dependency files lcov --remove coverage.info '.hunter/*' --output-file coverage.info # filter dependency files - + - name: Upload to Codecov uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.info - + - name: Configure all as historic run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -310,3 +309,9 @@ jobs: - name: Print ccache stats after full historic build run : | ccache --show-stats + - name: Testeth historic + run : | + cd build/test + export NO_NTP_CHECK=1 + export NO_ULIMIT_CHECK=1 + ./testeth -t JsonRpcSuite -- --express --verbosity 4 From 4881ccd0650ce90e0ee7471225c7c3a9145a9497 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 29 Dec 2023 16:09:07 +0000 Subject: [PATCH 119/159] SKALED-1714 Temporarily disable normal build --- .github/workflows/test.yml | 149 ------------------------------------- 1 file changed, 149 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c955ca7f..08ec93804 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -122,7 +122,6 @@ jobs: ccache --show-stats - name: Build dependencies run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" export CC=gcc-9 export CXX=g++-9 @@ -134,154 +133,6 @@ jobs: rm -f ./libwebsockets-from-git.tar.gz ./build.sh DEBUG=1 PARALLEL_COUNT=$(nproc) cd .. - - name: Configure all - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - export CC=gcc-9 - export CXX=g++-9 - export TARGET=all - export CMAKE_BUILD_TYPE=Debug - export CODE_COVERAGE=ON - mkdir -p build - cd build - # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 - cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCOVERAGE=$CODE_COVERAGE .. - cd .. - - name: Print ccache stats for deps - run: | - ccache --show-stats - - name: Build all - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - export CC=gcc-9 - export CXX=g++-9 - export TARGET=all - export CMAKE_BUILD_TYPE=Debug - export CODE_COVERAGE=ON - cd build - make testeth -j$(nproc) - cd .. - - name: Print ccache stats after full build - run : | - ccache --show-stats - - name: Testeth verbosity 1 - run : | - #first run with verbosity 1. If test fails, rerun with verbosity 4 - cd build/test - export NO_NTP_CHECK=1 - export NO_ULIMIT_CHECK=1 - # we specifically run each test for easier log review - ./testeth -t BlockchainTests -- --express && touch /tmp/BlockchainTestsPassed - ./testeth -t TransitionTests -- --express && touch /tmp/TransitionTestsPassed - ./testeth -t TransactionTests -- --express && touch /tmp/TransactionTestsPassed - ./testeth -t VMTests -- --express && touch /tmp/VMTestsPassed - ./testeth -t LevelDBTests -- --express && touch /tmp/LevelDBTestsPassed - ./testeth -t CoreLibTests -- --express && touch /tmp/CoreLibTestsPassed - ./testeth -t RlpTests -- --express && touch /tmp/RlpTestsPassed - ./testeth -t SharedSpaceTests -- --express && touch /tmp/SharedSpaceTestsPassed - ./testeth -t EthashTests -- --express && touch /tmp/EthashTestsPassed - ./testeth -t SealEngineTests -- --express && touch /tmp/SealEngineTestsPassed - ./testeth -t DifficultyTests -- --express && touch /tmp/DifficultyTestsPassed - ./testeth -t BlockSuite -- --express && touch /tmp/BlockSuitePassed - ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/BlockChainMainNetworkSuitePassed - ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/BlockChainFrontierSuitePassed - ./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 ExtVmSuite -- --express && touch /tmp/ExtVmSuitePassed - ./testeth -t GasPricer -- --express && touch /tmp/GasPricerPassed - ./testeth -t BasicTests -- --express && touch /tmp/BasicTestsPassed - ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/InstanceMonitorSuitePassed - ./testeth -t PrecompiledTests -- --express && touch /tmp/PrecompiledTestsPassed - ./testeth -t SkaleHostSuite -- --express && touch /tmp/SkaleHostSuitePassed - ./testeth -t StateUnitTests -- --express && touch /tmp/StateUnitTestsPassed - ./testeth -t libethereum -- --express && touch /tmp/libethereumPassed - ./testeth -t TransactionQueueSuite -- --express && touch /tmp/TransactionQueueSuitePassed - ./testeth -t LegacyVMSuite -- --express && touch /tmp/LegacyVMSuitePassed - ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/SkaleInterpreterSuitePassed - ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/SnapshotSigningTestSuitePassed - ./testeth -t SkUtils -- --express && touch /tmp/SkUtilsPassed - ./testeth -t BlockChainTestSuite -- --express && touch /tmp/BlockChainTestSuitePassed - ./testeth -t TestHelperSuite -- --express && touch /tmp/TestHelperSuitePassed - ./testeth -t LevelDBHashBase -- --express && touch /tmp/LevelDBHashBasePassed - ./testeth -t memDB -- --express && touch /tmp/memDBPassed - ./testeth -t OverlayDBTests -- --express && touch /tmp/OverlayDBTestsPassed - ./testeth -t AccountHolderTest -- --express && touch /tmp/AccountHolderTestPassed - ./testeth -t ClientTests -- --express && touch /tmp/ClientTestsPassed - ./testeth -t JsonRpcSuite -- --express && touch /tmp/JsonRpcSuitePassed - ./testeth -t SingleConsensusTests -- --express && touch /tmp/SingleConsensusTestsPassed - ./testeth -t ConsensusTests -- --express && touch /tmp/ConsensusTestsPassed - sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/BtrfsTestSuitePassed - sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/HashSnapshotTestSuitePassed - sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/ClientSnapshotsSuitePassed - cd ../.. - - name: Testeth verbosity 4 - run : | - # Since a tests failed, we are rerunning the failed test with higher verbosity - cd build/test - export NO_NTP_CHECK=1 - export NO_ULIMIT_CHECK=1 - ls /tmp/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 - ls /tmp/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 - ls /tmp/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 - ls /tmp/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 - ls /tmp/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 - ls /tmp/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 - ls /tmp/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 - ls /tmp/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 - ls /tmp/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 - ls /tmp/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 - ls /tmp/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 - ls /tmp/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 - ls /tmp/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 - ls /tmp/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 - 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/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 - ls /tmp/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 - ls /tmp/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 - ls /tmp/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 - ls /tmp/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 - ls /tmp/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 - ls /tmp/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 - ls /tmp/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 - ls /tmp/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 - ls /tmp/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 - ls /tmp/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 - ls /tmp/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 - ls /tmp/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 - ls /tmp/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 - ls /tmp/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 - ls /tmp/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 - ls /tmp/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 - ls /tmp/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 - ls /tmp/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 - ls /tmp/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 - ls /tmp/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 - ls /tmp/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 - ls /tmp/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 - ls /tmp/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 - - - name: Create lcov report - run: | - lcov --capture --directory build/test --output-file coverage.info - lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files - lcov --remove coverage.info 'deps/*' --output-file coverage.info # filter dependency files - lcov --remove coverage.info 'libconsensus/deps/*' --output-file coverage.info # filter dependency files - lcov --remove coverage.info 'libconsensus/libBLS/deps/*' --output-file coverage.info # filter dependency files - lcov --remove coverage.info '.hunter/*' --output-file coverage.info # filter dependency files - - - name: Upload to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage.info - - name: Configure all as historic run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" From 6a8e6c9d76088f659a9baf3e4b8a40da4b7dab18 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 29 Dec 2023 17:04:37 +0000 Subject: [PATCH 120/159] SKALED-1714 Fix ChainParams& in Net.h --- 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 b3f1c0743023958fe737fffa58b720b571eb9333 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 3 Jan 2024 19:40:54 +0000 Subject: [PATCH 121/159] Handle malformed/missing rotationInfoFile --- libethereum/InstanceMonitor.cpp | 35 +++++++++++++------ libethereum/InstanceMonitor.h | 14 ++++++++ .../libethereum/InstanceMonitorTest.cpp | 9 +++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index bad99e37f..595175e0b 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -40,28 +40,43 @@ void InstanceMonitor::prepareRotation() { } void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { - nlohmann::json rotationJson = nlohmann::json::object(); - rotationJson["timestamp"] = _finishTimestamp; + try { + nlohmann::json rotationJson = nlohmann::json::object(); + rotationJson["timestamp"] = _finishTimestamp; - std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); - rotationInfoFile << rotationJson; + std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); + rotationInfoFile << rotationJson; - LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; + LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; + } catch ( ... ) { + LOG( m_logger ) << "Setting rotation timestamp failed"; + throw_with_nested( std::runtime_error( "cannot save rotation timestamp" ) ); + } } bool InstanceMonitor::isTimeToRotate( uint64_t _blockTimestamp ) const { if ( !fs::exists( m_rotationInfoFilePath ) ) { return false; } - return rotationTimestamp() <= _blockTimestamp; + try { + auto _rotationTimestamp = rotationTimestamp(); + return _rotationTimestamp <= _blockTimestamp; + } catch ( InvalidRotationInfoFileException& ex ) { + return false; + } } uint64_t InstanceMonitor::rotationTimestamp() const { std::ifstream rotationInfoFile( m_rotationInfoFilePath.string() ); - auto rotationJson = nlohmann::json::parse( rotationInfoFile ); - auto timestamp = rotationJson["timestamp"].get< uint64_t >(); - LOG( m_logger ) << "Rotation scheduled for " << timestamp; - return timestamp; + try { + auto rotationJson = nlohmann::json::parse( rotationInfoFile ); + auto timestamp = rotationJson["timestamp"].get< uint64_t >(); + LOG( m_logger ) << "Rotation scheduled for " << timestamp; + return timestamp; + } catch ( ... ) { + LOG( m_logger ) << "Rotation file is malformed or missing"; + throw InvalidRotationInfoFileException( m_rotationInfoFilePath ); + } } void InstanceMonitor::reportExitTimeReached( bool _reached ) { diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 8470a2bbf..293a068f6 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -55,6 +55,20 @@ class InstanceMonitor { void reportExitTimeReached( bool _reached ); + class InvalidRotationInfoFileException : public std::exception { + protected: + std::string what_str; + + public: + boost::filesystem::path path; + + InvalidRotationInfoFileException( const boost::filesystem::path& _path ) : path( _path ) { + what_str = "File " + path.string() + " is malformed or missing"; + } + virtual const char* what() const noexcept override { return what_str.c_str(); } + }; + + private: mutable dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; }; diff --git a/test/unittests/libethereum/InstanceMonitorTest.cpp b/test/unittests/libethereum/InstanceMonitorTest.cpp index bd1ebee0e..137b70555 100644 --- a/test/unittests/libethereum/InstanceMonitorTest.cpp +++ b/test/unittests/libethereum/InstanceMonitorTest.cpp @@ -80,6 +80,15 @@ BOOST_AUTO_TEST_CASE( test_initRotationParams ) { BOOST_CHECK_EQUAL(rotateJson["timestamp"].get< uint64_t >(), ts); } + +BOOST_AUTO_TEST_CASE( test_isTimeToRotate_invalid_file ) { + uint64_t currentTime = 100; + std::ofstream rotationInfoFile(instanceMonitor->getRotationInfoFilePath().string() ); + rotationInfoFile << "Broken file"; + BOOST_REQUIRE( !instanceMonitor->isTimeToRotate( currentTime ) ); +} + + BOOST_AUTO_TEST_CASE( test_isTimeToRotate_false ) { uint64_t currentTime = 100; uint64_t finishTime = 200; From 573f3c059213ff234067b408c33e19163a2da537 Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 4 Jan 2024 14:00:54 +0000 Subject: [PATCH 122/159] Rename rotation.txt -> rotation.json --- libethereum/InstanceMonitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index 595175e0b..b3a48a74b 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -32,7 +32,7 @@ using namespace dev; namespace fs = boost::filesystem; -const std::string InstanceMonitor::rotation_info_file_name = "rotation.txt"; +const std::string InstanceMonitor::rotation_info_file_name = "rotation.json"; void InstanceMonitor::prepareRotation() { reportExitTimeReached( true ); From 1600857ba45aeb2703235cc6c4d41ac3e973f14d Mon Sep 17 00:00:00 2001 From: badrogger Date: Thu, 4 Jan 2024 18:24:26 +0000 Subject: [PATCH 123/159] Add error logger in InstanceMonitor --- libethereum/InstanceMonitor.cpp | 12 ++++++------ libethereum/InstanceMonitor.h | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index b3a48a74b..d3dd72db1 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -47,9 +47,9 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); rotationInfoFile << rotationJson; - LOG( m_logger ) << "Set rotation time to " << _finishTimestamp; + LOG( m_info_logger ) << "Set rotation time to " << _finishTimestamp; } catch ( ... ) { - LOG( m_logger ) << "Setting rotation timestamp failed"; + LOG( m_error_logger ) << "Setting rotation timestamp failed"; throw_with_nested( std::runtime_error( "cannot save rotation timestamp" ) ); } } @@ -71,18 +71,18 @@ uint64_t InstanceMonitor::rotationTimestamp() const { try { auto rotationJson = nlohmann::json::parse( rotationInfoFile ); auto timestamp = rotationJson["timestamp"].get< uint64_t >(); - LOG( m_logger ) << "Rotation scheduled for " << timestamp; + LOG( m_info_logger ) << "Rotation scheduled for " << timestamp; return timestamp; } catch ( ... ) { - LOG( m_logger ) << "Rotation file is malformed or missing"; + LOG( m_error_logger ) << "Rotation file is malformed or missing"; throw InvalidRotationInfoFileException( m_rotationInfoFilePath ); } } void InstanceMonitor::reportExitTimeReached( bool _reached ) { if ( m_statusAndControl ) { - LOG( m_logger ) << "Setting ExitTimeReached = " << _reached; + LOG( m_info_logger ) << "Setting ExitTimeReached = " << _reached; m_statusAndControl->setExitState( StatusAndControl::ExitTimeReached, _reached ); } else - LOG( m_logger ) << "Simulating setting ExitTimeReached = " << _reached; + LOG( m_info_logger ) << "Simulating setting ExitTimeReached = " << _reached; } diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 293a068f6..4e241ad4d 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -70,5 +70,6 @@ class InstanceMonitor { private: - mutable dev::Logger m_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; + mutable dev::Logger m_info_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; + mutable dev::Logger m_error_logger{ createLogger( dev::VerbosityError, "instance-monitor" ) }; }; From 5bcc89829011673c17766f2fe85fcccc4e68e252 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 4 Jan 2024 20:10:27 +0000 Subject: [PATCH 124/159] SKALED-1714 Proper handling of LatestBlock in GappedTransactionIndexCache --- libweb3jsonrpc/Eth.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 849664172..da6e1bfc6 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -66,6 +66,12 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn, _readLock.unlock(); _writeLock.lock(); + unsigned realBn = _bn; + if ( _bn == LatestBlock ) + realBn = client.number(); + else if ( _bn == PendingBlock ) + realBn = 0; // TODO test this case and decide + assert( real2gappedCache.size() <= cacheSize ); if ( real2gappedCache.size() >= cacheSize ) { real2gappedCache.erase( real2gappedCache.begin() ); @@ -89,7 +95,7 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn, pair< h256, unsigned > loc = client.transactionLocation( th ); // ignore transactions with 0 gas usage OR different location! - if ( diff == 0 || client.numberFromHash( loc.first ) != _bn || loc.second != realIndex ) + if ( diff == 0 || client.numberFromHash( loc.first ) != realBn || loc.second != realIndex ) continue; // cache it From a600e09dbe504765d7dd6cec58111c62b34c041c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 4 Jan 2024 21:32:17 +0000 Subject: [PATCH 125/159] SKALED-1714 Extended tests --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 43 +++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 7640a5b24..e75d7c9ef 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3023,15 +3023,36 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { #ifdef HISTORIC_STATE // 3 check that historic node sees only 3 txns + string explicitNumberStr = to_string(fixture.client->number()); + // 1 Block Json::Value block = fixture.rpcClient->eth_getBlockByNumber("latest", "false"); + string bh = block["hash"].asString(); + + // 2 transaction count + Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest"); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber(explicitNumberStr); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh); + BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); + + + BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3); + BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0"); + BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1"); + BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2"); + + // same with explicit number + block = fixture.rpcClient->eth_getBlockByNumber(explicitNumberStr, "false"); + BOOST_REQUIRE_EQUAL(block["transactions"].size(), 3); BOOST_REQUIRE_EQUAL(block["transactions"][0]["transactionIndex"], "0x0"); BOOST_REQUIRE_EQUAL(block["transactions"][1]["transactionIndex"], "0x1"); BOOST_REQUIRE_EQUAL(block["transactions"][2]["transactionIndex"], "0x2"); - // 2 receipts + // 3 receipts Json::Value r1,r3,r4; BOOST_REQUIRE_NO_THROW(r1 = fixture.rpcClient->eth_getTransactionReceipt(toJS(h1))); BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionReceipt(toJS(h2)), jsonrpc::JsonRpcException); @@ -3042,16 +3063,24 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { BOOST_REQUIRE_EQUAL(r3["transactionIndex"], "0x1"); BOOST_REQUIRE_EQUAL(r4["transactionIndex"], "0x2"); - // 3 transaction by index + // 4 transaction by index Json::Value t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "0"); Json::Value t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "1"); Json::Value t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex("latest", "2"); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); + BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); + // same with explicit block number + + t0 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "0"); + t1 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "1"); + t2 = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex(explicitNumberStr, "2"); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t0["hash"].asString()), h1); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); - string bh = r1["blockHash"].asString(); + BOOST_REQUIRE_EQUAL(bh, r1["blockHash"].asString()); t0 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "0"); t1 = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex(bh, "1"); @@ -3061,15 +3090,9 @@ BOOST_AUTO_TEST_CASE( skip_invalid_transactions ) { BOOST_REQUIRE_EQUAL(jsToFixed<32>(t1["hash"].asString()), h3); BOOST_REQUIRE_EQUAL(jsToFixed<32>(t2["hash"].asString()), h4); - // 4 transaction by hash + // 5 transaction by hash BOOST_REQUIRE_THROW (fixture.rpcClient->eth_getTransactionByHash(toJS(h2)), jsonrpc::JsonRpcException); - // 5 transaction count - Json::Value cnt = fixture.rpcClient->eth_getBlockTransactionCountByNumber("latest"); - BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); - cnt = fixture.rpcClient->eth_getBlockTransactionCountByHash(bh); - BOOST_REQUIRE_EQUAL(cnt.asString(), "0x3"); - // send it successfully // make money From 178584719e84cc8d2f984017af35f5fe9d85a090 Mon Sep 17 00:00:00 2001 From: badrogger Date: Fri, 5 Jan 2024 11:50:56 +0000 Subject: [PATCH 126/159] Rename m_info_logger -> m_infoLogger --- libethereum/InstanceMonitor.cpp | 12 ++++++------ libethereum/InstanceMonitor.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libethereum/InstanceMonitor.cpp b/libethereum/InstanceMonitor.cpp index d3dd72db1..ed180f6fc 100644 --- a/libethereum/InstanceMonitor.cpp +++ b/libethereum/InstanceMonitor.cpp @@ -47,9 +47,9 @@ void InstanceMonitor::initRotationParams( uint64_t _finishTimestamp ) { std::ofstream rotationInfoFile( m_rotationInfoFilePath.string() ); rotationInfoFile << rotationJson; - LOG( m_info_logger ) << "Set rotation time to " << _finishTimestamp; + LOG( m_infoLogger ) << "Set rotation time to " << _finishTimestamp; } catch ( ... ) { - LOG( m_error_logger ) << "Setting rotation timestamp failed"; + LOG( m_errorLogger ) << "Setting rotation timestamp failed"; throw_with_nested( std::runtime_error( "cannot save rotation timestamp" ) ); } } @@ -71,18 +71,18 @@ uint64_t InstanceMonitor::rotationTimestamp() const { try { auto rotationJson = nlohmann::json::parse( rotationInfoFile ); auto timestamp = rotationJson["timestamp"].get< uint64_t >(); - LOG( m_info_logger ) << "Rotation scheduled for " << timestamp; + LOG( m_infoLogger ) << "Rotation scheduled for " << timestamp; return timestamp; } catch ( ... ) { - LOG( m_error_logger ) << "Rotation file is malformed or missing"; + LOG( m_errorLogger ) << "Rotation file is malformed or missing"; throw InvalidRotationInfoFileException( m_rotationInfoFilePath ); } } void InstanceMonitor::reportExitTimeReached( bool _reached ) { if ( m_statusAndControl ) { - LOG( m_info_logger ) << "Setting ExitTimeReached = " << _reached; + LOG( m_infoLogger ) << "Setting ExitTimeReached = " << _reached; m_statusAndControl->setExitState( StatusAndControl::ExitTimeReached, _reached ); } else - LOG( m_info_logger ) << "Simulating setting ExitTimeReached = " << _reached; + LOG( m_infoLogger ) << "Simulating setting ExitTimeReached = " << _reached; } diff --git a/libethereum/InstanceMonitor.h b/libethereum/InstanceMonitor.h index 4e241ad4d..688fddcbd 100644 --- a/libethereum/InstanceMonitor.h +++ b/libethereum/InstanceMonitor.h @@ -70,6 +70,6 @@ class InstanceMonitor { private: - mutable dev::Logger m_info_logger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; - mutable dev::Logger m_error_logger{ createLogger( dev::VerbosityError, "instance-monitor" ) }; + mutable dev::Logger m_infoLogger{ createLogger( dev::VerbosityInfo, "instance-monitor" ) }; + mutable dev::Logger m_errorLogger{ createLogger( dev::VerbosityError, "instance-monitor" ) }; }; From c157fe17cae95c6d752b44177cbb67e19a03c23c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 5 Jan 2024 14:42:21 +0000 Subject: [PATCH 127/159] SKALED-1431 Rename DEBUG and fix in tests --- libethereum/Client.h | 2 +- libethereum/TransactionQueue.cpp | 2 +- libethereum/TransactionQueue.h | 2 +- libweb3jsonrpc/Debug.cpp | 2 +- libweb3jsonrpc/Net.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libethereum/Client.h b/libethereum/Client.h index ba6c74064..d62af01b1 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -127,7 +127,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/libweb3jsonrpc/Debug.cpp b/libweb3jsonrpc/Debug.cpp index 14e2e3fcd..91cc76bca 100644 --- a/libweb3jsonrpc/Debug.cpp +++ b/libweb3jsonrpc/Debug.cpp @@ -316,7 +316,7 @@ uint64_t Debug::debug_doBlocksDbCompaction() { } Json::Value Debug::debug_getFutureTransactions() { - auto res = toJson( m_eth.DEBUG_getFutureTransactions() ); + auto res = toJson( m_eth.debugGetFutureTransactions() ); for ( auto& t : res ) t.removeMember( "data" ); return res; 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 bff82992ff16dd3bcf70021344e2c1324f67491c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 5 Jan 2024 18:36:57 +0000 Subject: [PATCH 128/159] SKALED-1714 Assume that PendingBlock = latest+1 --- libweb3jsonrpc/Eth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index da6e1bfc6..63d4a8ff3 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -70,7 +70,7 @@ void GappedTransactionIndexCache::ensureCached( BlockNumber _bn, if ( _bn == LatestBlock ) realBn = client.number(); else if ( _bn == PendingBlock ) - realBn = 0; // TODO test this case and decide + realBn = client.number() + 1; // TODO test this case and decide assert( real2gappedCache.size() <= cacheSize ); if ( real2gappedCache.size() >= cacheSize ) { From b66157ef62635a9df82afd7d138229821d69b962 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 5 Jan 2024 18:37:34 +0000 Subject: [PATCH 129/159] SKALED-1714 Get back normal build --- .github/workflows/test.yml | 150 +++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 08ec93804..88d95350a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -133,6 +133,156 @@ jobs: rm -f ./libwebsockets-from-git.tar.gz ./build.sh DEBUG=1 PARALLEL_COUNT=$(nproc) cd .. + + - name: Configure all + run: | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + export CMAKE_BUILD_TYPE=Debug + export CODE_COVERAGE=ON + mkdir -p build + cd build + # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 + cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCOVERAGE=$CODE_COVERAGE .. + cd .. + - name: Print ccache stats for deps + run: | + ccache --show-stats + - name: Build all + run: | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + export CMAKE_BUILD_TYPE=Debug + export CODE_COVERAGE=ON + cd build + make testeth -j$(nproc) + cd .. + - name: Print ccache stats after full build + run : | + ccache --show-stats + - name: Testeth verbosity 1 + run : | + #first run with verbosity 1. If test fails, rerun with verbosity 4 + cd build/test + export NO_NTP_CHECK=1 + export NO_ULIMIT_CHECK=1 + # we specifically run each test for easier log review + ./testeth -t BlockchainTests -- --express && touch /tmp/BlockchainTestsPassed + ./testeth -t TransitionTests -- --express && touch /tmp/TransitionTestsPassed + ./testeth -t TransactionTests -- --express && touch /tmp/TransactionTestsPassed + ./testeth -t VMTests -- --express && touch /tmp/VMTestsPassed + ./testeth -t LevelDBTests -- --express && touch /tmp/LevelDBTestsPassed + ./testeth -t CoreLibTests -- --express && touch /tmp/CoreLibTestsPassed + ./testeth -t RlpTests -- --express && touch /tmp/RlpTestsPassed + ./testeth -t SharedSpaceTests -- --express && touch /tmp/SharedSpaceTestsPassed + ./testeth -t EthashTests -- --express && touch /tmp/EthashTestsPassed + ./testeth -t SealEngineTests -- --express && touch /tmp/SealEngineTestsPassed + ./testeth -t DifficultyTests -- --express && touch /tmp/DifficultyTestsPassed + ./testeth -t BlockSuite -- --express && touch /tmp/BlockSuitePassed + ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/BlockChainMainNetworkSuitePassed + ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/BlockChainFrontierSuitePassed + ./testeth -t BlockQueueSuite -- --express && touch /tmp/BlockQueueSuitePassed + ./testeth -t ClientBase -- --express && touch /tmp/ClientBasePassed + ./testeth -t EstimateGas -- --express && touch /tmp/EstimateGasPassed + ./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 + ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/InstanceMonitorSuitePassed + ./testeth -t PrecompiledTests -- --express && touch /tmp/PrecompiledTestsPassed + ./testeth -t SkaleHostSuite -- --express && touch /tmp/SkaleHostSuitePassed + ./testeth -t StateUnitTests -- --express && touch /tmp/StateUnitTestsPassed + ./testeth -t libethereum -- --express && touch /tmp/libethereumPassed + ./testeth -t TransactionQueueSuite -- --express && touch /tmp/TransactionQueueSuitePassed + ./testeth -t LegacyVMSuite -- --express && touch /tmp/LegacyVMSuitePassed + ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/SkaleInterpreterSuitePassed + ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/SnapshotSigningTestSuitePassed + ./testeth -t SkUtils -- --express && touch /tmp/SkUtilsPassed + ./testeth -t BlockChainTestSuite -- --express && touch /tmp/BlockChainTestSuitePassed + ./testeth -t TestHelperSuite -- --express && touch /tmp/TestHelperSuitePassed + ./testeth -t LevelDBHashBase -- --express && touch /tmp/LevelDBHashBasePassed + ./testeth -t memDB -- --express && touch /tmp/memDBPassed + ./testeth -t OverlayDBTests -- --express && touch /tmp/OverlayDBTestsPassed + ./testeth -t AccountHolderTest -- --express && touch /tmp/AccountHolderTestPassed + ./testeth -t ClientTests -- --express && touch /tmp/ClientTestsPassed + ./testeth -t JsonRpcSuite -- --express && touch /tmp/JsonRpcSuitePassed + ./testeth -t SingleConsensusTests -- --express && touch /tmp/SingleConsensusTestsPassed + ./testeth -t ConsensusTests -- --express && touch /tmp/ConsensusTestsPassed + sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/BtrfsTestSuitePassed + sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/HashSnapshotTestSuitePassed + sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/ClientSnapshotsSuitePassed + cd .. + - name: Testeth verbosity 4 + run : | + # Since a tests failed, we are rerunning the failed test with higher verbosity + cd build/test + export NO_NTP_CHECK=1 + export NO_ULIMIT_CHECK=1 + ls /tmp/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 + ls /tmp/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 + ls /tmp/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 + ls /tmp/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 + ls /tmp/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 + ls /tmp/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 + ls /tmp/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 + ls /tmp/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 + ls /tmp/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 + ls /tmp/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 + ls /tmp/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 + ls /tmp/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 + ls /tmp/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 + ls /tmp/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 + 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/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 + ls /tmp/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 + ls /tmp/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 + ls /tmp/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 + ls /tmp/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 + ls /tmp/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 + ls /tmp/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 + ls /tmp/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 + ls /tmp/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 + ls /tmp/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 + ls /tmp/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 + ls /tmp/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 + ls /tmp/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 + ls /tmp/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 + ls /tmp/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 + ls /tmp/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 + ls /tmp/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 + ls /tmp/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 + ls /tmp/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 + ls /tmp/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 + ls /tmp/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 + ls /tmp/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 + ls /tmp/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 + ls /tmp/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 + cd .. + + - name: Create lcov report + run: | + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files + lcov --remove coverage.info 'deps/*' --output-file coverage.info # filter dependency files + lcov --remove coverage.info 'libconsensus/deps/*' --output-file coverage.info # filter dependency files + lcov --remove coverage.info 'libconsensus/libBLS/deps/*' --output-file coverage.info # filter dependency files + lcov --remove coverage.info '.hunter/*' --output-file coverage.info # filter dependency files + + - name: Upload to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.info + - name: Configure all as historic run: | export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" From e38ef4fda6e47344269950792aab354e21344755 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 8 Jan 2024 13:05:32 +0000 Subject: [PATCH 130/159] fix boost build --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 77c101094..ddde155ee 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 77c101094ce15dc549cb4a1e606919c8e8170012 +Subproject commit ddde155ee8ca1e9dbc8adcccab62d9f85a48f1c0 From 6183fafbc194bc0fbd9f1c9afd91b76b54921e21 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 8 Jan 2024 13:19:48 +0000 Subject: [PATCH 131/159] fix boost build --- deps/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/build.sh b/deps/build.sh index 16f35d527..664c42448 100755 --- a/deps/build.sh +++ b/deps/build.sh @@ -1223,7 +1223,7 @@ then # #CMAKE_ARGS_FOR_LIB_WEB_SOCKETS="$CMAKE_ARGS_FOR_LIB_WEB_SOCKETS -DLWS_WITH_LIBEV=ON" # LWS_WITH_LIBEV=ON # fi - #else + #else ## #CMAKE_ARGS_FOR_LIB_WEB_SOCKETS="$CMAKE_ARGS_FOR_LIB_WEB_SOCKETS -DLWS_WITH_LIBEV=OFF" # echo " " #fi @@ -1383,7 +1383,7 @@ then if [ ! -f "boost_1_68_0.tar.bz2" ]; then echo -e "${COLOR_INFO}downloading it${COLOR_DOTS}...${COLOR_RESET}" - eval "$WGET" https://boostorg.jfrog.io/artifactory/main/release/1.68.0/source/boost_1_68_0.tar.bz2 + eval "$WGET" https://sourceforge.net/projects/boost/files/boost/1.68.0/boost_1_68_0.tar.bz2 fi echo -e "${COLOR_INFO}unpacking it${COLOR_DOTS}...${COLOR_RESET}" eval tar -xf boost_1_68_0.tar.bz2 From 08b6296f442b64b0a47ff804dc9edfb812db2a30 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 9 Jan 2024 12:28:27 +0000 Subject: [PATCH 132/159] #1640 increase timeout to reject old transaction through broadcast --- libethereum/SkaleHost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 734cd1369..6508d8781 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -66,7 +66,7 @@ using namespace dev::eth; #define CONSENSUS 1 #endif -const int SkaleHost::REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC = 360; +const int SkaleHost::REJECT_OLD_TRANSACTION_THROUGH_BROADCAST_INTERVAL_SEC = 600; std::unique_ptr< ConsensusInterface > DefaultConsensusFactory::create( ConsensusExtFace& _extFace ) const { From 8ed937ba8a429c689947fd4a87258bf99293f8d9 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 9 Jan 2024 16:49:08 +0000 Subject: [PATCH 133/159] SKALED-1745 Add missing re-check of external gas --- libconsensus | 2 +- libethereum/SkaleHost.cpp | 1 + libethereum/Transaction.cpp | 4 ++-- libethereum/Transaction.h | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libconsensus b/libconsensus index 77c101094..952e3890d 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 77c101094ce15dc549cb4a1e606919c8e8170012 +Subproject commit 952e3890d620d55d56e32dc0fbd26637f23d0694 diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 62dab409e..54c82d9c2 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -644,6 +644,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // TODO clear occasionally this cache?! if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { Transaction t = m_m_transaction_cache.at( sha.asArray() ); + t.checkOutExternalGas( m_client.chainParams(), m_client.number(), true ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 6b9a9aa74..de556a0f9 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -181,10 +181,10 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ) { +void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force ) { u256 const& difficulty = _cp.externalGasDifficulty; assert( difficulty > 0 ); - if ( !m_externalGasIsChecked && !isInvalid() ) { + if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) { h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); if ( !hash ) { hash = h256( 1 ); diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 5cc8cf1eb..dffadb347 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -122,7 +122,7 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn ); + void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force = false ); void ignoreExternalGas() { m_externalGasIsChecked = true; From 8c0473cce53d57fd4bfa52324f40fb09fc7e5ce1 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 9 Jan 2024 16:52:55 +0000 Subject: [PATCH 134/159] SKALED-1745 Updated libconsensus --- libconsensus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libconsensus b/libconsensus index 952e3890d..ddde155ee 160000 --- a/libconsensus +++ b/libconsensus @@ -1 +1 @@ -Subproject commit 952e3890d620d55d56e32dc0fbd26637f23d0694 +Subproject commit ddde155ee8ca1e9dbc8adcccab62d9f85a48f1c0 From 8e735e59bff656f65dd480f614bb3efe27a8a422 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 9 Jan 2024 17:12:33 +0000 Subject: [PATCH 135/159] SLALED-1745 Update eth_estimateGas only after patch timestamp --- libethereum/ClientBase.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 35a031695..6b6d530b4 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -23,6 +23,7 @@ */ #include "ClientBase.h" +#include #include #include @@ -115,8 +116,11 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from int64_t upperBound = _maxGas; if ( upperBound == Invalid256 || upperBound > c_maxGasEstimate ) upperBound = c_maxGasEstimate; - int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, - bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ); + int64_t lowerBound = + CorrectForkInPowPatch::isEnabled() ? + Transaction::baseGasRequired( !_dest, &_data, + bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ) : + Transaction::baseGasRequired( !_dest, &_data, EVMSchedule() ); Block bk = latestBlock(); if ( upperBound > bk.info().gasLimit() ) { From a9067bd813284a2ccb7c646c02aa89bfafe823e4 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 9 Jan 2024 18:43:16 +0000 Subject: [PATCH 136/159] SKALED-1431 Test --- .../libweb3jsonrpc/WebThreeStubClient.cpp | 10 ++++++++++ .../libweb3jsonrpc/WebThreeStubClient.h | 1 + test/unittests/libweb3jsonrpc/jsonrpc.cpp | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp index acdebbf42..680bdb57e 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp @@ -1344,3 +1344,13 @@ Json::Value WebThreeStubClient::debug_doBlocksDbCompaction() { throw jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); } + +Json::Value WebThreeStubClient::debug_getFutureTransactions() { + Json::Value p; + Json::Value result = this->CallMethod( "debug_getFutureTransactions", p ); + if ( result.isArray() ) + return result; + else + throw jsonrpc::JsonRpcException( + jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() ); +} diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index a97f41d25..ad50db93a 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -160,6 +160,7 @@ class WebThreeStubClient : public jsonrpc::Client { const Json::Value& param3 ) noexcept( false ); Json::Value debug_doStateDbCompaction() noexcept( false ); Json::Value debug_doBlocksDbCompaction() noexcept( false ); + Json::Value debug_getFutureTransactions() noexcept( false ); }; #endif // JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 7640a5b24..26e2c893c 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2878,23 +2878,40 @@ BOOST_AUTO_TEST_CASE( mtm_import_future_txs ) { BOOST_REQUIRE( h1 ); BOOST_REQUIRE_EQUAL( tq->futureSize(), 1); + Json::Value call = fixture.rpcClient->debug_getFutureTransactions(); + BOOST_REQUIRE_EQUAL( call.size(), 1); + h256 h2 = fixture.client->importTransaction( tx3 ); BOOST_REQUIRE( h2 ); BOOST_REQUIRE_EQUAL( tq->futureSize(), 2); + + call = fixture.rpcClient->debug_getFutureTransactions(); + BOOST_REQUIRE_EQUAL( call.size(), 2); + BOOST_REQUIRE_EQUAL( call[0]["from"], string("0x")+txJson["from"].asString() ); + h256 h3 = fixture.client->importTransaction( tx2 ); BOOST_REQUIRE( h3 ); BOOST_REQUIRE_EQUAL( tq->futureSize(), 3); + call = fixture.rpcClient->debug_getFutureTransactions(); + BOOST_REQUIRE_EQUAL( call.size(), 3); + h256 h4 = fixture.client->importTransaction( tx1 ); BOOST_REQUIRE( h4 ); BOOST_REQUIRE_EQUAL( tq->futureSize(), 1); BOOST_REQUIRE_EQUAL( tq->status().current, 3); + call = fixture.rpcClient->debug_getFutureTransactions(); + BOOST_REQUIRE_EQUAL( call.size(), 1); + h256 h5 = fixture.client->importTransaction( tx4 ); BOOST_REQUIRE( h5 ); BOOST_REQUIRE_EQUAL( tq->futureSize(), 0); BOOST_REQUIRE_EQUAL( tq->status().current, 5); + call = fixture.rpcClient->debug_getFutureTransactions(); + BOOST_REQUIRE_EQUAL( call.size(), 0); + fixture.client->skaleHost()->pauseConsensus( false ); } From 9f1de098e15c1c82f3840c4acecb1242e19ddf58 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 10 Jan 2024 13:55:15 +0000 Subject: [PATCH 137/159] SKALED-1745 Adjust tests --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 36 +++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 6c4edd55f..0f683f344 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -248,7 +248,7 @@ 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, int _emptyBlockIntervalMs = -1, bool _isSyncNode = false ) { + bool _mtmEnabled = false, bool _isSyncNode = false, int _emptyBlockIntervalMs = -1 ) { dev::p2p::NetworkPreferences nprefs; ChainParams chainParams; @@ -1604,7 +1604,7 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { // 1s empty block interval - JsonRpcFixture fixture( "", true, true, false, false, 1000 ); + JsonRpcFixture fixture( "", true, true, false, false, false, 1000 ); dev::eth::simulateMining( *( fixture.client ), 1 ); auto senderAddress = fixture.coinbase.address(); @@ -1621,15 +1621,17 @@ BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); u256 gasEstimate = jsToU256(gasEstimateStr); - BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*16)); + // old estimate before patch + BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*68)); u256 powGasPrice = 0; + u256 correctEstimate = u256(21000+1024*16); do { const u256 GAS_PER_HASH = 1; u256 candidate = h256::random(); h256 hash = dev::sha3( senderAddress ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; - if ( externalGas >= gasEstimate && externalGas < gasEstimate + gasEstimate/10 ) { + if ( externalGas >= correctEstimate && externalGas < correctEstimate + correctEstimate/10 ) { powGasPrice = candidate; } } while ( !powGasPrice ); @@ -1640,17 +1642,27 @@ BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { string txHash; BlockHeader badInfo, goodInfo; for(;;) { - try { + string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); + u256 gasEstimate = jsToU256(gasEstimateStr); + // old + if(gasEstimate == u256(21000+1024*68)){ + try{ + fixture.rpcClient->eth_sendTransaction( transact ); + BOOST_REQUIRE(false); + } catch(const std::exception& ex) { + assert(string(ex.what()).find("balance is too low") != string::npos); + badInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); + dev::eth::mineTransaction( *( fixture.client ), 1 ); // empty block + } // catch + } + // new + else { + BOOST_REQUIRE_EQUAL(gasEstimate, correctEstimate); txHash = fixture.rpcClient->eth_sendTransaction( transact ); goodInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); break; - } catch(const std::exception& ex) { - // error should be "balance is too low" - assert(string(ex.what()).find("balance is too low") != string::npos); - badInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); - dev::eth::mineTransaction( *( fixture.client ), 1 ); // empty block - } // catch - } + } // else + } // for BOOST_REQUIRE_LT(badInfo.timestamp(), fixture.powPatchActivationTimestamp); BOOST_REQUIRE_GE(goodInfo.timestamp(), fixture.powPatchActivationTimestamp); From f08f134af4a265bb66e6c742aa62222213045f64 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 10 Jan 2024 16:24:19 +0000 Subject: [PATCH 138/159] #1588 change snapshot hash computation --- libdevcore/LevelDB.cpp | 23 ++++++++++++++- libdevcore/LevelDB.h | 5 ++++ libskale/SnapshotManager.cpp | 25 ++++++++++++---- test/unittests/libweb3core/LevelDBHash.cpp | 33 ++++++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index 2896cf4d0..cb6fba758 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -22,7 +22,6 @@ #include "Assertions.h" #include "Log.h" #include -#include namespace dev { namespace db { @@ -263,6 +262,7 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); } + secp256k1_sha256_t ctx; secp256k1_sha256_initialize( &ctx ); for ( it->SeekToFirst(); it->Valid(); it->Next() ) { @@ -280,6 +280,27 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { return hash; } +void LevelDB::hashBasePartially( + secp256k1_sha256_t* ctx, const std::string& start, const std::string& finish ) const { + std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) ); + if ( it == nullptr ) { + BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); + } + for ( it->Seek( start ); it->Valid() && it->key().ToString() < finish; it->Next() ) { + std::string key_ = it->key().ToString(); + std::string value_ = it->value().ToString(); + // HACK! For backward compatibility! When snapshot could happen between update of two nodes + // - it would lead to stateRoot mismatch + // TODO Move this logic to separate "compatiliblity layer"! + if ( key_ == "pieceUsageBytes" ) + continue; + std::string key_value = key_ + value_; + const std::vector< uint8_t > usc( key_value.begin(), key_value.end() ); + bytesConstRef str_key_value( usc.data(), usc.size() ); + secp256k1_sha256_write( ctx, str_key_value.data(), str_key_value.size() ); + } +} + void LevelDB::doCompaction() const { m_db->CompactRange( nullptr, nullptr ); } diff --git a/libdevcore/LevelDB.h b/libdevcore/LevelDB.h index 0a597c51e..470f318dd 100644 --- a/libdevcore/LevelDB.h +++ b/libdevcore/LevelDB.h @@ -26,6 +26,8 @@ #include #include +#include + namespace dev { namespace db { class LevelDB : public DatabaseFace { @@ -59,6 +61,9 @@ class LevelDB : public DatabaseFace { h256 hashBase() const override; h256 hashBaseWithPrefix( char _prefix ) const; + void hashBasePartially( + secp256k1_sha256_t* ctx, const std::string& start, const std::string& finish ) const; + void doCompaction() const; // Return the total count of key deletes since the start diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index d3c3bc04e..04c7cd0be 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -445,13 +445,26 @@ void SnapshotManager::computeDatabaseHash( BOOST_THROW_EXCEPTION( InvalidPath( _dbDir ) ); } - std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( _dbDir.string(), - dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), - dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - dev::h256 hash_volume = m_db->hashBase(); - cnote << _dbDir << " hash is: " << hash_volume << std::endl; + std::array< std::string, 17 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", "6", + "7", "8", "9", "a", "b", "c", "d", "e", "f", "g" }; - secp256k1_sha256_write( ctx, hash_volume.data(), hash_volume.size ); + secp256k1_sha256_t dbCtx; + secp256k1_sha256_initialize( &dbCtx ); + + for ( size_t i = 0; i < lexographicKeysSegments.size() - 1; ++i ) { + std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( _dbDir.string(), + dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), + dev::db::LevelDB::defaultSnapshotDBOptions() ) ); + + m_db->hashBasePartially( + &dbCtx, lexographicKeysSegments[i], lexographicKeysSegments[i + 1] ); + } + + dev::h256 dbHash; + secp256k1_sha256_finalize( &dbCtx, dbHash.data() ); + cnote << _dbDir << " hash is: " << dbHash << std::endl; + + secp256k1_sha256_write( ctx, dbHash.data(), dbHash.size ); } catch ( const fs::filesystem_error& ex ) { std::throw_with_nested( CannotRead( ex.path1() ) ); } diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index 67dde80cb..bbecf1249 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -39,6 +39,39 @@ BOOST_AUTO_TEST_CASE( hash ) { BOOST_REQUIRE( hash == hash_same ); + dev::h256 hashPartially; + { + { + std::unique_ptr< dev::db::LevelDB > db_copy( new dev::db::LevelDB( td.path() ) ); + BOOST_REQUIRE( db_copy ); + + for ( size_t i = 0; i < 123; ++i ) { + std::string key = std::to_string( 43 + i ); + std::string value = std::to_string( i ); + db_copy->insert( dev::db::Slice(key), dev::db::Slice(value) ); + } + } + + std::array< std::string, 17 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", "6", + "7", "8", "9", "a", "b", "c", "d", + "e", "f", "g" }; + + secp256k1_sha256_t dbCtx; + secp256k1_sha256_initialize( &dbCtx ); + + for (size_t i = 0; i < lexographicKeysSegments.size() - 1; ++i) { + std::unique_ptr< dev::db::LevelDB > db( new dev::db::LevelDB( td.path(), + dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), + dev::db::LevelDB::defaultSnapshotDBOptions() ) ); + + db->hashBasePartially( &dbCtx, lexographicKeysSegments[i], lexographicKeysSegments[i + 1] ); + } + + secp256k1_sha256_finalize( &dbCtx, hashPartially.data() ); + } + + BOOST_REQUIRE( hash == hashPartially ); + dev::h256 hash_diff; { std::unique_ptr< dev::db::LevelDB > db_diff( new dev::db::LevelDB( td.path() ) ); From a2f6782be3c831614fe513f8c570b1f1417db319 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 10 Jan 2024 21:59:09 +0200 Subject: [PATCH 139/159] Revert "Bug/skaled 1745 invalid fork in pow gas" --- libethcore/ChainOperationParams.h | 1 - libethereum/Block.cpp | 5 +- libethereum/ChainParams.cpp | 5 -- libethereum/Client.cpp | 19 +---- libethereum/ClientBase.cpp | 11 +-- libethereum/SkaleHost.cpp | 3 +- libethereum/Transaction.cpp | 26 ++---- libethereum/Transaction.h | 9 +- libethereum/ValidationSchemes.cpp | 2 - libskale/CMakeLists.txt | 2 - libskale/CorrectForkInPowPatch.cpp | 12 --- libskale/CorrectForkInPowPatch.h | 41 ---------- test/tools/libtesteth/BlockChainHelper.cpp | 10 --- test/tools/libtesteth/ImportTest.cpp | 41 +++++++++- test/tools/libtesteth/TestOutputHelper.cpp | 3 - test/unittests/libethereum/SkaleHost.cpp | 10 +-- .../libweb3jsonrpc/WebThreeStubClient.h | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 82 +------------------ 18 files changed, 66 insertions(+), 218 deletions(-) delete mode 100644 libskale/CorrectForkInPowPatch.cpp delete mode 100644 libskale/CorrectForkInPowPatch.h diff --git a/libethcore/ChainOperationParams.h b/libethcore/ChainOperationParams.h index 678619900..3e442229d 100644 --- a/libethcore/ChainOperationParams.h +++ b/libethcore/ChainOperationParams.h @@ -178,7 +178,6 @@ struct SChain { time_t precompiledConfigPatchTimestamp = 0; time_t pushZeroPatchTimestamp = 0; time_t skipInvalidTransactionsPatchTimestamp = 0; - time_t correctForkInPowPatchTimestamp = 0; SChain() { name = "TestChain"; diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index d98705d88..28e17ad0f 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -351,7 +351,7 @@ pair< TransactionReceipts, bool > Block::sync( // caller if we hit the limit for ( Transaction& transaction : transactions ) { - transaction.checkOutExternalGas( _bc.chainParams(), _bc.number() ); + transaction.checkOutExternalGas( _bc.chainParams().externalGasDifficulty ); } assert( _bc.currentHash() == m_currentBlock.parentHash() ); @@ -631,7 +631,8 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) { // << " (state #" // << state().getNonce( tr.from() ) << ") value = " << tr.value() << // endl; - const_cast< Transaction& >( tr ).checkOutExternalGas( _bc.chainParams(), _bc.number() ); + const_cast< Transaction& >( tr ).checkOutExternalGas( + _bc.chainParams().externalGasDifficulty ); execute( _bc.lastBlockHashes(), tr ); // cerr << "Now: " // << "State #" << state().getNonce( tr.from() ) << endl; diff --git a/libethereum/ChainParams.cpp b/libethereum/ChainParams.cpp index 52d3fade1..fec3da5a5 100644 --- a/libethereum/ChainParams.cpp +++ b/libethereum/ChainParams.cpp @@ -280,11 +280,6 @@ ChainParams ChainParams::loadConfig( sChainObj.at( "skipInvalidTransactionsPatchTimestamp" ).get_int64() : 0; - s.correctForkInPowPatchTimestamp = - sChainObj.count( "correctForkInPowPatchTimestamp" ) ? - sChainObj.at( "correctForkInPowPatchTimestamp" ).get_int64() : - 0; - if ( sChainObj.count( "nodeGroups" ) ) { std::vector< NodeGroup > nodeGroups; for ( const auto& nodeGroupConf : sChainObj["nodeGroups"].get_obj() ) { diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 832ab5508..8bf8af377 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -53,7 +53,6 @@ #include #include -#include #include #include #include @@ -170,7 +169,6 @@ Client::Client( ChainParams const& _params, int _networkID, SkipInvalidTransactionsPatch::setTimestamp( this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp ); PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp ); - CorrectForkInPowPatch::setTimestamp( chainParams().sChain.correctForkInPowPatchTimestamp ); } @@ -602,10 +600,6 @@ size_t Client::importTransactionsAsBlock( sealUnconditionally( false ); importWorkingBlock(); - // this needs to be updated as soon as possible, as it's used in new transactions validation - CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp(); - CorrectForkInPowPatch::lastBlockNumber = blockChain().number(); - if ( !UnsafeRegion::isActive() ) { LOG( m_loggerDetail ) << "Total unsafe time so far = " << std::chrono::duration_cast< std::chrono::seconds >( @@ -674,9 +668,6 @@ size_t Client::syncTransactions( PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp(); SkipInvalidTransactionsPatch::lastBlockTimestamp = blockChain().info().timestamp(); PrecompiledConfigPatch::lastBlockTimestamp = blockChain().info().timestamp(); - CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp(); - CorrectForkInPowPatch::lastBlockNumber = blockChain().number(); - DEV_WRITE_GUARDED( x_working ) { assert( !m_working.isSealed() ); @@ -1199,6 +1190,8 @@ h256 Client::importTransaction( Transaction const& _t ) { // the latest block in the client's blockchain. This can throw but // we'll catch the exception at the RPC level. + const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams().externalGasDifficulty ); + // throws in case of error State state; u256 gasBidPrice; @@ -1206,10 +1199,6 @@ h256 Client::importTransaction( Transaction const& _t ) { DEV_GUARDED( m_blockImportMutex ) { state = this->state().createStateReadOnlyCopy(); gasBidPrice = this->gasBidPrice(); - - // We need to check external gas under mutex to be sure about current block bumber - // correctness - const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() ); } Executive::verifyTransaction( _t, @@ -1266,7 +1255,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.ignoreExternalGas(); + t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) { historicBlock.mutableState().mutableHistoricState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); @@ -1291,7 +1280,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest, Transaction t( _value, gasPrice, gas, _dest, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainParams().chainID ); - t.ignoreExternalGas(); + t.checkOutExternalGas( ~u256( 0 ) ); if ( _ff == FudgeFactor::Lenient ) temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted ); diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 6b6d530b4..842556765 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -23,7 +23,6 @@ */ #include "ClientBase.h" -#include #include #include @@ -90,7 +89,7 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl t = Transaction( _value, _gasPrice, _gas, _data, nonce ); t.forceSender( _from ); t.forceChainId( chainId() ); - t.ignoreExternalGas(); + t.checkOutExternalGas( ~u256( 0 ) ); EnvInfo const env( _latestBlock.info(), bc().lastBlockHashes(), 0, _gas ); // Make a copy of state!! It will be deleted after step! State tempState = _latestBlock.mutableState(); @@ -116,12 +115,8 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from int64_t upperBound = _maxGas; if ( upperBound == Invalid256 || upperBound > c_maxGasEstimate ) upperBound = c_maxGasEstimate; - int64_t lowerBound = - CorrectForkInPowPatch::isEnabled() ? - Transaction::baseGasRequired( !_dest, &_data, - bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ) : - Transaction::baseGasRequired( !_dest, &_data, EVMSchedule() ); - + int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data, + bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ); Block bk = latestBlock(); if ( upperBound > bk.info().gasLimit() ) { upperBound = bk.info().gasLimit().convert_to< int64_t >(); diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 54c82d9c2..68794f5b5 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -644,7 +644,6 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // TODO clear occasionally this cache?! if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { Transaction t = m_m_transaction_cache.at( sha.asArray() ); - t.checkOutExternalGas( m_client.chainParams(), m_client.number(), true ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); @@ -658,7 +657,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro // ).detach(); } else { Transaction t( data, CheckTransaction::Everything, true ); - t.checkOutExternalGas( m_client.chainParams(), m_client.number() ); + 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" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index de556a0f9..1645c30c3 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -29,7 +29,6 @@ #include #include #include -#include using namespace std; using namespace dev; @@ -181,32 +180,19 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force ) { - u256 const& difficulty = _cp.externalGasDifficulty; - assert( difficulty > 0 ); - if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) { +void Transaction::checkOutExternalGas( u256 const& _difficulty ) { + assert( _difficulty > 0 ); + if ( !m_externalGasIsChecked && !isInvalid() ) { h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); if ( !hash ) { hash = h256( 1 ); } - u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty; + u256 externalGas = ~u256( 0 ) / u256( hash ) / _difficulty; if ( externalGas > 0 ) ctrace << "Mined gas: " << externalGas << endl; - - EVMSchedule scheduleForUse = ConstantinopleSchedule; - if ( CorrectForkInPowPatch::isEnabled() ) - scheduleForUse = _cp.scheduleForBlockNumber( _bn ); - - // never call checkOutExternalGas with non-last block - if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) { - ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber(); - BOOST_THROW_EXCEPTION( std::runtime_error( - "Internal error: checkOutExternalGas() has invalid block number" ) ); - } - - if ( externalGas >= baseGasRequired( scheduleForUse ) ) + if ( externalGas >= baseGasRequired( ConstantinopleSchedule ) ) { m_externalGas = externalGas; - + } m_externalGasIsChecked = true; } } diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index dffadb347..6764bce5a 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -29,8 +29,6 @@ #include #include -#include "ChainParams.h" - namespace dev { namespace eth { @@ -122,12 +120,7 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force = false ); - - void ignoreExternalGas() { - m_externalGasIsChecked = true; - m_externalGas = 0; - } + void checkOutExternalGas( u256 const& _difficulty ); private: bool m_externalGasIsChecked = false; diff --git a/libethereum/ValidationSchemes.cpp b/libethereum/ValidationSchemes.cpp index 1f7243e31..75bd07af1 100644 --- a/libethereum/ValidationSchemes.cpp +++ b/libethereum/ValidationSchemes.cpp @@ -274,8 +274,6 @@ void validateConfigJson( js::mObject const& _obj ) { { "skipInvalidTransactionsPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } }, { "precompiledConfigPatchTimestamp", - { { js::int_type }, JsonFieldPresence::Optional } }, - { "correctForkInPowPatchTimestamp", { { js::int_type }, JsonFieldPresence::Optional } } } ); js::mArray const& nodes = sChain.at( "nodes" ).get_array(); diff --git a/libskale/CMakeLists.txt b/libskale/CMakeLists.txt index 1a0fb8ff1..aec50d6e0 100644 --- a/libskale/CMakeLists.txt +++ b/libskale/CMakeLists.txt @@ -23,7 +23,6 @@ set(sources PrecompiledConfigPatch.cpp PushZeroPatch.cpp SkipInvalidTransactionsPatch.cpp - CorrectForkInPowPatch.cpp ) set(headers @@ -45,7 +44,6 @@ set(headers PrecompiledConfigPatch.h OverlayFS.h SkipInvalidTransactionsPatch.h - CorrectForkInPowPatch.h ) add_library(skale ${sources} ${headers}) diff --git a/libskale/CorrectForkInPowPatch.cpp b/libskale/CorrectForkInPowPatch.cpp deleted file mode 100644 index aec18bc29..000000000 --- a/libskale/CorrectForkInPowPatch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "CorrectForkInPowPatch.h" - -time_t CorrectForkInPowPatch::activationTimestamp; -time_t CorrectForkInPowPatch::lastBlockTimestamp; -unsigned CorrectForkInPowPatch::lastBlockNumber; - -bool CorrectForkInPowPatch::isEnabled() { - if ( activationTimestamp == 0 ) { - return false; - } - return activationTimestamp <= lastBlockTimestamp; -} diff --git a/libskale/CorrectForkInPowPatch.h b/libskale/CorrectForkInPowPatch.h deleted file mode 100644 index 94c0f766e..000000000 --- a/libskale/CorrectForkInPowPatch.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CORRECTFORKINPOWPATCH_H -#define CORRECTFORKINPOWPATCH_H - -#include - -#include - -namespace dev { -namespace eth { -class Client; -} -namespace test { -class TestBlockChain; -class TestOutputHelperFixture; -} // namespace test -} // namespace dev - -/* - * Context: use current, and not Constantinople, fork in Transaction::checkOutExternalGas() - */ -class CorrectForkInPowPatch : public SchainPatch { -public: - static bool isEnabled(); - - static void setTimestamp( time_t _timeStamp ) { - printInfo( __FILE__, _timeStamp ); - activationTimestamp = _timeStamp; - } - - static unsigned getLastBlockNumber() { return lastBlockNumber; } - -private: - friend class dev::eth::Client; - friend class dev::test::TestBlockChain; - friend class dev::test::TestOutputHelperFixture; - static time_t activationTimestamp; - static time_t lastBlockTimestamp; - static unsigned lastBlockNumber; -}; - -#endif // CORRECTFORKINPOWPATCH_H diff --git a/test/tools/libtesteth/BlockChainHelper.cpp b/test/tools/libtesteth/BlockChainHelper.cpp index 757ac6169..fbdaf71be 100644 --- a/test/tools/libtesteth/BlockChainHelper.cpp +++ b/test/tools/libtesteth/BlockChainHelper.cpp @@ -21,8 +21,6 @@ * that manage block/transaction import and test mining */ -#include - #include #include #include @@ -475,10 +473,6 @@ void TestBlockChain::reset( TestBlock const& _genesisBlock ) { } bool TestBlockChain::addBlock( TestBlock const& _block ) { - - CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp(); - CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number(); - while ( true ) { try { _block.verify( *this ); // check that block header match TestBlock contents @@ -500,10 +494,6 @@ bool TestBlockChain::addBlock( TestBlock const& _block ) { State st( block.state() ); m_lastBlock.setState( st ); - - CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp(); - CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number(); - return true; } diff --git a/test/tools/libtesteth/ImportTest.cpp b/test/tools/libtesteth/ImportTest.cpp index 7ecf2283d..8400ed13c 100644 --- a/test/tools/libtesteth/ImportTest.cpp +++ b/test/tools/libtesteth/ImportTest.cpp @@ -111,9 +111,36 @@ void ImportTest::makeBlockchainTestFromStateTest( set< eth::Network > const& _ne TrExpectSection* search2 = &search; checkGeneralTestSectionSearch( exp.get_obj(), stateIndexesToPrint, "", search2 ); throw std::logic_error( "Skale state does not support addresses list" ); - + // if (search.second.first.addresses().size() != 0) // if match in + // the expect sections + // // for this tr + // found + // { + // // replace expected mining reward (in state tests it is 0) + // json_spirit::mObject obj = + // fillJsonWithState(search2->second.first, + // search2->second.second); + // for (auto& adr : obj) + // { + // if (adr.first == toHexPrefixed(m_envInfo->author()) && + // adr.second.get_obj().count("balance")) + // { + // u256 expectCoinbaseBalance = + // toInt(adr.second.get_obj()["balance"]); + // expectCoinbaseBalance += blockReward; + // adr.second.get_obj()["balance"] = + // toCompactHexPrefixed(expectCoinbaseBalance); + // } + // } + + // json_spirit::mObject expetSectionObj; + // expetSectionObj["network"] = test::netIdToString(net); + // expetSectionObj["result"] = obj; + // expetSectionArray.push_back(expetSectionObj); + // break; + // } } // for exp - } // for net + } // for net testObj["expect"] = expetSectionArray; @@ -198,6 +225,7 @@ bytes ImportTest::executeTest( bool _isFilling ) { continue; for ( auto& tr : m_transactions ) { + tr.transaction.checkOutExternalGas( 100 ); Options const& opt = Options::get(); if ( opt.trDataIndex != -1 && opt.trDataIndex != tr.dataInd ) continue; @@ -711,6 +739,15 @@ bool ImportTest::checkGeneralTestSectionSearch( json_spirit::mObject const& _exp _errorTransactions.push_back( i ); } } else if ( _expects.count( "hash" ) ) { + // checking filled state test against client + // BOOST_CHECK_MESSAGE(_expects.at("hash").get_str() == + // toHexPrefixed(tr.postState.globalRoot().asBytes()), + // TestOutputHelper::get().testName() + " on " + + // test::netIdToString(tr.netId) + + // ": Expected another postState hash! expected: " + + // _expects.at("hash").get_str() + " actual: " + + // toHexPrefixed(tr.postState.globalRoot().asBytes()) + + // " in " + trInfo); if ( _expects.count( "logs" ) ) BOOST_CHECK_MESSAGE( _expects.at( "logs" ).get_str() == exportLog( tr.output.second.log() ), diff --git a/test/tools/libtesteth/TestOutputHelper.cpp b/test/tools/libtesteth/TestOutputHelper.cpp index f5ec7cdf2..c863fa0fd 100644 --- a/test/tools/libtesteth/TestOutputHelper.cpp +++ b/test/tools/libtesteth/TestOutputHelper.cpp @@ -20,7 +20,6 @@ * Fixture class for boost output when running testeth */ -#include #include #include #include @@ -103,8 +102,6 @@ void TestOutputHelper::printTestExecStats() { } TestOutputHelperFixture::TestOutputHelperFixture() { TestOutputHelper::get().initTest(); - CorrectForkInPowPatch::lastBlockTimestamp = 1; - CorrectForkInPowPatch::lastBlockNumber = 0; } TestOutputHelperFixture::~TestOutputHelperFixture() { diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 84243ab98..7870cd7c9 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -123,7 +123,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { chainParams.allowFutureBlocks = true; chainParams.difficulty = chainParams.minimumDifficulty; chainParams.gasLimit = chainParams.maxGasLimit; - chainParams.istanbulForkBlock = 0; + chainParams.byzantiumForkBlock = 0; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -913,7 +913,7 @@ BOOST_AUTO_TEST_CASE( transactionDropReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -970,7 +970,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue, // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -1027,7 +1027,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPrice // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); // submit it! tq->import( tx1 ); @@ -1090,7 +1090,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPriceReceive // 1st tx Transaction tx1 = tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->number() ); + tx1.checkOutExternalGas( client->chainParams().difficulty ); RLPStream stream1; tx1.streamRLP( stream1 ); diff --git a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h index 5f56db895..a97f41d25 100644 --- a/test/unittests/libweb3jsonrpc/WebThreeStubClient.h +++ b/test/unittests/libweb3jsonrpc/WebThreeStubClient.h @@ -57,7 +57,7 @@ class WebThreeStubClient : public jsonrpc::Client { std::string eth_call( const Json::Value& param1, const std::string& param2 ) noexcept( false ); std::string eth_callEIP1898( const Json::Value& param1, const Json::Value& param2 ) noexcept( false ); bool eth_flush() noexcept( false ); - std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "latest" ) noexcept( false ); + std::string eth_estimateGas( const Json::Value& param1, const std::string& param2 = "" ) noexcept( false ); Json::Value eth_getBlockByHash( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getBlockByNumber( const std::string& param1, bool param2 ) noexcept( false ); Json::Value eth_getTransactionByHash( const std::string& param1 ) noexcept( false ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 0f683f344..7640a5b24 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -248,7 +248,7 @@ 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, bool _isSyncNode = false, int _emptyBlockIntervalMs = -1 ) { + bool _mtmEnabled = false, bool _isSyncNode = false ) { dev::p2p::NetworkPreferences nprefs; ChainParams chainParams; @@ -289,9 +289,6 @@ struct JsonRpcFixture : public TestOutputHelperFixture { // 615 + 1430 is experimentally-derived block size + average extras size chainParams.sChain.dbStorageLimit = 320.5*( 615 + 1430 ); chainParams.sChain.contractStoragePatchTimestamp = 1; - powPatchActivationTimestamp = time(nullptr) + 20; - chainParams.sChain.correctForkInPowPatchTimestamp = powPatchActivationTimestamp; // 10 guessed seconds - chainParams.sChain.emptyBlockIntervalMs = _emptyBlockIntervalMs; // add random extra data to randomize genesis hash and get random DB path, // so that tests can be run in parallel // TODO: better make it use ethemeral in-memory databases @@ -419,7 +416,6 @@ struct JsonRpcFixture : public TestOutputHelperFixture { unique_ptr< WebThreeStubClient > rpcClient; std::string adminSession; SkaleServerOverride* skale_server_connector; - time_t powPatchActivationTimestamp; }; struct RestrictedAddressFixture : public JsonRpcFixture { @@ -1602,78 +1598,6 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { responseString, "0x000000000000000000000000112233445566778899aabbccddeeff0011223344" ); } -BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { - // 1s empty block interval - JsonRpcFixture fixture( "", true, true, false, false, false, 1000 ); - dev::eth::simulateMining( *( fixture.client ), 1 ); - - auto senderAddress = fixture.coinbase.address(); - - Json::Value transact; - transact["from"] = toJS( senderAddress ); - transact["to"] = toJS( senderAddress ); - // 1k - ostringstream ss("0x"); - for(int i=0; i<1024/16; ++i) - ss << "112233445566778899aabbccddeeff11"; - transact["data"] = ss.str(); - - string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); - u256 gasEstimate = jsToU256(gasEstimateStr); - - // old estimate before patch - BOOST_REQUIRE_EQUAL(gasEstimate, u256(21000+1024*68)); - - u256 powGasPrice = 0; - u256 correctEstimate = u256(21000+1024*16); - do { - const u256 GAS_PER_HASH = 1; - u256 candidate = h256::random(); - h256 hash = dev::sha3( senderAddress ) ^ dev::sha3( u256( 0 ) ) ^ dev::sha3( candidate ); - u256 externalGas = ~u256( 0 ) / u256( hash ) * GAS_PER_HASH; - if ( externalGas >= correctEstimate && externalGas < correctEstimate + correctEstimate/10 ) { - powGasPrice = candidate; - } - } while ( !powGasPrice ); - // Account balance is too low will mean that PoW didn't work out - transact["gasPrice"] = toJS( powGasPrice ); - - // wait for patch turning on and see how it happens - string txHash; - BlockHeader badInfo, goodInfo; - for(;;) { - string gasEstimateStr = fixture.rpcClient->eth_estimateGas(transact); - u256 gasEstimate = jsToU256(gasEstimateStr); - // old - if(gasEstimate == u256(21000+1024*68)){ - try{ - fixture.rpcClient->eth_sendTransaction( transact ); - BOOST_REQUIRE(false); - } catch(const std::exception& ex) { - assert(string(ex.what()).find("balance is too low") != string::npos); - badInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); - dev::eth::mineTransaction( *( fixture.client ), 1 ); // empty block - } // catch - } - // new - else { - BOOST_REQUIRE_EQUAL(gasEstimate, correctEstimate); - txHash = fixture.rpcClient->eth_sendTransaction( transact ); - goodInfo = fixture.client->blockInfo(fixture.client->hashFromNumber(LatestBlock)); - break; - } // else - } // for - - BOOST_REQUIRE_LT(badInfo.timestamp(), fixture.powPatchActivationTimestamp); - BOOST_REQUIRE_GE(goodInfo.timestamp(), fixture.powPatchActivationTimestamp); - BOOST_REQUIRE_EQUAL(badInfo.number()+1, goodInfo.number()); - - dev::eth::mineTransaction( *( fixture.client ), 1 ); - - Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); -} - BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); @@ -3391,7 +3315,7 @@ BOOST_AUTO_TEST_CASE( test_transactions ) { Transaction valid( fromHex( "0xf86c808504a817c80083015f90943d7112ee86223baf0a506b9d2a77595cbbba51d1872386f26fc10000801ca0655757fd0650a65a373c48a4dc0f3d6ac5c3831aa0cc2cb863a5909dc6c25f72a071882ee8633466a243c0ea64dadb3120c1ca7a5cc7433c6c0b1c861a85322265" ), CheckTransaction::None ); - valid.ignoreExternalGas(); + valid.checkOutExternalGas( 1 ); client->importTransactionsAsBlock(Transactions{invalid, valid}, 1); @@ -3419,7 +3343,7 @@ BOOST_AUTO_TEST_CASE( test_exceptions ) { Transaction valid( fromHex( "0xf86c808504a817c80083015f90943d7112ee86223baf0a506b9d2a77595cbbba51d1872386f26fc10000801ca0655757fd0650a65a373c48a4dc0f3d6ac5c3831aa0cc2cb863a5909dc6c25f72a071882ee8633466a243c0ea64dadb3120c1ca7a5cc7433c6c0b1c861a85322265" ), CheckTransaction::None ); - valid.ignoreExternalGas(); + valid.checkOutExternalGas( 1 ); client->importTransactionsAsBlock(Transactions{invalid, valid}, 1); From 6a14d05f30112a2ea103c09de5c6921eb22e7cca Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 10 Jan 2024 20:25:57 +0000 Subject: [PATCH 140/159] SKALED-1745 Init patch timestamp in Client::init (to prevent failure) --- libethereum/Client.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 832ab5508..f2c34239f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -333,6 +333,10 @@ void Client::init( WithExisting _forceAction, u256 _networkId ) { // HACK Needed to set env var for consensus AmsterdamFixPatch::isEnabled( *this ); + // needed for checkOutExternalGas + CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp(); + CorrectForkInPowPatch::lastBlockNumber = blockChain().number(); + initCPUUSage(); doWork( false ); From 7469839b079e9deab6c6b24d813d71c732e84231 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 11 Jan 2024 13:19:17 +0000 Subject: [PATCH 141/159] #1588 fix new snapshot hash calculation --- libdevcore/LevelDB.cpp | 1 - libskale/SnapshotManager.cpp | 7 ++-- skaled/main.cpp | 2 +- test/unittests/libweb3core/LevelDBHash.cpp | 42 ++++++++++++++++------ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index cb6fba758..91791b554 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -212,7 +212,6 @@ void LevelDB::forEach( std::function< bool( Slice, Slice ) > f ) const { } } - void LevelDB::forEachWithPrefix( std::string& _prefix, std::function< bool( Slice, Slice ) > f ) const { cnote << "Iterating over the LevelDB prefix: " << _prefix; diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index 04c7cd0be..58d0afbe0 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -445,8 +445,11 @@ void SnapshotManager::computeDatabaseHash( BOOST_THROW_EXCEPTION( InvalidPath( _dbDir ) ); } - std::array< std::string, 17 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", "6", - "7", "8", "9", "a", "b", "c", "d", "e", "f", "g" }; + // std::array< std::string, 23 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", + // "6", + // "7", "8", "9", "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f", "{" }; + std::array< std::string, 11 > lexographicKeysSegments = { "0", "2", "4", "6", "8", "A", "F", + "a", "c", "e", "{" }; secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); diff --git a/skaled/main.cpp b/skaled/main.cpp index 381cda01f..27469a750 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -460,7 +460,7 @@ bool tryDownloadSnapshot( std::shared_ptr< SnapshotManager >& snapshotManager, "hash " ) << cc::notice( votedHash.first.hex() ) << cc::notice( " is not equal to calculated hash " ) - << cc::notice( calculated_hash.hex() ) << cc::notice( "Will try again" ); + << cc::notice( calculated_hash.hex() ) << cc::notice( " Will try again" ); if ( isRegularSnapshot ) snapshotManager->cleanup(); else diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index bbecf1249..0e77f86b9 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -9,36 +9,51 @@ BOOST_AUTO_TEST_SUITE( LevelDBHashBase ) BOOST_AUTO_TEST_CASE( hash ) { dev::TransientDirectory td; + std::vector< std::pair< std::string, std::string > > randomKeysValues(123); + dev::h256 hash; { std::unique_ptr< dev::db::LevelDB > db( new dev::db::LevelDB( td.path() ) ); BOOST_REQUIRE( db ); + db->insert( dev::db::Slice( "PieceUsageBytes" ), dev::db::Slice( "123456789" ) ); + db->insert( dev::db::Slice( "ppieceUsageBytes" ), dev::db::Slice( "123456789" ) ); + for ( size_t i = 0; i < 123; ++i ) { - std::string key = std::to_string( 43 + i ); - std::string value = std::to_string( i ); + std::string key = dev::h256::random().hex(); + std::string value = dev::h256::random().hex(); db->insert( dev::db::Slice(key), dev::db::Slice(value) ); + + randomKeysValues[i] = { key, value }; } hash = db->hashBase(); } + boost::filesystem::remove_all( td.path() ); + BOOST_REQUIRE( !boost::filesystem::exists( td.path() ) ); + dev::h256 hash_same; { std::unique_ptr< dev::db::LevelDB > db_copy( new dev::db::LevelDB( td.path() ) ); BOOST_REQUIRE( db_copy ); for ( size_t i = 0; i < 123; ++i ) { - std::string key = std::to_string( 43 + i ); - std::string value = std::to_string( i ); + std::string key = randomKeysValues[i].first; + std::string value = randomKeysValues[i].second; db_copy->insert( dev::db::Slice(key), dev::db::Slice(value) ); } + db_copy->insert( dev::db::Slice( "PieceUsageBytes" ), dev::db::Slice( "123456789" ) ); + db_copy->insert( dev::db::Slice( "ppieceUsageBytes" ), dev::db::Slice( "123456789" ) ); hash_same = db_copy->hashBase(); } BOOST_REQUIRE( hash == hash_same ); + boost::filesystem::remove_all( td.path() ); + BOOST_REQUIRE( !boost::filesystem::exists( td.path() ) ); + dev::h256 hashPartially; { { @@ -46,15 +61,17 @@ BOOST_AUTO_TEST_CASE( hash ) { BOOST_REQUIRE( db_copy ); for ( size_t i = 0; i < 123; ++i ) { - std::string key = std::to_string( 43 + i ); - std::string value = std::to_string( i ); + std::string key = randomKeysValues[i].first; + std::string value = randomKeysValues[i].second; db_copy->insert( dev::db::Slice(key), dev::db::Slice(value) ); } + + db_copy->insert( dev::db::Slice( "PieceUsageBytes" ), dev::db::Slice( "123456789" ) ); + db_copy->insert( dev::db::Slice( "ppieceUsageBytes" ), dev::db::Slice( "123456789" ) ); } - std::array< std::string, 17 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", "6", - "7", "8", "9", "a", "b", "c", "d", - "e", "f", "g" }; + std::array< std::string, 11 > lexographicKeysSegments = { "0", "2", "4", "6", "8", "A", + "F", "a", "c", "e", "{" }; secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); @@ -72,14 +89,17 @@ BOOST_AUTO_TEST_CASE( hash ) { BOOST_REQUIRE( hash == hashPartially ); + boost::filesystem::remove_all( td.path() ); + BOOST_REQUIRE( !boost::filesystem::exists( td.path() ) ); + dev::h256 hash_diff; { std::unique_ptr< dev::db::LevelDB > db_diff( new dev::db::LevelDB( td.path() ) ); BOOST_REQUIRE( db_diff ); for ( size_t i = 0; i < 123; ++i ) { - std::string key = std::to_string( 42 + i ); - std::string value = std::to_string( i ); + std::string key = dev::h256::random().hex(); + std::string value = dev::h256::random().hex(); db_diff->insert( dev::db::Slice(key), dev::db::Slice(value) ); } From 1bf2cd7bc15e2a0a71d5601a406ef6ae56091573 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 12 Jan 2024 13:46:21 +0000 Subject: [PATCH 142/159] #1588 change snapshot hash computation --- libdevcore/LevelDB.cpp | 11 +++++++---- libskale/SnapshotManager.cpp | 12 +++++++----- test/unittests/libweb3core/LevelDBHash.cpp | 9 +++++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index 91791b554..0025cf022 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -236,6 +236,7 @@ h256 LevelDB::hashBase() const { if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); } + secp256k1_sha256_t ctx; secp256k1_sha256_initialize( &ctx ); for ( it->SeekToFirst(); it->Valid(); it->Next() ) { @@ -251,6 +252,7 @@ h256 LevelDB::hashBase() const { bytesConstRef str_key_value( usc.data(), usc.size() ); secp256k1_sha256_write( &ctx, str_key_value.data(), str_key_value.size() ); } + h256 hash; secp256k1_sha256_finalize( &ctx, hash.data() ); return hash; @@ -285,6 +287,7 @@ void LevelDB::hashBasePartially( if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); } + for ( it->Seek( start ); it->Valid() && it->key().ToString() < finish; it->Next() ) { std::string key_ = it->key().ToString(); std::string value_ = it->value().ToString(); @@ -293,10 +296,10 @@ void LevelDB::hashBasePartially( // TODO Move this logic to separate "compatiliblity layer"! if ( key_ == "pieceUsageBytes" ) continue; - std::string key_value = key_ + value_; - const std::vector< uint8_t > usc( key_value.begin(), key_value.end() ); - bytesConstRef str_key_value( usc.data(), usc.size() ); - secp256k1_sha256_write( ctx, str_key_value.data(), str_key_value.size() ); + std::string keyValue = key_ + value_; + const std::vector< uint8_t > usc( keyValue.begin(), keyValue.end() ); + bytesConstRef strKeyValue( usc.data(), usc.size() ); + secp256k1_sha256_write( ctx, strKeyValue.data(), strKeyValue.size() ); } } diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index 58d0afbe0..c6e495c74 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -445,11 +445,13 @@ void SnapshotManager::computeDatabaseHash( BOOST_THROW_EXCEPTION( InvalidPath( _dbDir ) ); } - // std::array< std::string, 23 > lexographicKeysSegments = { "0", "1", "2", "3", "4", "5", - // "6", - // "7", "8", "9", "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f", "{" }; - std::array< std::string, 11 > lexographicKeysSegments = { "0", "2", "4", "6", "8", "A", "F", - "a", "c", "e", "{" }; + std::array< std::string, 17 > lexographicKeysSegments = { std::string( 1, char( 0 ) ), + std::string( 1, char( 16 ) ), std::string( 1, char( 32 ) ), std::string( 1, char( 48 ) ), + std::string( 1, char( 64 ) ), std::string( 1, char( 80 ) ), std::string( 1, char( 96 ) ), + std::string( 1, char( 112 ) ), std::string( 1, char( 128 ) ), std::string( 1, char( 144 ) ), + std::string( 1, char( 160 ) ), std::string( 1, char( 176 ) ), std::string( 1, char( 192 ) ), + std::string( 1, char( 208 ) ), std::string( 1, char( 224 ) ), std::string( 1, char( 240 ) ), + std::string( 1000, char( 255 ) ) }; secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index 0e77f86b9..f1140f8a1 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -70,8 +70,13 @@ BOOST_AUTO_TEST_CASE( hash ) { db_copy->insert( dev::db::Slice( "ppieceUsageBytes" ), dev::db::Slice( "123456789" ) ); } - std::array< std::string, 11 > lexographicKeysSegments = { "0", "2", "4", "6", "8", "A", - "F", "a", "c", "e", "{" }; + std::array< std::string, 17 > lexographicKeysSegments = { std::string( 1, char( 0 ) ), + std::string( 1, char( 16 ) ), std::string( 1, char( 32 ) ), std::string( 1, char( 48 ) ), + std::string( 1, char( 64 ) ), std::string( 1, char( 80 ) ), std::string( 1, char( 96 ) ), + std::string( 1, char( 112 ) ), std::string( 1, char( 128 ) ), std::string( 1, char( 144 ) ), + std::string( 1, char( 160 ) ), std::string( 1, char( 176 ) ), std::string( 1, char( 192 ) ), + std::string( 1, char( 208 ) ), std::string( 1, char( 224 ) ), std::string( 1, char( 240 ) ), + std::string( 1000, char( 255 ) ) }; secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); From 9431fab06e454694cb569948b70fab2cabb00cf3 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 12 Jan 2024 18:53:42 +0000 Subject: [PATCH 143/159] IS-902 check block number to download snapshot --- libweb3jsonrpc/Skale.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libweb3jsonrpc/Skale.cpp b/libweb3jsonrpc/Skale.cpp index 763c3af6c..40904ac46 100644 --- a/libweb3jsonrpc/Skale.cpp +++ b/libweb3jsonrpc/Skale.cpp @@ -158,6 +158,10 @@ nlohmann::json Skale::impl_skale_getSnapshot( const nlohmann::json& joRequest, C // TODO check unsigned blockNumber = joRequest["blockNumber"].get< unsigned >(); + if ( blockNumber != m_client.getLatestSnapshotBlockNumer() ) { + joResponse["error"] = "Wrong snapshot block number requested."; + return joResponse; + } // exit if too early if ( currentSnapshotBlockNumber >= 0 ) { From aab2420511525adef6cbea434af66573425f339b Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 16 Jan 2024 13:40:30 +0000 Subject: [PATCH 144/159] IS 902 handle wrong snapshot block number request for signatures --- libweb3jsonrpc/Skale.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Skale.cpp b/libweb3jsonrpc/Skale.cpp index 40904ac46..492e25fc8 100644 --- a/libweb3jsonrpc/Skale.cpp +++ b/libweb3jsonrpc/Skale.cpp @@ -159,7 +159,7 @@ nlohmann::json Skale::impl_skale_getSnapshot( const nlohmann::json& joRequest, C // TODO check unsigned blockNumber = joRequest["blockNumber"].get< unsigned >(); if ( blockNumber != m_client.getLatestSnapshotBlockNumer() ) { - joResponse["error"] = "Wrong snapshot block number requested."; + joResponse["error"] = "Invalid snapshot block number requested - it might be deleted."; return joResponse; } @@ -370,6 +370,11 @@ Json::Value Skale::skale_getSnapshotSignature( unsigned blockNumber ) { if ( chainParams.nodeInfo.keyShareName.empty() || chainParams.nodeInfo.sgxServerUrl.empty() ) throw jsonrpc::JsonRpcException( "Snapshot signing is not enabled" ); + if ( blockNumber != this->m_client.getLatestSnapshotBlockNumer() ) { + throw jsonrpc::JsonRpcException( + "Invalid snapshot block number requested - it might be deleted." ); + } + try { dev::h256 snapshot_hash = this->m_client.getSnapshotHash( blockNumber ); if ( !snapshot_hash ) From c4cffb1abd48a3005a1f1d522d3ec39563cb30ea Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 16 Jan 2024 15:34:46 +0000 Subject: [PATCH 145/159] #1588 change snapshot hash computation --- libdevcore/LevelDB.cpp | 15 +++++++++++++-- libdevcore/LevelDB.h | 2 +- libskale/SnapshotManager.cpp | 15 ++++----------- test/unittests/libweb3core/LevelDBHash.cpp | 15 ++++----------- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index 0025cf022..dda5756ef 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -282,13 +282,18 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { } void LevelDB::hashBasePartially( - secp256k1_sha256_t* ctx, const std::string& start, const std::string& finish ) const { + secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize ) const { std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) ); if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); } - for ( it->Seek( start ); it->Valid() && it->key().ToString() < finish; it->Next() ) { + if ( lastHashedKey != "start" ) + it->Seek( lastHashedKey ); + else + it->SeekToFirst(); + + for ( size_t counter = 0; it->Valid() && counter < batchSize; it->Next() ) { std::string key_ = it->key().ToString(); std::string value_ = it->value().ToString(); // HACK! For backward compatibility! When snapshot could happen between update of two nodes @@ -300,7 +305,13 @@ void LevelDB::hashBasePartially( const std::vector< uint8_t > usc( keyValue.begin(), keyValue.end() ); bytesConstRef strKeyValue( usc.data(), usc.size() ); secp256k1_sha256_write( ctx, strKeyValue.data(), strKeyValue.size() ); + ++counter; } + + if ( it->Valid() ) + lastHashedKey = it->key().ToString(); + else + lastHashedKey = "stop"; } void LevelDB::doCompaction() const { diff --git a/libdevcore/LevelDB.h b/libdevcore/LevelDB.h index 470f318dd..01461f4c7 100644 --- a/libdevcore/LevelDB.h +++ b/libdevcore/LevelDB.h @@ -62,7 +62,7 @@ class LevelDB : public DatabaseFace { h256 hashBaseWithPrefix( char _prefix ) const; void hashBasePartially( - secp256k1_sha256_t* ctx, const std::string& start, const std::string& finish ) const; + secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize = 10000 ) const; void doCompaction() const; diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index c6e495c74..5e6e5660a 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -445,24 +445,17 @@ void SnapshotManager::computeDatabaseHash( BOOST_THROW_EXCEPTION( InvalidPath( _dbDir ) ); } - std::array< std::string, 17 > lexographicKeysSegments = { std::string( 1, char( 0 ) ), - std::string( 1, char( 16 ) ), std::string( 1, char( 32 ) ), std::string( 1, char( 48 ) ), - std::string( 1, char( 64 ) ), std::string( 1, char( 80 ) ), std::string( 1, char( 96 ) ), - std::string( 1, char( 112 ) ), std::string( 1, char( 128 ) ), std::string( 1, char( 144 ) ), - std::string( 1, char( 160 ) ), std::string( 1, char( 176 ) ), std::string( 1, char( 192 ) ), - std::string( 1, char( 208 ) ), std::string( 1, char( 224 ) ), std::string( 1, char( 240 ) ), - std::string( 1000, char( 255 ) ) }; - secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); - for ( size_t i = 0; i < lexographicKeysSegments.size() - 1; ++i ) { + std::string finishKey = "start"; + + while ( finishKey != "stop" ) { std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( _dbDir.string(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( - &dbCtx, lexographicKeysSegments[i], lexographicKeysSegments[i + 1] ); + m_db->hashBasePartially( &dbCtx, finishKey ); } dev::h256 dbHash; diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index f1140f8a1..0756d0678 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -70,23 +70,16 @@ BOOST_AUTO_TEST_CASE( hash ) { db_copy->insert( dev::db::Slice( "ppieceUsageBytes" ), dev::db::Slice( "123456789" ) ); } - std::array< std::string, 17 > lexographicKeysSegments = { std::string( 1, char( 0 ) ), - std::string( 1, char( 16 ) ), std::string( 1, char( 32 ) ), std::string( 1, char( 48 ) ), - std::string( 1, char( 64 ) ), std::string( 1, char( 80 ) ), std::string( 1, char( 96 ) ), - std::string( 1, char( 112 ) ), std::string( 1, char( 128 ) ), std::string( 1, char( 144 ) ), - std::string( 1, char( 160 ) ), std::string( 1, char( 176 ) ), std::string( 1, char( 192 ) ), - std::string( 1, char( 208 ) ), std::string( 1, char( 224 ) ), std::string( 1, char( 240 ) ), - std::string( 1000, char( 255 ) ) }; - secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); - for (size_t i = 0; i < lexographicKeysSegments.size() - 1; ++i) { - std::unique_ptr< dev::db::LevelDB > db( new dev::db::LevelDB( td.path(), + std::string finishKey = "start"; + while ( finishKey != "stop" ) { + std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( td.path(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - db->hashBasePartially( &dbCtx, lexographicKeysSegments[i], lexographicKeysSegments[i + 1] ); + m_db->hashBasePartially( &dbCtx, finishKey, 10 ); } secp256k1_sha256_finalize( &dbCtx, hashPartially.data() ); From 99a645a241646e1658ad108e7c1a70500e4e6e3a Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 11:59:23 +0000 Subject: [PATCH 146/159] fix tests --- .github/workflows/test.yml | 180 +++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88d95350a..f3943c70b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -166,55 +166,57 @@ jobs: ccache --show-stats - name: Testeth verbosity 1 run : | + mkdir -p /tmp/tests/ + rm -rf /tmp/tests/* #first run with verbosity 1. If test fails, rerun with verbosity 4 cd build/test export NO_NTP_CHECK=1 - export NO_ULIMIT_CHECK=1 + export NO_ULIMIT_CHECK=1 # we specifically run each test for easier log review - ./testeth -t BlockchainTests -- --express && touch /tmp/BlockchainTestsPassed - ./testeth -t TransitionTests -- --express && touch /tmp/TransitionTestsPassed - ./testeth -t TransactionTests -- --express && touch /tmp/TransactionTestsPassed - ./testeth -t VMTests -- --express && touch /tmp/VMTestsPassed - ./testeth -t LevelDBTests -- --express && touch /tmp/LevelDBTestsPassed - ./testeth -t CoreLibTests -- --express && touch /tmp/CoreLibTestsPassed - ./testeth -t RlpTests -- --express && touch /tmp/RlpTestsPassed - ./testeth -t SharedSpaceTests -- --express && touch /tmp/SharedSpaceTestsPassed - ./testeth -t EthashTests -- --express && touch /tmp/EthashTestsPassed - ./testeth -t SealEngineTests -- --express && touch /tmp/SealEngineTestsPassed - ./testeth -t DifficultyTests -- --express && touch /tmp/DifficultyTestsPassed - ./testeth -t BlockSuite -- --express && touch /tmp/BlockSuitePassed - ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/BlockChainMainNetworkSuitePassed - ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/BlockChainFrontierSuitePassed - ./testeth -t BlockQueueSuite -- --express && touch /tmp/BlockQueueSuitePassed - ./testeth -t ClientBase -- --express && touch /tmp/ClientBasePassed - ./testeth -t EstimateGas -- --express && touch /tmp/EstimateGasPassed - ./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 - ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/InstanceMonitorSuitePassed - ./testeth -t PrecompiledTests -- --express && touch /tmp/PrecompiledTestsPassed - ./testeth -t SkaleHostSuite -- --express && touch /tmp/SkaleHostSuitePassed - ./testeth -t StateUnitTests -- --express && touch /tmp/StateUnitTestsPassed - ./testeth -t libethereum -- --express && touch /tmp/libethereumPassed - ./testeth -t TransactionQueueSuite -- --express && touch /tmp/TransactionQueueSuitePassed - ./testeth -t LegacyVMSuite -- --express && touch /tmp/LegacyVMSuitePassed - ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/SkaleInterpreterSuitePassed - ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/SnapshotSigningTestSuitePassed - ./testeth -t SkUtils -- --express && touch /tmp/SkUtilsPassed - ./testeth -t BlockChainTestSuite -- --express && touch /tmp/BlockChainTestSuitePassed - ./testeth -t TestHelperSuite -- --express && touch /tmp/TestHelperSuitePassed - ./testeth -t LevelDBHashBase -- --express && touch /tmp/LevelDBHashBasePassed - ./testeth -t memDB -- --express && touch /tmp/memDBPassed - ./testeth -t OverlayDBTests -- --express && touch /tmp/OverlayDBTestsPassed - ./testeth -t AccountHolderTest -- --express && touch /tmp/AccountHolderTestPassed - ./testeth -t ClientTests -- --express && touch /tmp/ClientTestsPassed - ./testeth -t JsonRpcSuite -- --express && touch /tmp/JsonRpcSuitePassed - ./testeth -t SingleConsensusTests -- --express && touch /tmp/SingleConsensusTestsPassed - ./testeth -t ConsensusTests -- --express && touch /tmp/ConsensusTestsPassed - sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/BtrfsTestSuitePassed - sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/HashSnapshotTestSuitePassed - sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/ClientSnapshotsSuitePassed + ./testeth -t BlockchainTests -- --express && touch /tmp/tests/BlockchainTestsPassed + ./testeth -t TransitionTests -- --express && touch /tmp/tests/TransitionTestsPassed + ./testeth -t TransactionTests -- --express && touch /tmp/tests/TransactionTestsPassed + ./testeth -t VMTests -- --express && touch /tmp/tests/VMTestsPassed + ./testeth -t LevelDBTests -- --express && touch /tmp/tests/LevelDBTestsPassed + ./testeth -t CoreLibTests -- --express && touch /tmp/tests/CoreLibTestsPassed + ./testeth -t RlpTests -- --express && touch /tmp/tests/RlpTestsPassed + ./testeth -t SharedSpaceTests -- --express && touch /tmp/tests/SharedSpaceTestsPassed + ./testeth -t EthashTests -- --express && touch /tmp/tests/EthashTestsPassed + ./testeth -t SealEngineTests -- --express && touch /tmp/tests/SealEngineTestsPassed + ./testeth -t DifficultyTests -- --express && touch /tmp/tests/DifficultyTestsPassed + ./testeth -t BlockSuite -- --express && touch /tmp/tests/BlockSuitePassed + ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/tests/BlockChainMainNetworkSuitePassed + ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/tests/BlockChainFrontierSuitePassed + ./testeth -t BlockQueueSuite -- --express && touch /tmp/tests/BlockQueueSuitePassed + ./testeth -t ClientBase -- --express && touch /tmp/tests/ClientBasePassed + ./testeth -t EstimateGas -- --express && touch /tmp/tests/EstimateGasPassed + ./testeth -t getHistoricNodesData -- --express && touch /tmp/tests/getHistoricNodesDataPassed + ./testeth -t ExtVmSuite -- --express && touch /tmp/tests/ExtVmSuitePassed + ./testeth -t GasPricer -- --express && touch /tmp/tests/GasPricerPassed + ./testeth -t BasicTests -- --express && touch /tmp/tests/BasicTestsPassed + ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/tests/InstanceMonitorSuitePassed + ./testeth -t PrecompiledTests -- --express && touch /tmp/tests/PrecompiledTestsPassed + ./testeth -t SkaleHostSuite -- --express && touch /tmp/tests/SkaleHostSuitePassed + ./testeth -t StateUnitTests -- --express && touch /tmp/tests/StateUnitTestsPassed + ./testeth -t libethereum -- --express && touch /tmp/tests/libethereumPassed + ./testeth -t TransactionQueueSuite -- --express && touch /tmp/tests/TransactionQueueSuitePassed + ./testeth -t LegacyVMSuite -- --express && touch /tmp/tests/LegacyVMSuitePassed + ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/tests/SkaleInterpreterSuitePassed + ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/tests/SnapshotSigningTestSuitePassed + ./testeth -t SkUtils -- --express && touch /tmp/tests/SkUtilsPassed + ./testeth -t BlockChainTestSuite -- --express && touch /tmp/tests/BlockChainTestSuitePassed + ./testeth -t TestHelperSuite -- --express && touch /tmp/tests/TestHelperSuitePassed + ./testeth -t LevelDBHashBase -- --express && touch /tmp/tests/LevelDBHashBasePassed + ./testeth -t memDB -- --express && touch /tmp/tests/memDBPassed + ./testeth -t OverlayDBTests -- --express && touch /tmp/tests/OverlayDBTestsPassed + ./testeth -t AccountHolderTest -- --express && touch /tmp/tests/AccountHolderTestPassed + ./testeth -t ClientTests -- --express && touch /tmp/tests/ClientTestsPassed + ./testeth -t JsonRpcSuite -- --express && touch /tmp/tests/JsonRpcSuitePassed + ./testeth -t SingleConsensusTests -- --express && touch /tmp/tests/SingleConsensusTestsPassed + ./testeth -t ConsensusTests -- --express && touch /tmp/tests/ConsensusTestsPassed + sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/tests/BtrfsTestSuitePassed + sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/tests/HashSnapshotTestSuitePassed + sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/tests/ClientSnapshotsSuitePassed cd .. - name: Testeth verbosity 4 run : | @@ -222,50 +224,50 @@ jobs: cd build/test export NO_NTP_CHECK=1 export NO_ULIMIT_CHECK=1 - ls /tmp/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 - ls /tmp/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 - ls /tmp/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 - ls /tmp/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 - ls /tmp/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 - ls /tmp/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 - ls /tmp/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 - ls /tmp/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 - ls /tmp/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 - ls /tmp/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 - ls /tmp/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 - ls /tmp/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 - ls /tmp/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 - ls /tmp/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 - 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/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 - ls /tmp/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 - ls /tmp/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 - ls /tmp/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 - ls /tmp/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 - ls /tmp/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 - ls /tmp/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 - ls /tmp/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 - ls /tmp/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 - ls /tmp/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 - ls /tmp/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 - ls /tmp/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 - ls /tmp/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 - ls /tmp/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 - ls /tmp/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 - ls /tmp/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 - ls /tmp/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 - ls /tmp/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 - ls /tmp/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 - ls /tmp/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 - ls /tmp/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 - ls /tmp/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 - ls /tmp/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 - ls /tmp/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 + ls /tmp/tests/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 + ls /tmp/tests/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 + ls /tmp/tests/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 + ls /tmp/tests/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 + ls /tmp/tests/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 + ls /tmp/tests/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 + ls /tmp/tests/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 + ls /tmp/tests/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 + ls /tmp/tests/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 + ls /tmp/tests/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 + ls /tmp/tests/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 + ls /tmp/tests/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 + ls /tmp/tests/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 + ls /tmp/tests/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 + ls /tmp/tests/BlockQueueSuitePassed || ./testeth -t BlockQueueSuite -- --express --verbosity 4 + ls /tmp/tests/ClientBasePassed || ./testeth -t ClientBase -- --express --verbosity 4 + ls /tmp/tests/EstimateGasPassed || ./testeth -t EstimateGas -- --express --verbosity 4 + ls /tmp/tests/getHistoricNodesDataPassed || ./testeth -t getHistoricNodesData -- --express --verbosity 4 + ls /tmp/tests/ExtVmSuitePassed || ./testeth -t ExtVmSuite -- --express --verbosity 4 + ls /tmp/tests/GasPricerPassed || ./testeth -t GasPricer -- --express --verbosity 4 + ls /tmp/tests/BasicTestsPassed || ./testeth -t BasicTests -- --express --verbosity 4 + ls /tmp/tests/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 + ls /tmp/tests/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 + ls /tmp/tests/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 + ls /tmp/tests/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 + ls /tmp/tests/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 + ls /tmp/tests/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 + ls /tmp/tests/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 + ls /tmp/tests/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 + ls /tmp/tests/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 + ls /tmp/tests/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 + ls /tmp/tests/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 + ls /tmp/tests/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 + ls /tmp/tests/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 + ls /tmp/tests/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 + ls /tmp/tests/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 + ls /tmp/tests/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 + ls /tmp/tests/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 + ls /tmp/tests/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 + ls /tmp/tests/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 + ls /tmp/tests/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 + ls /tmp/tests/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 + ls /tmp/tests/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 + ls /tmp/tests/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 cd .. - name: Create lcov report From 886c695a710aa358d378a75e80bde0ea8018b451 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 11:59:28 +0000 Subject: [PATCH 147/159] fix tests --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3943c70b..aa3a0e340 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -167,7 +167,7 @@ jobs: - name: Testeth verbosity 1 run : | mkdir -p /tmp/tests/ - rm -rf /tmp/tests/* + sudo rm -rf /tmp/tests/* #first run with verbosity 1. If test fails, rerun with verbosity 4 cd build/test export NO_NTP_CHECK=1 From 2b7cf66f33ce6d5e13c6a2b6c04e5e8fd30c819e Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 12:24:09 +0000 Subject: [PATCH 148/159] #1785 fix unittests --- .github/workflows/test.yml | 180 +++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0255608d..0df685841 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -166,55 +166,57 @@ jobs: ccache --show-stats - name: Testeth verbosity 1 run : | + mkdir -p /tmp/tests/ + sudo rm -rf /tmp/tests/* #first run with verbosity 1. If test fails, rerun with verbosity 4 cd build/test export NO_NTP_CHECK=1 - export NO_ULIMIT_CHECK=1 + export NO_ULIMIT_CHECK=1 # we specifically run each test for easier log review - ./testeth -t BlockchainTests -- --express && touch /tmp/BlockchainTestsPassed - ./testeth -t TransitionTests -- --express && touch /tmp/TransitionTestsPassed - ./testeth -t TransactionTests -- --express && touch /tmp/TransactionTestsPassed - ./testeth -t VMTests -- --express && touch /tmp/VMTestsPassed - ./testeth -t LevelDBTests -- --express && touch /tmp/LevelDBTestsPassed - ./testeth -t CoreLibTests -- --express && touch /tmp/CoreLibTestsPassed - ./testeth -t RlpTests -- --express && touch /tmp/RlpTestsPassed - ./testeth -t SharedSpaceTests -- --express && touch /tmp/SharedSpaceTestsPassed - ./testeth -t EthashTests -- --express && touch /tmp/EthashTestsPassed - ./testeth -t SealEngineTests -- --express && touch /tmp/SealEngineTestsPassed - ./testeth -t DifficultyTests -- --express && touch /tmp/DifficultyTestsPassed - ./testeth -t BlockSuite -- --express && touch /tmp/BlockSuitePassed - ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/BlockChainMainNetworkSuitePassed - ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/BlockChainFrontierSuitePassed - ./testeth -t BlockQueueSuite -- --express && touch /tmp/BlockQueueSuitePassed - ./testeth -t ClientBase -- --express && touch /tmp/ClientBasePassed - ./testeth -t EstimateGas -- --express && touch /tmp/EstimateGasPassed - ./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 - ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/InstanceMonitorSuitePassed - ./testeth -t PrecompiledTests -- --express && touch /tmp/PrecompiledTestsPassed - ./testeth -t SkaleHostSuite -- --express && touch /tmp/SkaleHostSuitePassed - ./testeth -t StateUnitTests -- --express && touch /tmp/StateUnitTestsPassed - ./testeth -t libethereum -- --express && touch /tmp/libethereumPassed - ./testeth -t TransactionQueueSuite -- --express && touch /tmp/TransactionQueueSuitePassed - ./testeth -t LegacyVMSuite -- --express && touch /tmp/LegacyVMSuitePassed - ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/SkaleInterpreterSuitePassed - ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/SnapshotSigningTestSuitePassed - ./testeth -t SkUtils -- --express && touch /tmp/SkUtilsPassed - ./testeth -t BlockChainTestSuite -- --express && touch /tmp/BlockChainTestSuitePassed - ./testeth -t TestHelperSuite -- --express && touch /tmp/TestHelperSuitePassed - ./testeth -t LevelDBHashBase -- --express && touch /tmp/LevelDBHashBasePassed - ./testeth -t memDB -- --express && touch /tmp/memDBPassed - ./testeth -t OverlayDBTests -- --express && touch /tmp/OverlayDBTestsPassed - ./testeth -t AccountHolderTest -- --express && touch /tmp/AccountHolderTestPassed - ./testeth -t ClientTests -- --express && touch /tmp/ClientTestsPassed - ./testeth -t JsonRpcSuite -- --express && touch /tmp/JsonRpcSuitePassed - ./testeth -t SingleConsensusTests -- --express && touch /tmp/SingleConsensusTestsPassed - ./testeth -t ConsensusTests -- --express && touch /tmp/ConsensusTestsPassed - sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/BtrfsTestSuitePassed - sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/HashSnapshotTestSuitePassed - sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/ClientSnapshotsSuitePassed + ./testeth -t BlockchainTests -- --express && touch /tmp/tests/BlockchainTestsPassed + ./testeth -t TransitionTests -- --express && touch /tmp/tests/TransitionTestsPassed + ./testeth -t TransactionTests -- --express && touch /tmp/tests/TransactionTestsPassed + ./testeth -t VMTests -- --express && touch /tmp/tests/VMTestsPassed + ./testeth -t LevelDBTests -- --express && touch /tmp/tests/LevelDBTestsPassed + ./testeth -t CoreLibTests -- --express && touch /tmp/tests/CoreLibTestsPassed + ./testeth -t RlpTests -- --express && touch /tmp/tests/RlpTestsPassed + ./testeth -t SharedSpaceTests -- --express && touch /tmp/tests/SharedSpaceTestsPassed + ./testeth -t EthashTests -- --express && touch /tmp/tests/EthashTestsPassed + ./testeth -t SealEngineTests -- --express && touch /tmp/tests/SealEngineTestsPassed + ./testeth -t DifficultyTests -- --express && touch /tmp/tests/DifficultyTestsPassed + ./testeth -t BlockSuite -- --express && touch /tmp/tests/BlockSuitePassed + ./testeth -t BlockChainMainNetworkSuite -- --express && touch /tmp/tests/BlockChainMainNetworkSuitePassed + ./testeth -t BlockChainFrontierSuite -- --express && touch /tmp/tests/BlockChainFrontierSuitePassed + ./testeth -t BlockQueueSuite -- --express && touch /tmp/tests/BlockQueueSuitePassed + ./testeth -t ClientBase -- --express && touch /tmp/tests/ClientBasePassed + ./testeth -t EstimateGas -- --express && touch /tmp/tests/EstimateGasPassed + ./testeth -t getHistoricNodesData -- --express && touch /tmp/tests/getHistoricNodesDataPassed + ./testeth -t ExtVmSuite -- --express && touch /tmp/tests/ExtVmSuitePassed + ./testeth -t GasPricer -- --express && touch /tmp/tests/GasPricerPassed + ./testeth -t BasicTests -- --express && touch /tmp/tests/BasicTestsPassed + ./testeth -t InstanceMonitorSuite -- --express && touch /tmp/tests/InstanceMonitorSuitePassed + ./testeth -t PrecompiledTests -- --express && touch /tmp/tests/PrecompiledTestsPassed + ./testeth -t SkaleHostSuite -- --express && touch /tmp/tests/SkaleHostSuitePassed + ./testeth -t StateUnitTests -- --express && touch /tmp/tests/StateUnitTestsPassed + ./testeth -t libethereum -- --express && touch /tmp/tests/libethereumPassed + ./testeth -t TransactionQueueSuite -- --express && touch /tmp/tests/TransactionQueueSuitePassed + ./testeth -t LegacyVMSuite -- --express && touch /tmp/tests/LegacyVMSuitePassed + ./testeth -t SkaleInterpreterSuite -- --express && touch /tmp/tests/SkaleInterpreterSuitePassed + ./testeth -t SnapshotSigningTestSuite -- --express && touch /tmp/tests/SnapshotSigningTestSuitePassed + ./testeth -t SkUtils -- --express && touch /tmp/tests/SkUtilsPassed + ./testeth -t BlockChainTestSuite -- --express && touch /tmp/tests/BlockChainTestSuitePassed + ./testeth -t TestHelperSuite -- --express && touch /tmp/tests/TestHelperSuitePassed + ./testeth -t LevelDBHashBase -- --express && touch /tmp/tests/LevelDBHashBasePassed + ./testeth -t memDB -- --express && touch /tmp/tests/memDBPassed + ./testeth -t OverlayDBTests -- --express && touch /tmp/tests/OverlayDBTestsPassed + ./testeth -t AccountHolderTest -- --express && touch /tmp/tests/AccountHolderTestPassed + ./testeth -t ClientTests -- --express && touch /tmp/tests/ClientTestsPassed + ./testeth -t JsonRpcSuite -- --express && touch /tmp/tests/JsonRpcSuitePassed + ./testeth -t SingleConsensusTests -- --express && touch /tmp/tests/SingleConsensusTestsPassed + ./testeth -t ConsensusTests -- --express && touch /tmp/tests/ConsensusTestsPassed + sudo ./testeth -t BtrfsTestSuite -- --all && touch /tmp/tests/BtrfsTestSuitePassed + sudo ./testeth -t HashSnapshotTestSuite -- --all && touch /tmp/tests/HashSnapshotTestSuitePassed + sudo ./testeth -t ClientSnapshotsSuite -- --all && touch /tmp/tests/ClientSnapshotsSuitePassed cd .. - name: Testeth verbosity 4 run : | @@ -222,50 +224,50 @@ jobs: cd build/test export NO_NTP_CHECK=1 export NO_ULIMIT_CHECK=1 - ls /tmp/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 - ls /tmp/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 - ls /tmp/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 - ls /tmp/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 - ls /tmp/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 - ls /tmp/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 - ls /tmp/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 - ls /tmp/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 - ls /tmp/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 - ls /tmp/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 - ls /tmp/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 - ls /tmp/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 - ls /tmp/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 - ls /tmp/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 - 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/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 - ls /tmp/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 - ls /tmp/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 - ls /tmp/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 - ls /tmp/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 - ls /tmp/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 - ls /tmp/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 - ls /tmp/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 - ls /tmp/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 - ls /tmp/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 - ls /tmp/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 - ls /tmp/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 - ls /tmp/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 - ls /tmp/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 - ls /tmp/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 - ls /tmp/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 - ls /tmp/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 - ls /tmp/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 - ls /tmp/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 - ls /tmp/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 - ls /tmp/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 - ls /tmp/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 - ls /tmp/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 - ls /tmp/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 + ls /tmp/tests/BlockchainTestsPassed || ./testeth -t BlockchainTests -- --express --verbosity 4 + ls /tmp/tests/TransitionTestsPassed || ./testeth -t TransitionTests -- --express --verbosity 4 + ls /tmp/tests/TransactionTestsPassed || ./testeth -t TransactionTests -- --express --verbosity 4 + ls /tmp/tests/VMTestsPassed || ./testeth -t VMTests -- --express --verbosity 4 + ls /tmp/tests/LevelDBTestsPassed || ./testeth -t LevelDBTests -- --express --verbosity 4 + ls /tmp/tests/CoreLibTestsPassed || ./testeth -t CoreLibTests -- --express --verbosity 4 + ls /tmp/tests/RlpTestsPassed || ./testeth -t RlpTests -- --express --verbosity 4 + ls /tmp/tests/SharedSpaceTestsPassed || ./testeth -t SharedSpaceTests -- --express --verbosity 4 + ls /tmp/tests/EthashTestsPassed || ./testeth -t EthashTests -- --express --verbosity 4 + ls /tmp/tests/SealEngineTestsPassed || ./testeth -t SealEngineTests -- --express --verbosity 4 + ls /tmp/tests/DifficultyTestsPassed || ./testeth -t DifficultyTests -- --express --verbosity 4 + ls /tmp/tests/BlockSuitePassed || ./testeth -t BlockSuite -- --express --verbosity 4 + ls /tmp/tests/BlockChainMainNetworkSuitePassed || ./testeth -t BlockChainMainNetworkSuite -- --express --verbosity 4 + ls /tmp/tests/BlockChainFrontierSuitePassed || ./testeth -t BlockChainFrontierSuite -- --express --verbosity 4 + ls /tmp/tests/BlockQueueSuitePassed || ./testeth -t BlockQueueSuite -- --express --verbosity 4 + ls /tmp/tests/ClientBasePassed || ./testeth -t ClientBase -- --express --verbosity 4 + ls /tmp/tests/EstimateGasPassed || ./testeth -t EstimateGas -- --express --verbosity 4 + ls /tmp/tests/getHistoricNodesDataPassed || ./testeth -t getHistoricNodesData -- --express --verbosity 4 + ls /tmp/tests/ExtVmSuitePassed || ./testeth -t ExtVmSuite -- --express --verbosity 4 + ls /tmp/tests/GasPricerPassed || ./testeth -t GasPricer -- --express --verbosity 4 + ls /tmp/tests/BasicTestsPassed || ./testeth -t BasicTests -- --express --verbosity 4 + ls /tmp/tests/InstanceMonitorSuitePassed || ./testeth -t InstanceMonitorSuite -- --express --verbosity 4 + ls /tmp/tests/PrecompiledTestsPassed || ./testeth -t PrecompiledTests -- --express --verbosity 4 + ls /tmp/tests/SkaleHostSuitePassed || ./testeth -t SkaleHostSuite -- --express --verbosity 4 + ls /tmp/tests/StateUnitTestsPassed || ./testeth -t StateUnitTests -- --express --verbosity 4 + ls /tmp/tests/libethereumPassed || ./testeth -t libethereum -- --express --verbosity 4 + ls /tmp/tests/TransactionQueueSuitePassed || ./testeth -t TransactionQueueSuite -- --express --verbosity 4 + ls /tmp/tests/LegacyVMSuitePassed || ./testeth -t LegacyVMSuite -- --express --verbosity 4 + ls /tmp/tests/SkaleInterpreterSuitePassed || ./testeth -t SkaleInterpreterSuite -- --express --verbosity 4 + ls /tmp/tests/SnapshotSigningTestSuitePassed || ./testeth -t SnapshotSigningTestSuite -- --express --verbosity 4 + ls /tmp/tests/SkUtilsPassed || ./testeth -t SkUtils -- --express --verbosity 4 + ls /tmp/tests/BlockChainTestSuitePassed || ./testeth -t BlockChainTestSuite -- --express --verbosity 4 + ls /tmp/tests/TestHelperSuitePassed || ./testeth -t TestHelperSuite -- --express --verbosity 4 + ls /tmp/tests/LevelDBHashBasePassed || ./testeth -t LevelDBHashBase -- --express --verbosity 4 + ls /tmp/tests/memDBPassed || ./testeth -t memDB -- --express --verbosity 4 + ls /tmp/tests/OverlayDBTestsPassed || ./testeth -t OverlayDBTests -- --express --verbosity 4 + ls /tmp/tests/AccountHolderTestPassed || ./testeth -t AccountHolderTest -- --express --verbosity 4 + ls /tmp/tests/ClientTestsPassed || ./testeth -t ClientTests -- --express --verbosity 4 + ls /tmp/tests/JsonRpcSuitePassed || ./testeth -t JsonRpcSuite -- --express --verbosity 4 + ls /tmp/tests/SingleConsensusTestsPassed || ./testeth -t SingleConsensusTests -- --express --verbosity 4 + ls /tmp/tests/ConsensusTestsPassed || ./testeth -t ConsensusTests -- --express --verbosity 4 + ls /tmp/tests/BtrfsTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t BtrfsTestSuite -- --all --verbosity 4 + ls /tmp/tests/HashSnapshotTestSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t HashSnapshotTestSuite -- --all --verbosity 4 + ls /tmp/tests/ClientSnapshotsSuitePassed || sudo NO_ULIMIT_CHECK=1 NO_NTP_CHECK=1 ./testeth -t ClientSnapshotsSuite -- --all --verbosity 4 cd .. - name: Create lcov report From a20069c4855bd84f99e83099e87113f6073fafd1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 12:57:38 +0000 Subject: [PATCH 149/159] #1785 fix SkaleHostSuite tests --- test/unittests/libethereum/SkaleHost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 7870cd7c9..0d64cdaf4 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -133,7 +133,7 @@ struct SkaleHostFixture : public TestOutputHelperFixture { chainParams.sChain.nodes[0].port = chainParams.sChain.nodes[0].port6 = rand_port; // not 0-timestamp genesis - to test patch - chainParams.timestamp = 1; + chainParams.timestamp = std::time( NULL ) - 5; if( params.count("multiTransactionMode") && stoi( params.at( "multiTransactionMode" ) ) ) chainParams.sChain.multiTransactionMode = true; From 2a3faddd16e3614fdff0a0fca6481400724938fd Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 13:28:25 +0000 Subject: [PATCH 150/159] #1785 fix EstimateGasSuite unittests --- test/unittests/libethereum/ClientTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 09160c7fe..81781fa7c 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -417,6 +417,7 @@ static std::string const c_genesisInfoSkaleTest = std::string() + "schainID": 1, "contractStorageLimit": 32000, "emptyBlockIntervalMs": -1, + "correctForkInPowPatchTimestamp": 1, "nodes": [ { "nodeID": 1112, "ip": "127.0.0.1", "basePort": )E"+std::to_string( rand_port ) + R"E(, "schainIndex" : 1, "publicKey": "0xfa"} ] From 525316824ade072efa3881e9313d06bccde49b96 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 15:12:04 +0000 Subject: [PATCH 151/159] #1785 build historic mode in different folder --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa3a0e340..2ec07ee36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -293,8 +293,8 @@ jobs: export TARGET=all export CMAKE_BUILD_TYPE=Debug export CODE_COVERAGE=ON - mkdir -p build - cd build + mkdir -p build_historic + cd build_historic # -DCMAKE_C_FLAGS=-O3 -DCMAKE_CXX_FLAGS=-O3 cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCOVERAGE=$CODE_COVERAGE -DHISTORIC_STATE=1 .. cd .. @@ -306,7 +306,7 @@ jobs: export TARGET=all export CMAKE_BUILD_TYPE=Debug export CODE_COVERAGE=ON - cd build + cd build_historic make testeth -j$(nproc) cd .. - name: Print ccache stats after full historic build @@ -314,7 +314,7 @@ jobs: ccache --show-stats - name: Testeth historic run : | - cd build/test + cd build_historic/test export NO_NTP_CHECK=1 export NO_ULIMIT_CHECK=1 ./testeth -t JsonRpcSuite -- --express --verbosity 4 From d6427e7410b78a692d19a7dde9fa9c5eabfd7f8d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 17 Jan 2024 15:12:19 +0000 Subject: [PATCH 152/159] #1785 fix JsonRpcSuite tests --- 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 fcb0596dd..714bb525e 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -289,7 +289,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { // 615 + 1430 is experimentally-derived block size + average extras size chainParams.sChain.dbStorageLimit = 320.5*( 615 + 1430 ); chainParams.sChain.contractStoragePatchTimestamp = 1; - powPatchActivationTimestamp = time(nullptr) + 20; + powPatchActivationTimestamp = time(nullptr) + 60; chainParams.sChain.correctForkInPowPatchTimestamp = powPatchActivationTimestamp; // 10 guessed seconds chainParams.sChain.emptyBlockIntervalMs = _emptyBlockIntervalMs; // add random extra data to randomize genesis hash and get random DB path, From 9ea8a422f3048c96078495841694b8ef327dc837 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 17 Jan 2024 18:13:48 +0000 Subject: [PATCH 153/159] SKALED-1693 Run functional test twice - for both original and historic builds --- .github/workflows/publish.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 63ae10fc6..7cb95d9d6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -150,6 +150,7 @@ jobs: export VERSION=$(cat VERSION) export VERSION=$(bash ./scripts/calculate_version.sh $BRANCH $VERSION) echo "::set-env name=VERSION::$VERSION" + echo "::set-env name=VERSION_ORIG::$VERSION" echo "Version $VERSION" ( test $BRANCH = "stable" && export PRERELEASE=false ) || export PRERELEASE=true echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV @@ -191,6 +192,7 @@ jobs: echo "Branch $BRANCH" export VERSION=$VERSION-historic echo "::set-env name=VERSION::$VERSION" + echo "::set-env name=VERSION_HISTORIC::$VERSION" echo "Version $VERSION" export RELEASE=true echo "::set-env name=RELEASE::$RELEASE" @@ -214,7 +216,8 @@ jobs: asset_name: skaled-debug-historic asset_content_type: application/octet-stream outputs: - version: ${{ env.VERSION }} + version_orig: ${{ env.VERSION_ORIG }} + version_historic: ${{ env.VERSION_HISTORIC }} functional-tests: uses: ./.github/workflows/functional-tests.yml @@ -223,3 +226,11 @@ jobs: with: version: ${{ needs.build.outputs.version }} secrets: inherit + + functional-tests-historic: + uses: ./.github/workflows/functional-tests.yml + name: Functional testing for build + needs: [build] + with: + version: ${{ needs.build.outputs.version_orig }} + secrets: inherit From 7c67a04a6a4801130b34041e309eed7d4a64b6e8 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 18 Jan 2024 11:30:59 +0000 Subject: [PATCH 154/159] #1588 rename variables --- libskale/SnapshotManager.cpp | 6 +++--- test/unittests/libweb3core/LevelDBHash.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index 5e6e5660a..8989b4274 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -448,14 +448,14 @@ void SnapshotManager::computeDatabaseHash( secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); - std::string finishKey = "start"; + std::string lastHashedKey = "start"; - while ( finishKey != "stop" ) { + while ( lastHashedKey != "stop" ) { std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( _dbDir.string(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( &dbCtx, finishKey ); + m_db->hashBasePartially( &dbCtx, lastHashedKey ); } dev::h256 dbHash; diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index 0756d0678..1eec5366e 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -73,13 +73,13 @@ BOOST_AUTO_TEST_CASE( hash ) { secp256k1_sha256_t dbCtx; secp256k1_sha256_initialize( &dbCtx ); - std::string finishKey = "start"; - while ( finishKey != "stop" ) { + std::string lastHashedKey = "start"; + while ( lastHashedKey != "stop" ) { std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( td.path(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( &dbCtx, finishKey, 10 ); + m_db->hashBasePartially( &dbCtx, lastHashedKey, 10 ); } secp256k1_sha256_finalize( &dbCtx, hashPartially.data() ); From b8cdd8d5851f666eac80f1d5f14d3fc06804cea0 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 18 Jan 2024 12:00:32 +0000 Subject: [PATCH 155/159] #1588 rename variables and remove colored logs --- libdevcore/LevelDB.cpp | 34 +++++++++++++++++----------------- skaled/main.cpp | 19 ++++++++----------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index dda5756ef..214c49522 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -240,17 +240,17 @@ h256 LevelDB::hashBase() const { secp256k1_sha256_t ctx; secp256k1_sha256_initialize( &ctx ); for ( it->SeekToFirst(); it->Valid(); it->Next() ) { - std::string key_ = it->key().ToString(); - std::string value_ = it->value().ToString(); + std::string keyTmp = it->key().ToString(); + std::string valueTmp = it->value().ToString(); // HACK! For backward compatibility! When snapshot could happen between update of two nodes // - it would lead to stateRoot mismatch // TODO Move this logic to separate "compatiliblity layer"! - if ( key_ == "pieceUsageBytes" ) + if ( keyTmp == "pieceUsageBytes" ) continue; - std::string key_value = key_ + value_; - const std::vector< uint8_t > usc( key_value.begin(), key_value.end() ); - bytesConstRef str_key_value( usc.data(), usc.size() ); - secp256k1_sha256_write( &ctx, str_key_value.data(), str_key_value.size() ); + std::string keyValue = keyTmp + valueTmp; + const std::vector< uint8_t > usc( keyValue.begin(), keyValue.end() ); + bytesConstRef strKeyValue( usc.data(), usc.size() ); + secp256k1_sha256_write( &ctx, strKeyValue.data(), strKeyValue.size() ); } h256 hash; @@ -268,12 +268,12 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { secp256k1_sha256_initialize( &ctx ); for ( it->SeekToFirst(); it->Valid(); it->Next() ) { if ( it->key()[0] == _prefix ) { - std::string key_ = it->key().ToString(); - std::string value_ = it->value().ToString(); - std::string key_value = key_ + value_; - const std::vector< uint8_t > usc( key_value.begin(), key_value.end() ); - bytesConstRef str_key_value( usc.data(), usc.size() ); - secp256k1_sha256_write( &ctx, str_key_value.data(), str_key_value.size() ); + std::string keyTmp = it->key().ToString(); + std::string valueTmp = it->value().ToString(); + std::string keyValue = keyTmp + valueTmp; + const std::vector< uint8_t > usc( keyValue.begin(), keyValue.end() ); + bytesConstRef strKeyValue( usc.data(), usc.size() ); + secp256k1_sha256_write( &ctx, strKeyValue.data(), strKeyValue.size() ); } } h256 hash; @@ -294,14 +294,14 @@ void LevelDB::hashBasePartially( it->SeekToFirst(); for ( size_t counter = 0; it->Valid() && counter < batchSize; it->Next() ) { - std::string key_ = it->key().ToString(); - std::string value_ = it->value().ToString(); + std::string keyTmp = it->key().ToString(); + std::string valueTmp = it->value().ToString(); // HACK! For backward compatibility! When snapshot could happen between update of two nodes // - it would lead to stateRoot mismatch // TODO Move this logic to separate "compatiliblity layer"! - if ( key_ == "pieceUsageBytes" ) + if ( keyTmp == "pieceUsageBytes" ) continue; - std::string keyValue = key_ + value_; + std::string keyValue = keyTmp + valueTmp; const std::vector< uint8_t > usc( keyValue.begin(), keyValue.end() ); bytesConstRef strKeyValue( usc.data(), usc.size() ); secp256k1_sha256_write( ctx, strKeyValue.data(), strKeyValue.size() ); diff --git a/skaled/main.cpp b/skaled/main.cpp index 27469a750..b0ad1aca8 100644 --- a/skaled/main.cpp +++ b/skaled/main.cpp @@ -438,9 +438,9 @@ bool tryDownloadSnapshot( std::shared_ptr< SnapshotManager >& snapshotManager, try { snapshotManager->computeSnapshotHash( blockNumber, true ); } catch ( const std::exception& ) { - std::throw_with_nested( - std::runtime_error( cc::fatal( "FATAL:" ) + " " + - cc::error( "Exception while computing snapshot hash " ) ) ); + std::throw_with_nested( std::runtime_error( + std::string( "FATAL:" ) + + std::string( " Exception while computing snapshot hash " ) ) ); } dev::h256 calculated_hash = snapshotManager->getSnapshotHash( blockNumber ); @@ -449,18 +449,15 @@ bool tryDownloadSnapshot( std::shared_ptr< SnapshotManager >& snapshotManager, successfullDownload = true; if ( isRegularSnapshot ) { snapshotManager->restoreSnapshot( blockNumber ); - std::cout << cc::success( "Snapshot restore success for block " ) - << cc::u( to_string( blockNumber ) ) << std::endl; + std::cout << "Snapshot restore success for block " << to_string( blockNumber ) + << std::endl; } return successfullDownload; } else { clog( VerbosityWarning, "tryDownloadSnapshot" ) - << cc::notice( - "Downloaded snapshot with incorrect hash! Incoming " - "hash " ) - << cc::notice( votedHash.first.hex() ) - << cc::notice( " is not equal to calculated hash " ) - << cc::notice( calculated_hash.hex() ) << cc::notice( " Will try again" ); + << "Downloaded snapshot with incorrect hash! Incoming hash " + << votedHash.first.hex() << " is not equal to calculated hash " + << calculated_hash.hex() << " Will try again"; if ( isRegularSnapshot ) snapshotManager->cleanup(); else From ac6490e83f6bc6a8327f459fd9d164b766006dfd Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 18 Jan 2024 12:13:13 +0000 Subject: [PATCH 156/159] #1588 move batchCHunkSize to class field --- libdevcore/LevelDB.cpp | 7 ++++--- libdevcore/LevelDB.h | 5 +++-- test/unittests/libweb3core/LevelDBHash.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index 214c49522..2fb094469 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -28,6 +28,8 @@ namespace db { unsigned c_maxOpenLeveldbFiles = 25; +const size_t LevelDB::BATCH_CHUNK_SIZE = 10000; + namespace { inline leveldb::Slice toLDBSlice( Slice _slice ) { return leveldb::Slice( _slice.data(), _slice.size() ); @@ -281,8 +283,7 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { return hash; } -void LevelDB::hashBasePartially( - secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize ) const { +void LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const { std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) ); if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); @@ -293,7 +294,7 @@ void LevelDB::hashBasePartially( else it->SeekToFirst(); - for ( size_t counter = 0; it->Valid() && counter < batchSize; it->Next() ) { + for ( size_t counter = 0; it->Valid() && counter < BATCH_CHUNK_SIZE; it->Next() ) { std::string keyTmp = it->key().ToString(); std::string valueTmp = it->value().ToString(); // HACK! For backward compatibility! When snapshot could happen between update of two nodes diff --git a/libdevcore/LevelDB.h b/libdevcore/LevelDB.h index 01461f4c7..7a316f99c 100644 --- a/libdevcore/LevelDB.h +++ b/libdevcore/LevelDB.h @@ -61,8 +61,7 @@ class LevelDB : public DatabaseFace { h256 hashBase() const override; h256 hashBaseWithPrefix( char _prefix ) const; - void hashBasePartially( - secp256k1_sha256_t* ctx, std::string& lastHashedKey, size_t batchSize = 10000 ) const; + void hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const; void doCompaction() const; @@ -79,6 +78,8 @@ class LevelDB : public DatabaseFace { leveldb::WriteOptions const m_writeOptions; leveldb::Options m_options; boost::filesystem::path const m_path; + + static const size_t BATCH_CHUNK_SIZE; }; } // namespace db diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index 1eec5366e..d3324fa60 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( hash ) { dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( &dbCtx, lastHashedKey, 10 ); + m_db->hashBasePartially( &dbCtx, lastHashedKey ); } secp256k1_sha256_finalize( &dbCtx, hashPartially.data() ); From a79c45da42865e5723e031d41146dfe2d88f464b Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 18 Jan 2024 12:25:18 +0000 Subject: [PATCH 157/159] #1588 bool flag to continue db hash computation --- libdevcore/LevelDB.cpp | 9 +++++---- libdevcore/LevelDB.h | 2 +- libskale/SnapshotManager.cpp | 5 +++-- test/unittests/libweb3core/LevelDBHash.cpp | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libdevcore/LevelDB.cpp b/libdevcore/LevelDB.cpp index 2fb094469..b568d85da 100644 --- a/libdevcore/LevelDB.cpp +++ b/libdevcore/LevelDB.cpp @@ -283,7 +283,7 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const { return hash; } -void LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const { +bool LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const { std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) ); if ( it == nullptr ) { BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) ); @@ -309,10 +309,11 @@ void LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashe ++counter; } - if ( it->Valid() ) + if ( it->Valid() ) { lastHashedKey = it->key().ToString(); - else - lastHashedKey = "stop"; + return true; + } else + return false; } void LevelDB::doCompaction() const { diff --git a/libdevcore/LevelDB.h b/libdevcore/LevelDB.h index 7a316f99c..5c314e8bf 100644 --- a/libdevcore/LevelDB.h +++ b/libdevcore/LevelDB.h @@ -61,7 +61,7 @@ class LevelDB : public DatabaseFace { h256 hashBase() const override; h256 hashBaseWithPrefix( char _prefix ) const; - void hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const; + bool hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const; void doCompaction() const; diff --git a/libskale/SnapshotManager.cpp b/libskale/SnapshotManager.cpp index 8989b4274..8729d2a74 100644 --- a/libskale/SnapshotManager.cpp +++ b/libskale/SnapshotManager.cpp @@ -449,13 +449,14 @@ void SnapshotManager::computeDatabaseHash( secp256k1_sha256_initialize( &dbCtx ); std::string lastHashedKey = "start"; + bool isContinue = true; - while ( lastHashedKey != "stop" ) { + while ( isContinue ) { std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( _dbDir.string(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( &dbCtx, lastHashedKey ); + isContinue = m_db->hashBasePartially( &dbCtx, lastHashedKey ); } dev::h256 dbHash; diff --git a/test/unittests/libweb3core/LevelDBHash.cpp b/test/unittests/libweb3core/LevelDBHash.cpp index d3324fa60..f7c444dcd 100644 --- a/test/unittests/libweb3core/LevelDBHash.cpp +++ b/test/unittests/libweb3core/LevelDBHash.cpp @@ -74,12 +74,13 @@ BOOST_AUTO_TEST_CASE( hash ) { secp256k1_sha256_initialize( &dbCtx ); std::string lastHashedKey = "start"; - while ( lastHashedKey != "stop" ) { + bool isContinue = true; + while ( isContinue ) { std::unique_ptr< dev::db::LevelDB > m_db( new dev::db::LevelDB( td.path(), dev::db::LevelDB::defaultSnapshotReadOptions(), dev::db::LevelDB::defaultWriteOptions(), dev::db::LevelDB::defaultSnapshotDBOptions() ) ); - m_db->hashBasePartially( &dbCtx, lastHashedKey ); + isContinue = m_db->hashBasePartially( &dbCtx, lastHashedKey ); } secp256k1_sha256_finalize( &dbCtx, hashPartially.data() ); From bde0c844f7ecbf9de12b4dc6d15b83eb1cdd4ea3 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 18 Jan 2024 18:32:44 +0000 Subject: [PATCH 158/159] SKALED-1693 Run functional tests for orig and historic builds --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7cb95d9d6..372bc11a6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -224,7 +224,7 @@ jobs: name: Functional testing for build needs: [build] with: - version: ${{ needs.build.outputs.version }} + version: ${{ needs.build.outputs.version_orig }} secrets: inherit functional-tests-historic: @@ -232,5 +232,5 @@ jobs: name: Functional testing for build needs: [build] with: - version: ${{ needs.build.outputs.version_orig }} + version: ${{ needs.build.outputs.version_historic }} secrets: inherit From 92bb42445c54331e26ef5edc6f948c64657b4e63 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 19 Jan 2024 11:56:40 +0000 Subject: [PATCH 159/159] IS-902 fix 0 zero snapshot case --- libweb3jsonrpc/Skale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libweb3jsonrpc/Skale.cpp b/libweb3jsonrpc/Skale.cpp index 492e25fc8..27b71b1cb 100644 --- a/libweb3jsonrpc/Skale.cpp +++ b/libweb3jsonrpc/Skale.cpp @@ -158,7 +158,7 @@ nlohmann::json Skale::impl_skale_getSnapshot( const nlohmann::json& joRequest, C // TODO check unsigned blockNumber = joRequest["blockNumber"].get< unsigned >(); - if ( blockNumber != m_client.getLatestSnapshotBlockNumer() ) { + if ( blockNumber != 0 && blockNumber != m_client.getLatestSnapshotBlockNumer() ) { joResponse["error"] = "Invalid snapshot block number requested - it might be deleted."; return joResponse; } @@ -370,7 +370,7 @@ Json::Value Skale::skale_getSnapshotSignature( unsigned blockNumber ) { if ( chainParams.nodeInfo.keyShareName.empty() || chainParams.nodeInfo.sgxServerUrl.empty() ) throw jsonrpc::JsonRpcException( "Snapshot signing is not enabled" ); - if ( blockNumber != this->m_client.getLatestSnapshotBlockNumer() ) { + if ( blockNumber != 0 && blockNumber != this->m_client.getLatestSnapshotBlockNumer() ) { throw jsonrpc::JsonRpcException( "Invalid snapshot block number requested - it might be deleted." ); }