From ee343eeac4044c0fffdb593668e7334c200f1902 Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Fri, 13 Jul 2018 11:38:59 -0700 Subject: [PATCH] Fix block generation logic to account for correct header size #2632 --- libraries/chain/database.cpp | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 189fce7657..856f9703dd 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -834,11 +834,40 @@ signed_block database::_generate_block( if( !(skip & skip_witness_signature) ) FC_ASSERT( witness_obj.signing_key == block_signing_private_key.get_public_key() ); - static const size_t max_block_header_size = fc::raw::pack_size( signed_block_header() ) + 4; + signed_block pending_block; + + pending_block.previous = head_block_id(); + pending_block.timestamp = when; + pending_block.witness = witness_owner; + + if( has_hardfork( STEEM_HARDFORK_0_5__54 ) ) + { + const auto& witness = get_witness( witness_owner ); + + if( witness.running_version != STEEM_BLOCKCHAIN_VERSION ) + pending_block.extensions.insert( block_header_extensions( STEEM_BLOCKCHAIN_VERSION ) ); + + const auto& hfp = get_hardfork_property_object(); + + if( hfp.current_hardfork_version < STEEM_BLOCKCHAIN_VERSION // Binary is newer hardfork than has been applied + && ( witness.hardfork_version_vote != _hardfork_versions[ hfp.last_hardfork + 1 ] || witness.hardfork_time_vote != _hardfork_times[ hfp.last_hardfork + 1 ] ) ) // Witness vote does not match binary configuration + { + // Make vote match binary configuration + pending_block.extensions.insert( block_header_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork + 1 ], _hardfork_times[ hfp.last_hardfork + 1 ] ) ) ); + } + else if( hfp.current_hardfork_version == STEEM_BLOCKCHAIN_VERSION // Binary does not know of a new hardfork + && witness.hardfork_version_vote > STEEM_BLOCKCHAIN_VERSION ) // Voting for hardfork in the future, that we do not know of... + { + // Make vote match binary configuration. This is vote to not apply the new hardfork. + pending_block.extensions.insert( block_header_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork ], _hardfork_times[ hfp.last_hardfork ] ) ) ); + } + } + + // The 4 is for the max size of the transaction vector length + size_t total_block_size = fc::raw::pack_size( pending_block ) + 4; auto maximum_block_size = get_dynamic_global_properties().maximum_block_size; //STEEM_MAX_BLOCK_SIZE; - size_t total_block_size = max_block_header_size; - signed_block pending_block; + idump( (total_block_size) ); // // The following code throws away existing pending_tx_session and @@ -902,32 +931,7 @@ signed_block database::_generate_block( // However, the push_block() call below will re-create the // _pending_tx_session. - pending_block.previous = head_block_id(); - pending_block.timestamp = when; pending_block.transaction_merkle_root = pending_block.calculate_merkle_root(); - pending_block.witness = witness_owner; - if( has_hardfork( STEEM_HARDFORK_0_5__54 ) ) - { - const auto& witness = get_witness( witness_owner ); - - if( witness.running_version != STEEM_BLOCKCHAIN_VERSION ) - pending_block.extensions.insert( block_header_extensions( STEEM_BLOCKCHAIN_VERSION ) ); - - const auto& hfp = get_hardfork_property_object(); - - if( hfp.current_hardfork_version < STEEM_BLOCKCHAIN_VERSION // Binary is newer hardfork than has been applied - && ( witness.hardfork_version_vote != _hardfork_versions[ hfp.last_hardfork + 1 ] || witness.hardfork_time_vote != _hardfork_times[ hfp.last_hardfork + 1 ] ) ) // Witness vote does not match binary configuration - { - // Make vote match binary configuration - pending_block.extensions.insert( block_header_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork + 1 ], _hardfork_times[ hfp.last_hardfork + 1 ] ) ) ); - } - else if( hfp.current_hardfork_version == STEEM_BLOCKCHAIN_VERSION // Binary does not know of a new hardfork - && witness.hardfork_version_vote > STEEM_BLOCKCHAIN_VERSION ) // Voting for hardfork in the future, that we do not know of... - { - // Make vote match binary configuration. This is vote to not apply the new hardfork. - pending_block.extensions.insert( block_header_extensions( hardfork_version_vote( _hardfork_versions[ hfp.last_hardfork ], _hardfork_times[ hfp.last_hardfork ] ) ) ); - } - } if( !(skip & skip_witness_signature) ) pending_block.sign( block_signing_private_key );