Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Progress #10: Fix rsf test
Browse files Browse the repository at this point in the history
Test of the recent slots filled are now working correctly.
  • Loading branch information
nathanielhourt committed Apr 19, 2017
1 parent fcf98b6 commit 1209d32
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
22 changes: 15 additions & 7 deletions libraries/chain/database.cpp
Expand Up @@ -683,7 +683,6 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create global properties
create<global_property_object>([&](global_property_object& p) {
p.parameters = genesis_state.initial_parameters;
//p.active_producers.resize(initial_producers.size());
std::copy(initial_producers.begin(), initial_producers.end(), p.active_producers.begin());
});
create<dynamic_global_property_object>([&](dynamic_global_property_object& p) {
Expand Down Expand Up @@ -828,6 +827,10 @@ void database::update_global_dynamic_data( const signed_block& b )
uint32_t missed_blocks = get_slot_at_time( b.timestamp );
assert( missed_blocks != 0 );
missed_blocks--;

if (missed_blocks)
wlog("Blockchain continuing after gap of ${b} missed blocks", ("b", missed_blocks));

for(uint32_t i = 0; i < missed_blocks; ++i) {
const auto& producer_missed = get(get_scheduled_producer(i+1));
if(producer_missed.id != b.producer) {
Expand All @@ -849,10 +852,15 @@ void database::update_global_dynamic_data( const signed_block& b )
dgp.head_block_id = b.id();
dgp.time = b.timestamp;
dgp.current_producer = b.producer;
dgp.recent_slots_filled = (
(dgp.recent_slots_filled << 1)
+ 1) << missed_blocks;
dgp.current_aslot += missed_blocks+1;
dgp.current_absolute_slot += missed_blocks+1;

// If we've missed more blocks than the bitmap stores, skip calculations and simply reset the bitmap
if (missed_blocks < sizeof(dgp.recent_slots_filled) * 8) {
dgp.recent_slots_filled <<= 1;
dgp.recent_slots_filled += 1;
dgp.recent_slots_filled <<= missed_blocks;
} else
dgp.recent_slots_filled = 0;
});

_fork_db.set_max_size( _dgp.head_block_number - _dgp.last_irreversible_block_num + 1 );
Expand All @@ -861,7 +869,7 @@ void database::update_global_dynamic_data( const signed_block& b )
void database::update_signing_producer(const producer_object& signing_producer, const signed_block& new_block)
{
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
uint64_t new_block_aslot = dpo.current_aslot + get_slot_at_time( new_block.timestamp );
uint64_t new_block_aslot = dpo.current_absolute_slot + get_slot_at_time( new_block.timestamp );

modify( signing_producer, [&]( producer_object& _wit )
{
Expand Down Expand Up @@ -939,7 +947,7 @@ using boost::container::flat_set;
producer_id_type database::get_scheduled_producer(uint32_t slot_num)const
{
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
uint64_t current_aslot = dpo.current_aslot + slot_num;
uint64_t current_aslot = dpo.current_absolute_slot + slot_num;
const auto& gpo = get<global_property_object>();
return gpo.active_producers[current_aslot % gpo.active_producers.size()];
}
Expand Down
6 changes: 4 additions & 2 deletions libraries/chain/include/eos/chain/config.hpp
Expand Up @@ -31,9 +31,11 @@
#define EOS_1_PERCENT (EOS_100_PERCENT/100)
#define EOS_DEFAULT_MAX_BLOCK_SIZE (256*1024)

#define EOS_DEFAULT_PRODUCER_PAY_PER_BLOCK (EOS_BLOCKCHAIN_PRECISION * int64_t( 10) )
#define EOS_DEFAULT_PRODUCER_PAY_PER_BLOCK (EOS_BLOCKCHAIN_PRECISION * int64_t(10))
#define EOS_DEFAULT_MAX_TIME_UNTIL_EXPIRATION (60*60)

#define EOS_IRREVERSIBLE_THRESHOLD (70 * EOS_1_PERCENT)


namespace eos { namespace config {
const static int EOS_PRODUCER_COUNT = 21;
} } // namespace eos::config
32 changes: 23 additions & 9 deletions libraries/chain/include/eos/chain/global_property_object.hpp
Expand Up @@ -49,7 +49,8 @@ namespace eos { namespace chain {

id_type id;
chain_parameters parameters;
std::array<producer_id_type,21> active_producers;

std::array<producer_id_type, config::EOS_PRODUCER_COUNT> active_producers;
};


Expand All @@ -75,15 +76,28 @@ namespace eos { namespace chain {
uint32_t accounts_registered_this_interval = 0;

/**
* The current absolute slot number. Equal to the total
* number of slots since genesis. Also equal to the total
* number of missed slots plus head_block_number.
*/
uint64_t current_aslot = 0;
* The current absolute slot number. Equal to the total
* number of slots since genesis. Also equal to the total
* number of missed slots plus head_block_number.
*/
uint64_t current_absolute_slot = 0;

/**
* Used to compute producer participation.
*/
* Bitmap used to compute producer participation. Stores
* a high bit for each generated block, a low bit for
* each missed block. Least significant bit is most
* recent block.
*
* NOTE: This bitmap always excludes the head block,
* which, by definition, exists. The least significant
* bit corresponds to the block with number
* head_block_num()-1
*
* e.g. if the least significant 5 bits were 10011, it
* would indicate that the last two blocks prior to the
* head block were produced, the two before them were
* missed, and the one before that was produced.
*/
uint64_t recent_slots_filled;

uint32_t last_irreversible_block_num = 0;
Expand Down Expand Up @@ -119,7 +133,7 @@ FC_REFLECT(eos::chain::dynamic_global_property_object,
(time)
(current_producer)
(accounts_registered_this_interval)
(current_aslot)
(current_absolute_slot)
(recent_slots_filled)
(last_irreversible_block_num)
)
Expand Down
Expand Up @@ -33,7 +33,7 @@ namespace eos { namespace chain {

struct immutable_chain_parameters
{
uint16_t min_producer_count = 21;
uint16_t min_producer_count = config::EOS_PRODUCER_COUNT;
};

} } // eos::chain
Expand Down
16 changes: 8 additions & 8 deletions tests/tests/block_tests.cpp
Expand Up @@ -244,22 +244,22 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );

db.produce_blocks(1, 64);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000000000000000000000000000000000000"
"1111100000000000001000000001000001000100101011111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(31) );
*/
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(0) );

db.produce_blocks(1, 63);
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000000000000000000000000000000000001"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(1) );

db.produce_blocks(1, 32);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000010000000000000000000000000000000"
"0000000000000000000000000000000001111100000000000001000000001000"
);
*/
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(8) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(1) );
} FC_LOG_AND_RETHROW() }

// Check that a db rewinds to the LIB after being closed and reopened
Expand Down

0 comments on commit 1209d32

Please sign in to comment.