Implement last_irreversible_block_num
This commit is contained in:
parent
f05a7bbc97
commit
93a108487d
6 changed files with 47 additions and 2 deletions
|
|
@ -479,6 +479,7 @@ void database::_apply_block( const signed_block& next_block )
|
||||||
|
|
||||||
update_global_dynamic_data(next_block);
|
update_global_dynamic_data(next_block);
|
||||||
update_signing_witness(signing_witness, next_block);
|
update_signing_witness(signing_witness, next_block);
|
||||||
|
update_last_irreversible_block();
|
||||||
|
|
||||||
// Are we at the maintenance interval?
|
// Are we at the maintenance interval?
|
||||||
if( maint_needed )
|
if( maint_needed )
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,45 @@ void database::update_signing_witness(const witness_object& signing_witness, con
|
||||||
modify( signing_witness, [&]( witness_object& _wit )
|
modify( signing_witness, [&]( witness_object& _wit )
|
||||||
{
|
{
|
||||||
_wit.last_aslot = new_block_aslot;
|
_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()
|
void database::clear_expired_transactions()
|
||||||
{
|
{
|
||||||
//Look for expired transactions in the deduplication list, and remove them.
|
//Look for expired transactions in the deduplication list, and remove them.
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,9 @@
|
||||||
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
|
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
|
||||||
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
|
#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
|
* Reserved Account IDs with special meaning
|
||||||
|
|
|
||||||
|
|
@ -422,6 +422,7 @@ namespace graphene { namespace chain {
|
||||||
//////////////////// db_update.cpp ////////////////////
|
//////////////////// db_update.cpp ////////////////////
|
||||||
void update_global_dynamic_data( const signed_block& b );
|
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_signing_witness(const witness_object& signing_witness, const signed_block& new_block);
|
||||||
|
void update_last_irreversible_block();
|
||||||
void clear_expired_transactions();
|
void clear_expired_transactions();
|
||||||
void clear_expired_proposals();
|
void clear_expired_proposals();
|
||||||
void clear_expired_orders();
|
void clear_expired_orders();
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ namespace graphene { namespace chain {
|
||||||
*/
|
*/
|
||||||
uint32_t dynamic_flags = 0;
|
uint32_t dynamic_flags = 0;
|
||||||
|
|
||||||
|
uint32_t last_irreversible_block_num = 0;
|
||||||
|
|
||||||
enum dynamic_flag_bits
|
enum dynamic_flag_bits
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,6 +131,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::
|
||||||
(current_aslot)
|
(current_aslot)
|
||||||
(recent_slots_filled)
|
(recent_slots_filled)
|
||||||
(dynamic_flags)
|
(dynamic_flags)
|
||||||
|
(last_irreversible_block_num)
|
||||||
)
|
)
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::global_property_object, (graphene::db::object),
|
FC_REFLECT_DERIVED( graphene::chain::global_property_object, (graphene::db::object),
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ namespace graphene { namespace chain {
|
||||||
vote_id_type vote_id;
|
vote_id_type vote_id;
|
||||||
uint64_t total_votes = 0;
|
uint64_t total_votes = 0;
|
||||||
string url;
|
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) {}
|
witness_object() : vote_id(vote_id_type::witness) {}
|
||||||
};
|
};
|
||||||
|
|
@ -72,4 +73,5 @@ FC_REFLECT_DERIVED( graphene::chain::witness_object, (graphene::db::object),
|
||||||
(total_votes)
|
(total_votes)
|
||||||
(url)
|
(url)
|
||||||
(total_missed)
|
(total_missed)
|
||||||
|
(last_confirmed_block_num)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue