From 42f4b179dbb04c7f24e7df92eeb4ad087c1d56fa Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 6 Feb 2025 15:39:51 +0000 Subject: [PATCH 1/7] #2031 fix crash in unit tests --- libethereum/Client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index b266145df..aea42a4df 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -573,7 +573,7 @@ size_t Client::syncTransactions( assert( !m_working.isSealed() ); tie( newPendingReceipts, goodReceipts ) = m_working.syncEveryone( bc(), _transactions, _timestamp, _gasPrice ); - m_state = m_state.createStateCopyAndClearCaches(); + m_state.clearAllCaches(); #ifdef HISTORIC_STATE // make sure the trie in new state object points to the new state root m_state.mutableHistoricState().setRoot( @@ -641,7 +641,7 @@ void Client::restartMining() { DEV_READ_GUARDED( x_preSeal ) newPreMine = m_preSeal; - m_state = m_state.createStateCopyAndClearCaches(); + m_state.clearAllCaches(); preChanged = newPreMine.sync( bc(), m_state ); if ( preChanged || m_postSeal.author() != m_preSeal.author() ) { From 046106f2e1ed28b95c43352ab76d2e099c94be26 Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 6 Feb 2025 16:25:34 +0000 Subject: [PATCH 2/7] #2031 fix timeout --- test/unittests/libethereum/ClientTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/libethereum/ClientTest.cpp b/test/unittests/libethereum/ClientTest.cpp index 4f6f835f6..ade323edf 100644 --- a/test/unittests/libethereum/ClientTest.cpp +++ b/test/unittests/libethereum/ClientTest.cpp @@ -1070,7 +1070,7 @@ BOOST_AUTO_TEST_CASE( ClientSnapshotsTest, *boost::unit_test::disabled() ) { BOOST_REQUIRE( testClient->latestBlock().info().stateRoot() == empty_state_root_hash ); - std::this_thread::sleep_for( 1000ms ); + std::this_thread::sleep_for( 3000ms ); BOOST_REQUIRE( fs::exists( fs::path( fixture.getTmpDataDir() ) / "snapshots" / "2" / "snapshot_hash.txt" ) ); From 2fe35bdef51527b0ef12b826f7ed6744d0de35ef Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 6 Feb 2025 18:56:31 +0000 Subject: [PATCH 3/7] #2031 debug --- libethereum/Client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index aea42a4df..dbc63bf33 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -573,7 +573,8 @@ size_t Client::syncTransactions( assert( !m_working.isSealed() ); tie( newPendingReceipts, goodReceipts ) = m_working.syncEveryone( bc(), _transactions, _timestamp, _gasPrice ); - m_state.clearAllCaches(); + // m_state.clearAllCaches(); + m_state.createStateCopyAndClearCaches(); #ifdef HISTORIC_STATE // make sure the trie in new state object points to the new state root m_state.mutableHistoricState().setRoot( From ea0dad508a4ba0302a29c297754e1b7dfdda6509 Mon Sep 17 00:00:00 2001 From: Oleh Date: Thu, 6 Feb 2025 20:57:37 +0000 Subject: [PATCH 4/7] #2031 debug --- libethereum/Client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index dbc63bf33..f6d49706e 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -573,8 +573,8 @@ size_t Client::syncTransactions( assert( !m_working.isSealed() ); tie( newPendingReceipts, goodReceipts ) = m_working.syncEveryone( bc(), _transactions, _timestamp, _gasPrice ); - // m_state.clearAllCaches(); - m_state.createStateCopyAndClearCaches(); + m_state.clearAllCaches(); + // m_state.createStateCopyAndClearCaches(); #ifdef HISTORIC_STATE // make sure the trie in new state object points to the new state root m_state.mutableHistoricState().setRoot( From 11fb25a58ec2d872c8a2799a9021f09fdfe53bb4 Mon Sep 17 00:00:00 2001 From: Oleh Date: Fri, 7 Feb 2025 08:40:45 +0000 Subject: [PATCH 5/7] #2031 debug --- libethereum/Client.cpp | 7 ++++--- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 10 ++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index f6d49706e..fd988be75 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -573,8 +573,8 @@ size_t Client::syncTransactions( assert( !m_working.isSealed() ); tie( newPendingReceipts, goodReceipts ) = m_working.syncEveryone( bc(), _transactions, _timestamp, _gasPrice ); - m_state.clearAllCaches(); - // m_state.createStateCopyAndClearCaches(); + // m_state.clearAllCaches(); + m_state = m_state.createStateCopyAndClearCaches(); #ifdef HISTORIC_STATE // make sure the trie in new state object points to the new state root m_state.mutableHistoricState().setRoot( @@ -642,7 +642,8 @@ void Client::restartMining() { DEV_READ_GUARDED( x_preSeal ) newPreMine = m_preSeal; - m_state.clearAllCaches(); + // m_state.clearAllCaches(); + m_state = m_state.createStateCopyAndClearCaches(); preChanged = newPreMine.sync( bc(), m_state ); if ( preChanged || m_postSeal.author() != m_preSeal.author() ) { diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 8f3418557..f38b7c6ca 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -339,7 +339,10 @@ struct JsonRpcFixture : public TestOutputHelperFixture { client.reset( new eth::ClientTest( chainParams, ( int ) chainParams.networkID, shared_ptr< GasPricer >(), NULL, monitor, tempDir.path(), WithExisting::Kill ) ); - client->setAuthor( coinbase.address() ); + if ( !_generation2 ) + client->setAuthor( coinbase.address() ); + else + client->setAuthor( chainParams.sChain.blockAuthor ); // wait for 1st block - because it's always empty std::promise< void > blockPromise; @@ -352,11 +355,6 @@ struct JsonRpcFixture : public TestOutputHelperFixture { if ( !_isSyncNode ) blockPromise.get_future().wait(); - if ( !_generation2 ) - client->setAuthor( coinbase.address() ); - else - client->setAuthor( chainParams.sChain.blockAuthor ); - using FullServer = ModularServer< rpc::EthFace, rpc::NetFace, rpc::Web3Face, rpc::AdminEthFace /*, rpc::AdminNetFace*/, rpc::DebugFace, rpc::TestFace >; From e40257201c6afb6939ecde360eee73cd4dfcc351 Mon Sep 17 00:00:00 2001 From: Oleh Date: Fri, 7 Feb 2025 12:27:21 +0000 Subject: [PATCH 6/7] #2031 fix tests --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index f38b7c6ca..016fd2f82 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -394,7 +394,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { sleep( 1 ); - auto httpClient = new jsonrpc::HttpClient( + httpClient = new jsonrpc::HttpClient( "http://" + chainParams.nodeInfo.ip + ":" + std::to_string( serverOpts.netOpts_.bindOptsStandard_.nBasePortHTTP4_ ) ); httpClient->SetTimeout( 1000000000 ); @@ -408,6 +408,9 @@ struct JsonRpcFixture : public TestOutputHelperFixture { ~JsonRpcFixture() { if ( skale_server_connector ) skale_server_connector->StopListening(); + + if ( httpClient ) + delete httpClient; BOOST_TEST_MESSAGE( "Destructed JsonRpcFixture" ); } @@ -445,6 +448,7 @@ struct JsonRpcFixture : public TestOutputHelperFixture { unique_ptr< WebThreeStubClient > rpcClient; std::string adminSession; SkaleServerOverride* skale_server_connector; + jsonrpc::HttpClient* httpClient; time_t powPatchActivationTimestamp; time_t push0PatchActivationTimestamp; }; From bd06b85fd2bfe80d6b48f0c132dea963b4063268 Mon Sep 17 00:00:00 2001 From: Oleh Date: Fri, 7 Feb 2025 18:22:53 +0000 Subject: [PATCH 7/7] #2031 fix unit tests --- libethereum/Client.cpp | 2 -- .../libskutils/test_skutils_helper.cpp | 6 ++--- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 22 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index fd988be75..b266145df 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -573,7 +573,6 @@ size_t Client::syncTransactions( assert( !m_working.isSealed() ); tie( newPendingReceipts, goodReceipts ) = m_working.syncEveryone( bc(), _transactions, _timestamp, _gasPrice ); - // m_state.clearAllCaches(); m_state = m_state.createStateCopyAndClearCaches(); #ifdef HISTORIC_STATE // make sure the trie in new state object points to the new state root @@ -642,7 +641,6 @@ void Client::restartMining() { DEV_READ_GUARDED( x_preSeal ) newPreMine = m_preSeal; - // m_state.clearAllCaches(); m_state = m_state.createStateCopyAndClearCaches(); preChanged = newPreMine.sync( bc(), m_state ); diff --git a/test/unittests/libskutils/test_skutils_helper.cpp b/test/unittests/libskutils/test_skutils_helper.cpp index 1141a4e81..df1737a5c 100644 --- a/test/unittests/libskutils/test_skutils_helper.cpp +++ b/test/unittests/libskutils/test_skutils_helper.cpp @@ -1380,9 +1380,9 @@ void test_print_header_name( const char* s ) { cc::_on_ = bPrev; } - -int g_nDefaultPort = 9696; -int g_nDefaultPortProxygen = 8686; +int randomOffset = std::rand() % 50000; +int g_nDefaultPort = 9696 + randomOffset; +int g_nDefaultPortProxygen = 8686 + randomOffset; std::vector< std::string > g_vecTestClientNamesA = {"Frodo", "Bilbo", "Sam", "Elrond", "Galadriel", "Celeborn", "Balrog", "Anduin", "Samwise", "Gandalf", "Legolas", "Aragorn", "Gimli", "Faramir", diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 016fd2f82..37a8b2681 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2512,7 +2512,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txCall["from"] = toJS( senderAddress ); txCall["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_call( txCall, "latest" ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 0 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 0 ); Json::Value txPushValueAndCall; // call storeAndCall(1) txPushValueAndCall["to"] = contractAddress; @@ -2522,7 +2522,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txPushValueAndCall["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txPushValueAndCall ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 ); Json::Value txPushValue; // call store(2) txPushValue["to"] = contractAddress; @@ -2532,7 +2532,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txPushValue["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txPushValue ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 ); Json::Value txThrow; // trying to call store(3) txThrow["to"] = contractAddress; @@ -2541,7 +2541,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txThrow["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txThrow ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 ); Json::Value txEraseValue; // call erase(2) txEraseValue["to"] = contractAddress; @@ -2551,7 +2551,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txEraseValue["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txEraseValue ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 ); Json::Value txZeroValue; // call zero(1) txZeroValue["to"] = contractAddress; @@ -2561,7 +2561,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txZeroValue["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txZeroValue ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 64 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 64 ); Json::Value txZeroValue1; // call zero(1) txZeroValue1["to"] = contractAddress; @@ -2571,7 +2571,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txZeroValue1["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txZeroValue1 ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 64 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 64 ); Json::Value txValueChanged; // call strangeFunction(1) txValueChanged["to"] = contractAddress; @@ -2581,7 +2581,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txValueChanged["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 ); Json::Value txValueChanged1; // call strangeFunction(0) txValueChanged1["to"] = contractAddress; @@ -2591,7 +2591,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txValueChanged1["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged1 ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 96 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 96 ); Json::Value txValueChanged2; // call strangeFunction(2) txValueChanged2["to"] = contractAddress; @@ -2601,7 +2601,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txValueChanged2["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged2 ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 ); Json::Value txValueChanged3; // try call strangeFunction(3) txValueChanged3["to"] = contractAddress; @@ -2611,7 +2611,7 @@ BOOST_AUTO_TEST_CASE( storage_limit_contract ) { txValueChanged3["gasPrice"] = fixture.rpcClient->eth_gasPrice(); txHash = fixture.rpcClient->eth_sendTransaction( txValueChanged3 ); dev::eth::mineTransaction( *( fixture.client ), 1 ); - BOOST_REQUIRE( fixture.client->state().storageUsed( contract ) == 128 ); + BOOST_REQUIRE( fixture.client->state().createReadOnlySnapBasedCopy().storageUsed( contract ) == 128 ); } BOOST_AUTO_TEST_CASE( storage_limit_chain ) {