From d4ba29d3ca830bfcce90183d2f1c871b9bd9183b Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Tue, 13 Dec 2016 13:15:00 -0500 Subject: [PATCH] Remove block_stats_object #675 --- libraries/chain/database.cpp | 28 ++++++++--------- .../steemit/chain/block_summary_object.hpp | 30 ------------------- libraries/chain/steem_evaluator.cpp | 2 +- 3 files changed, 14 insertions(+), 46 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index cbb7c0d416..2bad13fb21 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -114,12 +114,6 @@ void database::open( const fc::path& data_dir, const fc::path& shared_mem_dir, u auto log_head = _block_log.head(); - // block_log.head must be in block stats - // If it is not, print warning and exit - if( log_head && head_block_num() ) - FC_ASSERT( get< block_stats_object >( log_head->block_num() - 1 ).block_id == log_head->id(), - "Head block of log file is not included in current chain state. log_head: ${log_head}", ("log_head", log_head) ); - // Rewind all undo state. This should return us to the state at the last irreversible block. with_write_lock( [&]() { @@ -231,7 +225,7 @@ void database::close(bool rewind) bool database::is_known_block( const block_id_type& id )const { - return _fork_db.is_known_block(id) || find< block_stats_object, by_block_id >( id ); + return fetch_block_by_id( id ).valid(); } /** @@ -247,7 +241,18 @@ bool database::is_known_transaction( const transaction_id_type& id )const block_id_type database::get_block_id_for_num( uint32_t block_num )const { - return get< block_stats_object >( block_num - 1 ).block_id; + try + { + auto b = _block_log.read_block_by_num( block_num ); + if( b.valid() ) + return b->id(); + + auto results = _fork_db.fetch_block_by_number( block_num ); + FC_ASSERT( results.size() == 1 ); + return results[0]->data.id(); + + } + FC_CAPTURE_AND_RETHROW( (block_num) ) } optional database::fetch_block_by_id( const block_id_type& id )const @@ -2675,7 +2680,6 @@ void database::initialize_indexes() add_core_index< escrow_index >(*this); add_core_index< savings_withdraw_index >(*this); add_core_index< decline_voting_rights_request_index >(*this); - add_core_index< block_stats_index >(*this); _plugin_index_signal(); } @@ -3043,12 +3047,6 @@ void database::_apply_block( const signed_block& next_block ) ++_current_trx_in_block; } - create< block_stats_object >( [&]( block_stats_object& bso ) - { - assert( bso.block_num() == next_block_num ); // Probably can be taken out. Sanity check - bso.block_id = next_block_id; - }); - update_global_dynamic_data(next_block); update_signing_witness(signing_witness, next_block); diff --git a/libraries/chain/include/steemit/chain/block_summary_object.hpp b/libraries/chain/include/steemit/chain/block_summary_object.hpp index d608eecb08..6ddd98e95c 100644 --- a/libraries/chain/include/steemit/chain/block_summary_object.hpp +++ b/libraries/chain/include/steemit/chain/block_summary_object.hpp @@ -38,37 +38,7 @@ namespace steemit { namespace chain { allocator< block_summary_object > > block_summary_index; - class block_stats_object : public object< block_stats_object_type, block_stats_object > - { - public: - template< typename Constructor, typename Allocator > - block_stats_object( Constructor&& c, allocator< Allocator > a ) - { - c( *this ); - } - - id_type id; - block_id_type block_id; - uint64_t block_num()const { return id._id + 1; } - }; - - struct by_block_id; - - typedef multi_index_container< - block_stats_object, - indexed_by< - ordered_unique< tag< by_id >, - member< block_stats_object, block_stats_id_type, &block_stats_object::id > >, - ordered_unique< tag< by_block_id >, - member< block_stats_object, block_id_type, &block_stats_object::block_id > > - >, - allocator< block_stats_object > - > block_stats_index; - } } // steemit::chain FC_REFLECT( steemit::chain::block_summary_object, (id)(block_id) ) CHAINBASE_SET_INDEX_TYPE( steemit::chain::block_summary_object, steemit::chain::block_summary_index ) - -FC_REFLECT( steemit::chain::block_stats_object, (id)(block_id) ) -CHAINBASE_SET_INDEX_TYPE( steemit::chain::block_stats_object, steemit::chain::block_stats_index ) diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index 7bcfcdfd86..3fec0bc4a5 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -1490,7 +1490,7 @@ void pow2_evaluator::do_apply( const pow2_operation& o ) { const auto& work = o.work.get< equihash_pow >(); FC_ASSERT( work.prev_block == db.head_block_id(), "Equihash pow op not for last block" ); - auto recent_block_num = db.get< block_stats_object, by_block_id >( work.input.prev_block ).block_num(); + auto recent_block_num = protocol::block_header::num_from_id( work.input.prev_block ); FC_ASSERT( recent_block_num > dgp.last_irreversible_block_num, "Equihash pow done for block older than last irreversible block num" ); FC_ASSERT( work.pow_summary < target_pow, "Insufficient work difficulty. Work: ${w}, Target: ${t}", ("w",work.pow_summary)("t", target_pow) );