From dcc4f8076bdff5f53088eae8dc922993e41a4f25 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 25 Aug 2015 14:46:56 -0400 Subject: [PATCH] database.hpp: Simplify get_scheduled_witness() return value --- libraries/chain/db_block.cpp | 4 +- libraries/chain/db_witness_schedule.cpp | 6 +- .../chain/include/graphene/chain/database.hpp | 6 +- libraries/plugins/witness/witness.cpp | 2 +- tests/app/main.cpp | 2 +- tests/benchmarks/genesis_allocation.cpp | 4 +- tests/common/database_fixture.cpp | 2 +- tests/intense/block_tests.cpp | 2 +- tests/tests/block_tests.cpp | 60 +++++++++---------- tests/tests/operation_tests2.cpp | 10 ++-- 10 files changed, 48 insertions(+), 50 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 99131146..94b02511 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -257,7 +257,7 @@ signed_block database::_generate_block( uint32_t skip = get_node_properties().skip_flags; uint32_t slot_num = get_slot_at_time( when ); FC_ASSERT( slot_num > 0 ); - witness_id_type scheduled_witness = get_scheduled_witness( slot_num ).first; + witness_id_type scheduled_witness = get_scheduled_witness( slot_num ); FC_ASSERT( scheduled_witness == witness_id ); const auto& witness_obj = witness_id(*this); @@ -566,7 +566,7 @@ const witness_object& database::validate_block_header( uint32_t skip, const sign uint32_t slot_num = get_slot_at_time( next_block.timestamp ); FC_ASSERT( slot_num > 0 ); - witness_id_type scheduled_witness = get_scheduled_witness( slot_num ).first; + witness_id_type scheduled_witness = get_scheduled_witness( slot_num ); FC_ASSERT( next_block.witness == scheduled_witness ); } diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 2cb8b711..90aab09e 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -23,10 +23,10 @@ namespace graphene { namespace chain { -pair database::get_scheduled_witness(uint32_t slot_num)const +witness_id_type database::get_scheduled_witness(uint32_t slot_num)const { if( slot_num == 0 ) - return pair(witness_id_type(), false); + return witness_id_type(); const witness_schedule_object& wso = witness_schedule_id_type()(*this); @@ -53,7 +53,7 @@ pair database::get_scheduled_witness(uint32_t slot_num)co assert( false ); } } - return pair(wid, slot_is_near); + return wid; } fc::time_point_sec database::get_slot_time(uint32_t slot_num)const diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index e1a56e90..99df3cb0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -220,11 +220,9 @@ namespace graphene { namespace chain { * Use the get_slot_time() and get_slot_at_time() functions * to convert between slot_num and timestamp. * - * Passing slot_num == 0 returns (witness_id_type(), false) - * - * The bool value is true if near schedule, false if far schedule. + * Passing slot_num == 0 returns witness_id_type() */ - pair get_scheduled_witness(uint32_t slot_num)const; + witness_id_type get_scheduled_witness(uint32_t slot_num)const; /** * Get the time at which the given slot occurs. diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 637447ee..9290837d 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -177,7 +177,7 @@ void witness_plugin::block_production_loop() // is anyone scheduled to produce now or one second in the future? const fc::time_point_sec now = graphene::time::now(); uint32_t slot = db.get_slot_at_time( now ); - graphene::chain::witness_id_type scheduled_witness = db.get_scheduled_witness( slot ).first; + graphene::chain::witness_id_type scheduled_witness = db.get_scheduled_witness( slot ); fc::time_point_sec scheduled_time = db.get_slot_time( slot ); graphene::chain::public_key_type scheduled_key = scheduled_witness( db ).signing_key; diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 1e7bfcad..b498ec01 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) auto block_1 = db2->generate_block( db2->get_slot_time(1), - db2->get_scheduled_witness(1).first, + db2->get_scheduled_witness(1), committee_key, database::skip_nothing); diff --git a/tests/benchmarks/genesis_allocation.cpp b/tests/benchmarks/genesis_allocation.cpp index eb93700a..5dedaedf 100644 --- a/tests/benchmarks/genesis_allocation.cpp +++ b/tests/benchmarks/genesis_allocation.cpp @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) int blocks_out = 0; auto witness_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); auto aw = db.get_global_properties().active_witnesses; - auto b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, witness_priv_key, ~0 ); + auto b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ), witness_priv_key, ~0 ); start_time = fc::time_point::now(); /* TODO: get this buliding again @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) db.push_transaction(trx, ~0); aw = db.get_global_properties().active_witnesses; - b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, witness_priv_key, ~0 ); + b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ), witness_priv_key, ~0 ); } */ ilog("Pushed ${c} blocks (1 op each, no validation) in ${t} milliseconds.", diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 53cbd00a..61fb036d 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -297,7 +297,7 @@ signed_block database_fixture::generate_block(uint32_t skip, const fc::ecc::priv skip |= database::skip_undo_history_check; // skip == ~0 will skip checks specified in database::validation_steps return db.generate_block(db.get_slot_time(miss_blocks + 1), - db.get_scheduled_witness(miss_blocks + 1).first, + db.get_scheduled_witness(miss_blocks + 1), key, skip); } diff --git a/tests/intense/block_tests.cpp b/tests/intense/block_tests.cpp index e9f1196e..fd77132e 100644 --- a/tests/intense/block_tests.cpp +++ b/tests/intense/block_tests.cpp @@ -279,7 +279,7 @@ BOOST_FIXTURE_TEST_CASE( witness_order_mc_test, database_fixture ) { wdump( (db.head_block_num()) ); } - witness_id_type wid = db.get_scheduled_witness( 1 ).first; + witness_id_type wid = db.get_scheduled_witness( 1 ); full_schedule.push_back( wid ); cur_round.push_back( wid ); if( cur_round.size() == num_witnesses ) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 427fdd51..d8301856 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -131,13 +131,13 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) { database db; db.open(data_dir.path(), make_genesis ); - b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); for( uint32_t i = 1; i < 200; ++i ) { BOOST_CHECK( db.head_block_id() == b.id() ); witness_id_type prev_witness = b.witness; - witness_id_type cur_witness = db.get_scheduled_witness(1).first; + witness_id_type cur_witness = db.get_scheduled_witness(1); BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); BOOST_CHECK( b.witness == cur_witness ); @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) { BOOST_CHECK( db.head_block_id() == b.id() ); witness_id_type prev_witness = b.witness; - witness_id_type cur_witness = db.get_scheduled_witness(1).first; + witness_id_type cur_witness = db.get_scheduled_witness(1); BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); } @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE( undo_block ) { now = db.get_slot_time(1); time_stack.push_back( now ); - auto b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, init_account_priv_key, database::skip_nothing ); + auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing ); } BOOST_CHECK( db.head_block_num() == 5 ); BOOST_CHECK( db.head_block_time() == now ); @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE( undo_block ) { now = db.get_slot_time(1); time_stack.push_back( now ); - auto b = db.generate_block( now, db.get_scheduled_witness( 1 ).first, init_account_priv_key, database::skip_nothing ); + auto b = db.generate_block( now, db.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing ); } BOOST_CHECK( db.head_block_num() == 7 ); } @@ -227,20 +227,20 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); for( uint32_t i = 0; i < 10; ++i ) { - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); try { PUSH_BLOCK( db2, b ); } FC_CAPTURE_AND_RETHROW( ("db2") ); } for( uint32_t i = 10; i < 13; ++i ) { - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); } string db1_tip = db1.head_block_id().str(); uint32_t next_slot = 3; for( uint32_t i = 13; i < 16; ++i ) { - auto b = db2.generate_block(db2.get_slot_time(next_slot), db2.get_scheduled_witness(next_slot).first, init_account_priv_key, database::skip_nothing); + auto b = db2.generate_block(db2.get_slot_time(next_slot), db2.get_scheduled_witness(next_slot), init_account_priv_key, database::skip_nothing); next_slot = 1; // notify both databases of the new block. // only db2 should switch to the new fork, db1 should not @@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) BOOST_CHECK_EQUAL(db1.head_block_num(), 13); BOOST_CHECK_EQUAL(db2.head_block_num(), 13); { - auto b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); good_block = b; b.transactions.emplace_back(signed_transaction()); b.transactions.back().operations.emplace_back(transfer_operation()); @@ -289,18 +289,18 @@ BOOST_AUTO_TEST_CASE( out_of_order_blocks ) BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); - auto b1 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b2 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b3 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b4 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b5 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b6 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b7 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b8 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b9 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b10 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b11 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); - auto b12 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b1 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b2 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b3 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b4 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b5 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b6 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b7 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b8 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b9 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b10 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b11 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + auto b12 = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); BOOST_CHECK_EQUAL(db1.head_block_num(), 12); BOOST_CHECK_EQUAL(db2.head_block_num(), 0); PUSH_BLOCK( db2, b1 ); @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE( undo_pending ) trx.operations.push_back(t); PUSH_TX( db, trx, ~0 ); - auto b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, ~0); + auto b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, ~0); } signed_transaction trx; @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE( undo_pending ) //sign( trx, init_account_priv_key ); PUSH_TX( db, trx ); - auto b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); BOOST_CHECK(nathan_id(db).name == "nathan"); @@ -424,14 +424,14 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) // db2 : B C D auto aw = db1.get_global_properties().active_witnesses; - auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); BOOST_CHECK(nathan_id(db1).name == "nathan"); - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); db1.push_block(b); aw = db2.get_global_properties().active_witnesses; - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); db1.push_block(b); GRAPHENE_CHECK_THROW(nathan_id(db1), fc::exception); @@ -439,7 +439,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) PUSH_TX( db2, trx ); aw = db2.get_global_properties().active_witnesses; - b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + b = db2.generate_block(db2.get_slot_time(1), db2.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); db1.push_block(b); BOOST_CHECK(nathan_id(db1).name == "nathan"); @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) GRAPHENE_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception); - auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ).first, init_account_priv_key, skip_sigs ); + auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key, skip_sigs ); PUSH_BLOCK( db2, b, skip_sigs ); GRAPHENE_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception); @@ -515,7 +515,7 @@ BOOST_AUTO_TEST_CASE( tapos ) public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); const graphene::db::index& account_idx = db1.get_index(protocol_ids, account_object_type); - auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ).first, init_account_priv_key, database::skip_nothing); + auto b = db1.generate_block( db1.get_slot_time(1), db1.get_scheduled_witness( 1 ), init_account_priv_key, database::skip_nothing); signed_transaction trx; //This transaction must be in the next block after its reference, or it is invalid. @@ -531,7 +531,7 @@ BOOST_AUTO_TEST_CASE( tapos ) trx.operations.push_back(cop); trx.sign( init_account_priv_key, db1.get_chain_id() ); db1.push_transaction(trx); - b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); + b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); trx.clear(); transfer_operation t; diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 28192b2e..59c34c92 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -1098,7 +1098,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) BOOST_CHECK(db.find_object(balance_id_type(1)) != nullptr); auto slot = db.get_slot_at_time(starting_time); - db.generate_block(starting_time, db.get_scheduled_witness(slot).first, init_account_priv_key, skip_flags); + db.generate_block(starting_time, db.get_scheduled_witness(slot), init_account_priv_key, skip_flags); set_expiration( db, trx ); const balance_object& vesting_balance_1 = balance_id_type(2)(db); @@ -1149,9 +1149,9 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) // Attempting to claim twice within a day GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_claimed_too_often); - db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, skip_flags); + db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, skip_flags); slot = db.get_slot_at_time(vesting_balance_1.vesting_policy->begin_timestamp + 60); - db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot).first, init_account_priv_key, skip_flags); + db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot), init_account_priv_key, skip_flags); set_expiration( db, trx ); op.balance_to_claim = vesting_balance_1.id; @@ -1175,9 +1175,9 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) // Attempting to claim twice within a day GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_claimed_too_often); - db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, skip_flags); + db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, skip_flags); slot = db.get_slot_at_time(db.head_block_time() + fc::days(1)); - db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot).first, init_account_priv_key, skip_flags); + db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot), init_account_priv_key, skip_flags); set_expiration( db, trx ); op.total_claimed = vesting_balance_2.balance;