Skip to content

Commit

Permalink
Fix block generation logic to account for correct header size #2632
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Jul 13, 2018
1 parent 21df985 commit 1c79222
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions libraries/chain/database.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -902,36 +931,13 @@ 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 );

idump( (fc::raw::pack_size(pending_block)) );

// TODO: Move this to _push_block() so session is restored.
if( !(skip & skip_block_size_check) )
{
Expand Down

0 comments on commit 1c79222

Please sign in to comment.