diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 2a0754ef..be71012d 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -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 ) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 99131146..89dd4613 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -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 ) ); diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index ded6a04a..da6e84ef 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -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 } ); } diff --git a/libraries/chain/db_witness_schedule.cpp b/libraries/chain/db_witness_schedule.cpp index 2cb8b711..30389bc8 100644 --- a/libraries/chain/db_witness_schedule.cpp +++ b/libraries/chain/db_witness_schedule.cpp @@ -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 = ( diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index dacb5ce2..82a5703b 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -42,7 +42,7 @@ namespace graphene { namespace chain { chain_parameters parameters; optional pending_parameters; - uint32_t next_available_vote_id = 0; + uint32_t next_available_vote_id = 0; vector active_committee_members; // updated once per maintenance interval flat_set 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 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), diff --git a/libraries/chain/include/graphene/chain/protocol/block.hpp b/libraries/chain/include/graphene/chain/protocol/block.hpp index d9e882a1..34b0cfc2 100644 --- a/libraries/chain/include/graphene/chain/protocol/block.hpp +++ b/libraries/chain/include/graphene/chain/protocol/block.hpp @@ -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) ) diff --git a/libraries/chain/include/graphene/chain/witness_object.hpp b/libraries/chain/include/graphene/chain/witness_object.hpp index 17b94ed5..0b392eb8 100644 --- a/libraries/chain/include/graphene/chain/witness_object.hpp +++ b/libraries/chain/include/graphene/chain/witness_object.hpp @@ -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) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index f34dbdb7..b61c752c 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -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 diff --git a/programs/size_checker/main.cpp b/programs/size_checker/main.cpp index 5950f6aa..0d3fc7f1 100644 --- a/programs/size_checker/main.cpp +++ b/programs/size_checker/main.cpp @@ -64,6 +64,20 @@ int main( int argc, char** argv ) { graphene::chain::operation op; + + vector 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)));