progress toward witness schedule refactor
This commit is contained in:
parent
cb3c23a17b
commit
a79eff2761
9 changed files with 31 additions and 41 deletions
|
|
@ -4,7 +4,7 @@ add_subdirectory( deterministic_openssl_rand )
|
|||
add_subdirectory( chain )
|
||||
add_subdirectory( egenesis )
|
||||
add_subdirectory( net )
|
||||
add_subdirectory( p2p )
|
||||
#add_subdirectory( p2p )
|
||||
add_subdirectory( time )
|
||||
add_subdirectory( utilities )
|
||||
add_subdirectory( app )
|
||||
|
|
|
|||
|
|
@ -267,24 +267,6 @@ signed_block database::_generate_block(
|
|||
|
||||
_pending_block.timestamp = when;
|
||||
|
||||
// Genesis witnesses start with a default initial secret
|
||||
if( witness_obj.next_secret_hash == secret_hash_type::hash( secret_hash_type() ) )
|
||||
{
|
||||
_pending_block.previous_secret = secret_hash_type();
|
||||
}
|
||||
else
|
||||
{
|
||||
secret_hash_type::encoder last_enc;
|
||||
fc::raw::pack( last_enc, block_signing_private_key );
|
||||
fc::raw::pack( last_enc, witness_obj.previous_secret );
|
||||
_pending_block.previous_secret = last_enc.result();
|
||||
}
|
||||
|
||||
secret_hash_type::encoder next_enc;
|
||||
fc::raw::pack( next_enc, block_signing_private_key );
|
||||
fc::raw::pack( next_enc, _pending_block.previous_secret );
|
||||
_pending_block.next_secret_hash = secret_hash_type::hash(next_enc.result());
|
||||
|
||||
_pending_block.transaction_merkle_root = _pending_block.calculate_merkle_root();
|
||||
|
||||
_pending_block.witness = witness_id;
|
||||
|
|
@ -555,8 +537,6 @@ const witness_object& database::validate_block_header( uint32_t skip, const sign
|
|||
FC_ASSERT( _pending_block.previous == next_block.previous, "", ("pending.prev",_pending_block.previous)("next.prev",next_block.previous) );
|
||||
FC_ASSERT( _pending_block.timestamp <= next_block.timestamp, "", ("_pending_block.timestamp",_pending_block.timestamp)("next",next_block.timestamp)("blocknum",next_block.block_num()) );
|
||||
const witness_object& witness = next_block.witness(*this);
|
||||
FC_ASSERT( secret_hash_type::hash( next_block.previous_secret ) == witness.next_secret_hash, "",
|
||||
("previous_secret", next_block.previous_secret)("next_secret_hash", witness.next_secret_hash));
|
||||
|
||||
if( !(skip&skip_witness_signature) )
|
||||
FC_ASSERT( next_block.validate_signee( witness.signing_key ) );
|
||||
|
|
|
|||
|
|
@ -44,11 +44,6 @@ void database::update_global_dynamic_data( const signed_block& b )
|
|||
|
||||
// dynamic global properties updating
|
||||
modify( _dgp, [&]( dynamic_global_property_object& dgp ){
|
||||
secret_hash_type::encoder enc;
|
||||
fc::raw::pack( enc, dgp.random );
|
||||
fc::raw::pack( enc, b.previous_secret );
|
||||
dgp.random = enc.result();
|
||||
|
||||
if( _checkpoints.size() && _checkpoints.rbegin()->first >= b.block_num() )
|
||||
dgp.recently_missed_count = 0;
|
||||
else if( missed_blocks )
|
||||
|
|
@ -92,8 +87,7 @@ void database::update_signing_witness(const witness_object& signing_witness, con
|
|||
|
||||
modify( signing_witness, [&]( witness_object& _wit )
|
||||
{
|
||||
_wit.previous_secret = new_block.previous_secret;
|
||||
_wit.next_secret_hash = new_block.next_secret_hash;
|
||||
_wit.last_slot_num = new_block.block_num(); /// TODO: plus total missed blocks
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,9 +132,8 @@ void database::update_witness_schedule(const signed_block& next_block)
|
|||
|
||||
witness_id_type wit;
|
||||
|
||||
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
||||
//const dynamic_global_property_object& dpo = get_dynamic_global_properties();
|
||||
|
||||
assert( dpo.random.data_size() == witness_scheduler_rng::seed_length );
|
||||
assert( witness_scheduler_rng::seed_length == wso.rng_seed.size() );
|
||||
|
||||
modify(wso, [&](witness_schedule_object& _wso)
|
||||
|
|
@ -161,8 +160,9 @@ void database::update_witness_schedule(const signed_block& next_block)
|
|||
}
|
||||
while( !_wso.scheduler.get_slot(schedule_needs_filled, wit) )
|
||||
{
|
||||
auto random = fc::ripemd160::hash( next_block.timestamp );
|
||||
if( _wso.scheduler.produce_schedule(rng) & emit_turn )
|
||||
memcpy(_wso.rng_seed.begin(), dpo.random.data(), dpo.random.data_size());
|
||||
memcpy(_wso.rng_seed.begin(), random.data(), random.data_size());
|
||||
}
|
||||
_wso.last_scheduling_block = next_block.block_num();
|
||||
_wso.recent_slots_filled = (
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace graphene { namespace chain {
|
|||
chain_parameters parameters;
|
||||
optional<chain_parameters> pending_parameters;
|
||||
|
||||
uint32_t next_available_vote_id = 0;
|
||||
uint32_t next_available_vote_id = 0;
|
||||
vector<committee_member_id_type> active_committee_members; // updated once per maintenance interval
|
||||
flat_set<witness_id_type> active_witnesses; // updated once per maintenance interval
|
||||
// n.b. witness scheduling is done by witness_schedule object
|
||||
|
|
@ -64,7 +64,6 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t space_id = implementation_ids;
|
||||
static const uint8_t type_id = impl_dynamic_global_property_object_type;
|
||||
|
||||
secret_hash_type random;
|
||||
uint32_t head_block_number = 0;
|
||||
block_id_type head_block_id;
|
||||
time_point_sec time;
|
||||
|
|
@ -81,6 +80,11 @@ namespace graphene { namespace chain {
|
|||
*/
|
||||
uint32_t recently_missed_count = 0;
|
||||
|
||||
/** this is the set of witnesses that may produce the next block because they
|
||||
* haven't produced any blocks recently.
|
||||
*/
|
||||
vector<witness_id_type> potential_witnesses;
|
||||
|
||||
/**
|
||||
* dynamic_flags specifies chain state properties that can be
|
||||
* expressed in one bit.
|
||||
|
|
@ -104,7 +108,6 @@ namespace graphene { namespace chain {
|
|||
}}
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::db::object),
|
||||
(random)
|
||||
(head_block_number)
|
||||
(head_block_id)
|
||||
(time)
|
||||
|
|
@ -114,6 +117,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::
|
|||
(accounts_registered_this_interval)
|
||||
(recently_missed_count)
|
||||
(dynamic_flags)
|
||||
(potential_witnesses)
|
||||
)
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::global_property_object, (graphene::db::object),
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ namespace graphene { namespace chain {
|
|||
uint32_t block_num()const { return num_from_id(previous) + 1; }
|
||||
fc::time_point_sec timestamp;
|
||||
witness_id_type witness;
|
||||
secret_hash_type next_secret_hash;
|
||||
secret_hash_type previous_secret;
|
||||
checksum_type transaction_merkle_root;
|
||||
extensions_type extensions;
|
||||
|
||||
|
|
@ -53,7 +51,6 @@ namespace graphene { namespace chain {
|
|||
|
||||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT( graphene::chain::block_header, (previous)(timestamp)(witness)
|
||||
(next_secret_hash)(previous_secret)(transaction_merkle_root)(extensions) )
|
||||
FC_REFLECT( graphene::chain::block_header, (previous)(timestamp)(witness)(transaction_merkle_root)(extensions) )
|
||||
FC_REFLECT_DERIVED( graphene::chain::signed_block_header, (graphene::chain::block_header), (witness_signature) )
|
||||
FC_REFLECT_DERIVED( graphene::chain::signed_block, (graphene::chain::signed_block_header), (transactions) )
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = witness_object_type;
|
||||
|
||||
account_id_type witness_account;
|
||||
uint32_t last_slot_num = 0;
|
||||
public_key_type signing_key;
|
||||
secret_hash_type next_secret_hash;
|
||||
secret_hash_type previous_secret;
|
||||
|
|
@ -45,6 +46,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
struct by_account;
|
||||
struct by_vote_id;
|
||||
struct by_last_block;
|
||||
using witness_multi_index_type = multi_index_container<
|
||||
witness_object,
|
||||
indexed_by<
|
||||
|
|
@ -64,9 +66,8 @@ namespace graphene { namespace chain {
|
|||
|
||||
FC_REFLECT_DERIVED( graphene::chain::witness_object, (graphene::db::object),
|
||||
(witness_account)
|
||||
(last_slot_num)
|
||||
(signing_key)
|
||||
(next_secret_hash)
|
||||
(previous_secret)
|
||||
(pay_vb)
|
||||
(vote_id)
|
||||
(total_votes)
|
||||
|
|
|
|||
|
|
@ -478,7 +478,6 @@ public:
|
|||
result["chain_id"] = chain_props.chain_id;
|
||||
result["active_witnesses"] = global_props.active_witnesses;
|
||||
result["active_committee_members"] = global_props.active_committee_members;
|
||||
result["entropy"] = dynamic_props.random;
|
||||
return result;
|
||||
}
|
||||
chain_property_object get_chain_properties() const
|
||||
|
|
|
|||
|
|
@ -64,6 +64,20 @@ int main( int argc, char** argv )
|
|||
{
|
||||
graphene::chain::operation op;
|
||||
|
||||
|
||||
vector<uint64_t> witnesses; witnesses.resize(50);
|
||||
for( uint32_t i = 0; i < 60*60*24*30; ++i )
|
||||
{
|
||||
witnesses[ rand() % 50 ]++;
|
||||
}
|
||||
|
||||
std::sort( witnesses.begin(), witnesses.end() );
|
||||
idump((witnesses.back() - witnesses.front()) );
|
||||
idump((60*60*24*30/50));
|
||||
idump(("deviation: ")((60*60*24*30/50-witnesses.front())/(60*60*24*30/50.0)));
|
||||
|
||||
idump( (witnesses) );
|
||||
|
||||
for( int32_t i = 0; i < op.count(); ++i )
|
||||
{
|
||||
op.set_which(i);
|
||||
|
|
@ -85,6 +99,7 @@ int main( int argc, char** argv )
|
|||
std::cout << "\n";
|
||||
}
|
||||
std::cout << "]\n";
|
||||
std::cerr << "Size of block header: " << sizeof( block_header ) << " " << fc::raw::pack_size( block_header() ) << "\n";
|
||||
}
|
||||
catch ( const fc::exception& e ){ edump((e.to_detail_string())); }
|
||||
idump((sizeof(signed_block)));
|
||||
|
|
|
|||
Loading…
Reference in a new issue