Implement last_irreversible_block_num

This commit is contained in:
theoreticalbts 2015-10-02 17:19:03 -04:00
parent f05a7bbc97
commit 93a108487d
6 changed files with 47 additions and 2 deletions

View file

@ -479,6 +479,7 @@ void database::_apply_block( const signed_block& next_block )
update_global_dynamic_data(next_block);
update_signing_witness(signing_witness, next_block);
update_last_irreversible_block();
// Are we at the maintenance interval?
if( maint_needed )

View file

@ -108,9 +108,45 @@ void database::update_signing_witness(const witness_object& signing_witness, con
modify( signing_witness, [&]( witness_object& _wit )
{
_wit.last_aslot = new_block_aslot;
_wit.last_confirmed_block_num = new_block.block_num();
} );
}
void database::update_last_irreversible_block()
{
const global_property_object& gpo = get_global_properties();
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
vector< const witness_object* > wit_objs;
wit_objs.reserve( gpo.active_witnesses.size() );
for( const witness_id_type& wid : gpo.active_witnesses )
wit_objs.push_back( &(wid(*this)) );
static_assert( GRAPHENE_IRREVERSIBLE_THRESHOLD > 0, "irreversible threshold must be nonzero" );
// 1 1 1 2 2 2 2 2 2 2 -> 2 .7*10 = 7
// 1 1 1 1 1 1 1 2 2 2 -> 1
// 3 3 3 3 3 3 3 3 3 3 -> 3
size_t offset = ((GRAPHENE_100_PERCENT - GRAPHENE_IRREVERSIBLE_THRESHOLD) * wit_objs.size() / GRAPHENE_100_PERCENT);
std::nth_element( wit_objs.begin(), wit_objs.begin() + offset, wit_objs.end(),
[]( const witness_object* a, const witness_object* b )
{
return a->last_confirmed_block_num < b->last_confirmed_block_num;
} );
uint32_t new_last_irreversible_block_num = wit_objs[offset]->last_confirmed_block_num;
if( new_last_irreversible_block_num > dpo.last_irreversible_block_num )
{
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.last_irreversible_block_num = new_last_irreversible_block_num;
} );
}
}
void database::clear_expired_transactions()
{
//Look for expired transactions in the deduplication list, and remove them.

View file

@ -135,7 +135,9 @@
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
#define GRAPHENE_CURRENT_DB_VERSION "test3d"
#define GRAPHENE_CURRENT_DB_VERSION "test5b"
#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)
/**
* Reserved Account IDs with special meaning

View file

@ -422,6 +422,7 @@ namespace graphene { namespace chain {
//////////////////// db_update.cpp ////////////////////
void update_global_dynamic_data( const signed_block& b );
void update_signing_witness(const witness_object& signing_witness, const signed_block& new_block);
void update_last_irreversible_block();
void clear_expired_transactions();
void clear_expired_proposals();
void clear_expired_orders();

View file

@ -101,6 +101,8 @@ namespace graphene { namespace chain {
*/
uint32_t dynamic_flags = 0;
uint32_t last_irreversible_block_num = 0;
enum dynamic_flag_bits
{
/**
@ -129,6 +131,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::
(current_aslot)
(recent_slots_filled)
(dynamic_flags)
(last_irreversible_block_num)
)
FC_REFLECT_DERIVED( graphene::chain::global_property_object, (graphene::db::object),

View file

@ -38,7 +38,8 @@ namespace graphene { namespace chain {
vote_id_type vote_id;
uint64_t total_votes = 0;
string url;
int64_t total_missed = 0;
int64_t total_missed = 0;
uint32_t last_confirmed_block_num = 0;
witness_object() : vote_id(vote_id_type::witness) {}
};
@ -72,4 +73,5 @@ FC_REFLECT_DERIVED( graphene::chain::witness_object, (graphene::db::object),
(total_votes)
(url)
(total_missed)
(last_confirmed_block_num)
)