From a536d392539ac3362baaeb1c8c3533f54ccae3d7 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 8 Oct 2015 14:01:41 -0400 Subject: [PATCH] TESTNET RESET REQUIRED - convert all hashed indexs to ordered indexes Fix #362 by replacing non-deterministic hashed indexes with ordered indexes Remove HARDFORK check for witness ordering because this #362 will require a test net reset to effeciently implment. Changed the order in wich process_fees iterates accounts to be "by_name" rather than "by_id" so that we retain the ability to switch back to hashed indexes in the future. This change was overly pestimistic and assumes all indexes may be traversed as part of consensus. We want to reserve the ability to change some of the indices back to hashed indicies in the future after a through audit reveals that they are never iterated over in order. --- libraries/chain/db_block.cpp | 18 ++---------------- libraries/chain/db_maint.cpp | 2 +- .../include/graphene/chain/account_object.hpp | 4 ++-- .../include/graphene/chain/asset_object.hpp | 4 ++-- .../include/graphene/chain/balance_object.hpp | 2 +- .../graphene/chain/committee_member_object.hpp | 4 ++-- .../graphene/chain/market_evaluator.hpp | 6 +++--- .../include/graphene/chain/proposal_object.hpp | 2 +- .../graphene/chain/transaction_object.hpp | 2 +- .../graphene/chain/vesting_balance_object.hpp | 2 +- .../chain/withdraw_permission_object.hpp | 6 +++--- .../include/graphene/chain/witness_object.hpp | 6 +++--- 12 files changed, 22 insertions(+), 36 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 217949d4..f2652ac8 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -640,23 +640,9 @@ const witness_object& database::validate_block_header( uint32_t skip, const sign witness_id_type scheduled_witness = get_scheduled_witness( slot_num ); -#warning REMOVE HARDFORK in final release check - if( next_block.block_num() > 58500 ) { - FC_ASSERT( next_block.witness == scheduled_witness, "Witness produced block at wrong time", - ("block witness",next_block.witness)("scheduled",scheduled_witness)("slot_num",slot_num) ); - } - } /*else { - uint32_t slot_num = get_slot_at_time( next_block.timestamp ); - FC_ASSERT( slot_num > 0 ); - - const witness_schedule_object& wso = witness_schedule_id_type()(*this); - const dynamic_global_property_object& dpo = get_dynamic_global_properties(); - - witness_id_type scheduled_witness = get_scheduled_witness( slot_num ); - if( next_block.witness != scheduled_witness ) - edump( (next_block.block_num())(next_block.witness)(scheduled_witness)(slot_num)(wso)(dpo.current_aslot) ); + FC_ASSERT( next_block.witness == scheduled_witness, "Witness produced block at wrong time", + ("block witness",next_block.witness)("scheduled",scheduled_witness)("slot_num",slot_num) ); } - */ return witness; } diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 20541344..748681b7 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -47,7 +47,7 @@ vector> database::sort template void database::perform_account_maintenance(std::tuple helpers) { - const auto& idx = get_index_type().indices(); + const auto& idx = get_index_type().indices().get(); for( const account_object& a : idx ) detail::for_each(helpers, a, detail::gen_seq()); } diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 27c80523..44cd4218 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -288,7 +288,7 @@ namespace graphene { namespace chain { account_balance_object, indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, - hashed_unique< tag, composite_key< + ordered_unique< tag, composite_key< account_balance_object, member, member > @@ -311,7 +311,7 @@ namespace graphene { namespace chain { typedef multi_index_container< account_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, member > > > account_multi_index_type; diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 6586c5a7..f9328be8 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -215,7 +215,7 @@ namespace graphene { namespace chain { typedef multi_index_container< asset_bitasset_data_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, const_mem_fun< asset_bitasset_data_object, time_point_sec, &asset_bitasset_data_object::feed_expiration_time > > @@ -227,7 +227,7 @@ namespace graphene { namespace chain { typedef multi_index_container< asset_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, member > > > asset_object_multi_index_type; diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index 82828f7c..342a1ce3 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -33,7 +33,7 @@ namespace graphene { namespace chain { using balance_multi_index_type = multi_index_container< balance_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, composite_key< balance_object, member, diff --git a/libraries/chain/include/graphene/chain/committee_member_object.hpp b/libraries/chain/include/graphene/chain/committee_member_object.hpp index 2ab34ac7..6d12da99 100644 --- a/libraries/chain/include/graphene/chain/committee_member_object.hpp +++ b/libraries/chain/include/graphene/chain/committee_member_object.hpp @@ -56,10 +56,10 @@ namespace graphene { namespace chain { ordered_unique< tag, member >, - hashed_unique< tag, + ordered_unique< tag, member >, - hashed_unique< tag, + ordered_unique< tag, member > > diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index 5f60c12f..d23e19ff 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -45,7 +45,7 @@ namespace graphene { namespace chain { typedef multi_index_container< limit_order_object, indexed_by< - hashed_unique< tag, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, member< limit_order_object, time_point_sec, &limit_order_object::expiration> >, ordered_unique< tag, @@ -112,7 +112,7 @@ namespace graphene { namespace chain { typedef multi_index_container< call_order_object, indexed_by< - hashed_unique< tag, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< call_order_object, @@ -140,7 +140,7 @@ namespace graphene { namespace chain { typedef multi_index_container< force_settlement_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, member >, diff --git a/libraries/chain/include/graphene/chain/proposal_object.hpp b/libraries/chain/include/graphene/chain/proposal_object.hpp index eb8d890c..db5f76c1 100644 --- a/libraries/chain/include/graphene/chain/proposal_object.hpp +++ b/libraries/chain/include/graphene/chain/proposal_object.hpp @@ -76,7 +76,7 @@ struct by_expiration{}; typedef boost::multi_index_container< proposal_object, indexed_by< - hashed_unique< tag< by_id >, member< object, object_id_type, &object::id > >, + ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_non_unique< tag< by_expiration >, member< proposal_object, time_point_sec, &proposal_object::expiration_time > > > > proposal_multi_index_container; diff --git a/libraries/chain/include/graphene/chain/transaction_object.hpp b/libraries/chain/include/graphene/chain/transaction_object.hpp index 80be41bf..de963968 100644 --- a/libraries/chain/include/graphene/chain/transaction_object.hpp +++ b/libraries/chain/include/graphene/chain/transaction_object.hpp @@ -56,7 +56,7 @@ namespace graphene { namespace chain { typedef multi_index_container< transaction_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, hashed_unique< tag, BOOST_MULTI_INDEX_MEMBER(transaction_object, transaction_id_type, trx_id), std::hash >, ordered_non_unique< tag, const_mem_fun > > diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index ee14dc89..8e94eb36 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -168,7 +168,7 @@ namespace graphene { namespace chain { typedef multi_index_container< vesting_balance_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, member > diff --git a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp index 145ab5bf..cba5e626 100644 --- a/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp +++ b/libraries/chain/include/graphene/chain/withdraw_permission_object.hpp @@ -71,9 +71,9 @@ namespace graphene { namespace chain { typedef multi_index_container< withdraw_permission_object, indexed_by< - hashed_unique< tag, member< object, object_id_type, &object::id > >, - hashed_non_unique< tag, member >, - hashed_non_unique< tag, member >, + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_non_unique< tag, member >, + ordered_non_unique< tag, member >, ordered_non_unique< tag, member > > > withdraw_permission_object_multi_index_type; diff --git a/libraries/chain/include/graphene/chain/witness_object.hpp b/libraries/chain/include/graphene/chain/witness_object.hpp index e3ac8fba..c2cc6b31 100644 --- a/libraries/chain/include/graphene/chain/witness_object.hpp +++ b/libraries/chain/include/graphene/chain/witness_object.hpp @@ -50,13 +50,13 @@ namespace graphene { namespace chain { using witness_multi_index_type = multi_index_container< witness_object, indexed_by< - hashed_unique< tag, + ordered_unique< tag, member >, - hashed_unique< tag, + ordered_unique< tag, member >, - hashed_unique< tag, + ordered_unique< tag, member > >