Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check block size more strictly when generating #1252

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ 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;
static const size_t max_partial_block_header_size = fc::raw::pack_size( signed_block_header() )
- fc::raw::pack_size( witness_id_type() ) // witness_id
+ 4; // space to store size of transactions
const size_t max_block_header_size = max_partial_block_header_size + fc::raw::pack_size( witness_id );
auto maximum_block_size = get_global_properties().parameters.maximum_block_size;
size_t total_block_size = max_block_header_size;

Expand Down Expand Up @@ -373,12 +376,21 @@ signed_block database::_generate_block(
{
auto temp_session = _undo_db.start_undo_session();
processed_transaction ptx = _apply_transaction( tx );
temp_session.merge();

// We have to recompute pack_size(ptx) because it may be different
// than pack_size(tx) (i.e. if one or more results increased
// their size)
total_block_size += fc::raw::pack_size( ptx );
new_total_size = total_block_size + fc::raw::pack_size( ptx );
// postpone transaction if it would make block too big
if( new_total_size >= maximum_block_size )
{
postponed_tx_count++;
continue;
}

temp_session.merge();

total_block_size = new_total_size;
pending_block.transactions.push_back( ptx );
}
catch ( const fc::exception& e )
Expand Down