Skip to content

Commit

Permalink
Remove block_stats_object #675
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Dec 13, 2016
1 parent adae614 commit d4ba29d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 46 deletions.
28 changes: 13 additions & 15 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( [&]()
{
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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<signed_block> database::fetch_block_by_id( const block_id_type& id )const
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 0 additions & 30 deletions libraries/chain/include/steemit/chain/block_summary_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
2 changes: 1 addition & 1 deletion libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
Expand Down

0 comments on commit d4ba29d

Please sign in to comment.