adding checkpoints #121 to database

This commit is contained in:
Daniel Larimer 2015-07-09 14:09:21 -04:00
parent 84a83042ff
commit c49fbd87e7
3 changed files with 28 additions and 1 deletions

View file

@ -82,6 +82,7 @@ const signed_transaction& database::get_recent_transaction(const transaction_id_
*/
bool database::push_block(const signed_block& new_block, uint32_t skip)
{
bool result;
with_skip_flags( skip, [&]()
{
@ -365,6 +366,21 @@ const vector<operation_history_object>& database::get_applied_operations() const
void database::apply_block( const signed_block& next_block, uint32_t skip )
{
auto block_num = next_block.block_num();
if( _checkpoints.size() )
{
auto itr = _checkpoints.find( block_num );
if( itr != _checkpoints.end() )
FC_ASSERT( next_block.id() == itr->second, "Block did not match checkpoint", ("checkpoint",*itr)("block_id",next_block.id()) );
auto last = _checkpoints.rbegin();
if( last->first >= block_num )
{
// WE CAN SKIP ALMOST EVERYTHING
skip = ~0;
}
}
with_skip_flags( skip, [&]()
{
_apply_block( next_block );
@ -649,4 +665,10 @@ void database::create_block_summary(const signed_block& next_block)
FC_ASSERT( sum.id.instance() == next_block.block_num(), "", ("summary.id",sum.id)("next.block_num",next_block.block_num()) );
}
void database::add_checkpoints( const flat_map<uint32_t,block_id_type>& checkpts )
{
for( const auto& i : checkpts )
_checkpoints[i.first] = i.second;
}
} }

View file

@ -136,6 +136,9 @@ namespace graphene { namespace chain {
optional<signed_block> fetch_block_by_number( uint32_t num )const;
const signed_transaction& get_recent_transaction( const transaction_id_type& trx_id )const;
void add_checkpoints( const flat_map<uint32_t,block_id_type>& checkpts );
const flat_map<uint32_t,block_id_type> get_checkpoints()const { return _checkpoints; }
bool push_block( const signed_block& b, uint32_t skip = skip_nothing );
processed_transaction push_transaction( const signed_transaction& trx, uint32_t skip = skip_nothing );
bool _push_block( const signed_block& b );
@ -470,6 +473,8 @@ namespace graphene { namespace chain {
vector<uint64_t> _committee_count_histogram_buffer;
uint64_t _total_voting_stake;
flat_map<uint32_t,block_id_type> _checkpoints;
node_property_object _node_property_object;
};

View file

@ -54,5 +54,5 @@ namespace graphene { namespace chain {
} } // graphene::chain
FC_REFLECT_TYPENAME( graphene::chain::fee_parameters )
FC_REFLECT( graphene::chain::fee_schedule, (parameters) )
FC_REFLECT( graphene::chain::fee_schedule, (parameters)(scale) )