From a42bf347731d3a17ee66c029cc29b4895205a61f Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 15 Dec 2016 14:15:04 -0500 Subject: [PATCH 1/2] Log hardforks for testnet nodes #710 --- libraries/chain/database.cpp | 74 +++++++------------ .../chain/include/steemit/chain/database.hpp | 2 + tests/common/database_fixture.cpp | 1 + tests/tests/block_tests.cpp | 10 +++ 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index db53cb80e0..6a474067b8 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -4026,12 +4026,18 @@ void database::set_hardfork( uint32_t hardfork, bool apply_now ) void database::apply_hardfork( uint32_t hardfork ) { + auto log_hardfork = [this]( int hf ) + { + if( _log_hardforks ) + { + elog( "HARDFORK ${hf} at block ${b}", ("hf", hf)("b", head_block_num()) ); + } + }; + switch( hardfork ) { case STEEMIT_HARDFORK_0_1: -#ifndef IS_TEST_NET - elog( "HARDFORK 1 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(1); perform_vesting_share_split( 1000000 ); #ifdef IS_TEST_NET { @@ -4048,50 +4054,34 @@ void database::apply_hardfork( uint32_t hardfork ) #endif break; case STEEMIT_HARDFORK_0_2: -#ifndef IS_TEST_NET - elog( "HARDFORK 2 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(2); retally_witness_votes(); break; case STEEMIT_HARDFORK_0_3: -#ifndef IS_TEST_NET - elog( "HARDFORK 3 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(3); retally_witness_votes(); break; case STEEMIT_HARDFORK_0_4: -#ifndef IS_TEST_NET - elog( "HARDFORK 4 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(4); reset_virtual_schedule_time(); break; case STEEMIT_HARDFORK_0_5: -#ifndef IS_TEST_NET - elog( "HARDFORK 5 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(5); break; case STEEMIT_HARDFORK_0_6: -#ifndef IS_TEST_NET - elog( "HARDFORK 6 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(6); retally_witness_vote_counts(); retally_comment_children(); break; case STEEMIT_HARDFORK_0_7: -#ifndef IS_TEST_NET - elog( "HARDFORK 7 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(7); break; case STEEMIT_HARDFORK_0_8: -#ifndef IS_TEST_NET - elog( "HARDFORK 8 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(8); retally_witness_vote_counts(true); break; case STEEMIT_HARDFORK_0_9: -#ifndef IS_TEST_NET - elog( "HARDFORK 9 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(9); { for( const std::string& acc : hardfork9::get_compromised_accounts() ) { @@ -4110,20 +4100,14 @@ void database::apply_hardfork( uint32_t hardfork ) } break; case STEEMIT_HARDFORK_0_10: -#ifndef IS_TEST_NET - elog( "HARDFORK 10 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(10); retally_liquidity_weight(); break; case STEEMIT_HARDFORK_0_11: -#ifndef IS_TEST_NET - elog( "HARDFORK 11 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(11); break; case STEEMIT_HARDFORK_0_12: -#ifndef IS_TEST_NET - elog( "HARDFORK 12 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(12); { const auto& comment_idx = get_index< comment_index >().indices(); @@ -4175,24 +4159,16 @@ void database::apply_hardfork( uint32_t hardfork ) } break; case STEEMIT_HARDFORK_0_13: -#ifndef IS_TEST_NET - elog( "HARDFORK 13 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(13); break; case STEEMIT_HARDFORK_0_14: -#ifndef IS_TEST_NET - elog( "HARDFORK 14 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(14); break; - case STEEMIT_HARDFORK_0_15: -#ifndef IS_TEST_NET - elog( "HARDFORK 15 at block ${b}", ("b", head_block_num()) ); -#endif + case STEEMIT_HARDFORK_0_15: + log_hardfork(15); break; case STEEMIT_HARDFORK_0_16: -#ifndef IS_TEST_NET - elog( "HARDFORK 16 at block ${b}", ("b", head_block_num()) ); -#endif + log_hardfork(16); modify( get_feed_history(), [&]( feed_history_object& fho ) { while( fho.price_history.size() > STEEMIT_FEED_HISTORY_WINDOW ) diff --git a/libraries/chain/include/steemit/chain/database.hpp b/libraries/chain/include/steemit/chain/database.hpp index d4af8723a5..3df2fb375d 100644 --- a/libraries/chain/include/steemit/chain/database.hpp +++ b/libraries/chain/include/steemit/chain/database.hpp @@ -44,6 +44,8 @@ namespace steemit { namespace chain { void set_producing( bool p ) { _is_producing = p; } bool _is_producing = false; + bool _log_hardforks = true; + enum validation_steps { skip_nothing = 0, diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 2a0b6da5dc..c2b8be4432 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -187,6 +187,7 @@ void database_fixture::open_database() { if( !data_dir ) { data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); + db._log_hardforks = false; db.open( data_dir->path(), data_dir->path(), INITIAL_TEST_SUPPLY, 1024 * 1024 * 8, chainbase::database::read_write ); // 8 MB file for testing } } diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 6eaea93521..666c58dbac 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -58,6 +58,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) signed_block cutoff_block; { database db; + db._log_hardforks = false; db.open(data_dir.path(), data_dir.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); @@ -84,6 +85,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) } { database db; + db._log_hardforks = false; db.open(data_dir.path(), data_dir.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num() ); b = cutoff_block; @@ -109,6 +111,7 @@ BOOST_AUTO_TEST_CASE( undo_block ) fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); { database db; + db._log_hardforks = false; db.open(data_dir.path(), data_dir.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); fc::time_point_sec now( STEEMIT_TESTING_GENESIS_TIMESTAMP ); std::vector< time_point_sec > time_stack; @@ -160,8 +163,10 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) //TODO This test needs 6-7 ish witnesses prior to fork database db1; + db1._log_hardforks = false; db1.open( data_dir1.path(), data_dir1.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); database db2; + db2._log_hardforks = false; db2.open( data_dir2.path(), data_dir2.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); @@ -223,7 +228,9 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) dir2( graphene::utilities::temp_directory_path() ); database db1, db2; + db1._log_hardforks = false; db1.open( dir1.path(), dir1.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); + db2._log_hardforks = false; db2.open( dir2.path(), dir2.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); @@ -280,7 +287,9 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) dir2( graphene::utilities::temp_directory_path() ); database db1, db2; + db1._log_hardforks = false; db1.open(dir1.path(), dir1.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); + db2._log_hardforks = false; db2.open(dir2.path(), dir2.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); @@ -330,6 +339,7 @@ BOOST_AUTO_TEST_CASE( tapos ) try { fc::temp_directory dir1( graphene::utilities::temp_directory_path() ); database db1; + db1._log_hardforks = false; db1.open(dir1.path(), dir1.path(), INITIAL_TEST_SUPPLY, TEST_SHARED_MEM_SIZE, chainbase::database::read_write ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("init_key")) ); From 23609e6473ef8fc8af692ca0861a7ba882a79947 Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Wed, 21 Dec 2016 11:50:51 -0500 Subject: [PATCH 2/2] Simplify logging #710 --- libraries/chain/database.cpp | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 6a474067b8..6e0c164ba3 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -4026,18 +4026,12 @@ void database::set_hardfork( uint32_t hardfork, bool apply_now ) void database::apply_hardfork( uint32_t hardfork ) { - auto log_hardfork = [this]( int hf ) - { - if( _log_hardforks ) - { - elog( "HARDFORK ${hf} at block ${b}", ("hf", hf)("b", head_block_num()) ); - } - }; + if( _log_hardforks ) + elog( "HARDFORK ${hf} at block ${b}", ("hf", hardfork)("b", head_block_num()) ); switch( hardfork ) { case STEEMIT_HARDFORK_0_1: - log_hardfork(1); perform_vesting_share_split( 1000000 ); #ifdef IS_TEST_NET { @@ -4054,34 +4048,26 @@ void database::apply_hardfork( uint32_t hardfork ) #endif break; case STEEMIT_HARDFORK_0_2: - log_hardfork(2); retally_witness_votes(); break; case STEEMIT_HARDFORK_0_3: - log_hardfork(3); retally_witness_votes(); break; case STEEMIT_HARDFORK_0_4: - log_hardfork(4); reset_virtual_schedule_time(); break; case STEEMIT_HARDFORK_0_5: - log_hardfork(5); break; case STEEMIT_HARDFORK_0_6: - log_hardfork(6); retally_witness_vote_counts(); retally_comment_children(); break; case STEEMIT_HARDFORK_0_7: - log_hardfork(7); break; case STEEMIT_HARDFORK_0_8: - log_hardfork(8); retally_witness_vote_counts(true); break; case STEEMIT_HARDFORK_0_9: - log_hardfork(9); { for( const std::string& acc : hardfork9::get_compromised_accounts() ) { @@ -4100,14 +4086,11 @@ void database::apply_hardfork( uint32_t hardfork ) } break; case STEEMIT_HARDFORK_0_10: - log_hardfork(10); retally_liquidity_weight(); break; case STEEMIT_HARDFORK_0_11: - log_hardfork(11); break; case STEEMIT_HARDFORK_0_12: - log_hardfork(12); { const auto& comment_idx = get_index< comment_index >().indices(); @@ -4159,16 +4142,12 @@ void database::apply_hardfork( uint32_t hardfork ) } break; case STEEMIT_HARDFORK_0_13: - log_hardfork(13); break; case STEEMIT_HARDFORK_0_14: - log_hardfork(14); break; case STEEMIT_HARDFORK_0_15: - log_hardfork(15); break; case STEEMIT_HARDFORK_0_16: - log_hardfork(16); modify( get_feed_history(), [&]( feed_history_object& fho ) { while( fho.price_history.size() > STEEMIT_FEED_HISTORY_WINDOW )