diff --git a/libraries/chain/block_header_state.cpp b/libraries/chain/block_header_state.cpp index c6f3e552f937f0fa4f4f83d8bdbc6590089746ff..d6fe99333b390bad00299af5ea91b08d813998b7 100644 --- a/libraries/chain/block_header_state.cpp +++ b/libraries/chain/block_header_state.cpp @@ -85,7 +85,6 @@ namespace eosio { namespace chain { result.block_num = block_num + 1; result.producer_to_last_produced = producer_to_last_produced; result.producer_to_last_produced[prokey.producer_name] = result.block_num; -// result.dpos_irreversible_blocknum = result.calc_dpos_last_irreversible(); result.blockroot_merkle = blockroot_merkle; result.blockroot_merkle.append( id ); @@ -114,20 +113,21 @@ namespace eosio { namespace chain { } /// grow the confirmed count - uint8_t required_confs = (result.active_schedule.producers.size() * 2 / 3) + 1; - if( confirm_count.size() < 1024 ) { + static_assert(std::numeric_limits::max() >= (config::max_producers * 2 / 3) + 1, "8bit confirmations may not be able to hold all of the needed confirmations"); + auto num_active_producers = result.active_schedule.producers.size(); + uint32_t required_confs = (uint32_t)(num_active_producers * 2 / 3) + 1; + + if( confirm_count.size() < config::maximum_tracked_dpos_confirmations ) { result.confirm_count.reserve( confirm_count.size() + 1 ); result.confirm_count = confirm_count; result.confirm_count.resize( confirm_count.size() + 1 ); - result.confirm_count.back() = required_confs; + result.confirm_count.back() = (uint8_t)required_confs; } else { result.confirm_count.resize( confirm_count.size() ); memcpy( &result.confirm_count[0], &confirm_count[1], confirm_count.size() - 1 ); - result.confirm_count.back() = required_confs; + result.confirm_count.back() = (uint8_t)required_confs; } - - return result; } /// generate_next diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 665cf6c9fe9bd41dedb4cd735fe83cc5b3a8e33a..1b6cf8243300ef03041368a0d9ba8d74922661e6 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -22,16 +22,14 @@ struct block_header_state { flat_map producer_to_last_produced; public_key_type block_signing_key; vector confirm_count; + vector confirmations; block_header_state next( const signed_block_header& h )const; block_header_state generate_next( block_timestamp_type when )const; void set_new_producers( producer_schedule_type next_pending ); void set_confirmed( uint16_t num_prev_blocks ); - - void add_confirmation( const header_confirmation& c ); - vector confirmations; bool has_pending_producers()const { return pending_schedule.producers.size(); } @@ -57,8 +55,8 @@ struct block_header_state { } } /// namespace eosio::chain FC_REFLECT( eosio::chain::block_header_state, - (id)(block_num)(header)(dpos_irreversible_blocknum) + (id)(block_num)(header)(dpos_irreversible_blocknum)(bft_irreversible_blocknum) (pending_schedule_lib_num)(pending_schedule_hash) (pending_schedule)(active_schedule)(blockroot_merkle) (producer_to_last_produced)(block_signing_key) - (bft_irreversible_blocknum)(confirmations) ) + (confirm_count)(confirmations) ) diff --git a/libraries/chain/include/eosio/chain/config.hpp b/libraries/chain/include/eosio/chain/config.hpp index 05f72be9744505dd491e96df4216d7c8486f1165..198b152b2ebc8142a466c5671aadb6d2b24050e8 100644 --- a/libraries/chain/include/eosio/chain/config.hpp +++ b/libraries/chain/include/eosio/chain/config.hpp @@ -98,6 +98,11 @@ const static eosio::chain::wasm_interface::vm_type default_wasm_runtime = eosio: * The number of sequential blocks produced by a single producer */ const static int producer_repetitions = 12; +const static int max_producers = 125; + +const static size_t maximum_tracked_dpos_confirmations = 1024; ///< +static_assert(maximum_tracked_dpos_confirmations >= ((max_producers * 2 / 3) + 1) * producer_repetitions, "Settings never allow for DPOS irreversibility" ); + /** * The number of blocks produced per round is based upon all producers having a chance diff --git a/libraries/chain/wasm_interface.cpp b/libraries/chain/wasm_interface.cpp index 77aefc29864ce19e2a508c1fcdf5765edf2c1177..866c6e33e9b77e65f8bb7a970e6b060e251f8eed 100644 --- a/libraries/chain/wasm_interface.cpp +++ b/libraries/chain/wasm_interface.cpp @@ -145,6 +145,7 @@ class privileged_api : public context_aware_api { datastream ds( packed_producer_schedule, datalen ); vector producers; fc::raw::unpack(ds, producers); + EOS_ASSERT(producers.size() <= config::max_producers, wasm_execution_error, "Producer schedule exceeds the maximum producer count for this chain"); // check that producers are unique std::set unique_producers; for (const auto& p: producers) {