Don't infinitely recurse when block generation fails #261

This commit is contained in:
theoreticalbts 2015-08-26 18:13:58 -04:00
parent e5ada2756a
commit 013033001f
2 changed files with 38 additions and 9 deletions

View file

@ -242,7 +242,7 @@ signed_block database::generate_block(
signed_block result;
with_skip_flags( skip, [&]()
{
result = _generate_block( when, witness_id, block_signing_private_key );
result = _generate_block( when, witness_id, block_signing_private_key, true );
} );
return result;
}
@ -250,7 +250,8 @@ signed_block database::generate_block(
signed_block database::_generate_block(
fc::time_point_sec when,
witness_id_type witness_id,
const fc::ecc::private_key& block_signing_private_key
const fc::ecc::private_key& block_signing_private_key,
bool retry_on_failure
)
{
try {
@ -280,18 +281,45 @@ signed_block database::_generate_block(
bool failed = false;
try { push_block( tmp, skip ); }
catch ( const undo_database_exception& e ) { throw; }
catch ( const fc::exception& e ) { failed = true; }
catch ( const fc::exception& e )
{
if( !retry_on_failure )
{
failed = true;
}
else
{
wlog( "Reason for block production failure: ${e}", ("e",e) );
throw;
}
}
if( failed )
{
uint32_t failed_tx_count = 0;
for( const auto& trx : tmp.transactions )
{
try {
push_transaction( trx, skip );
} catch ( const fc::exception& e ) {
wlog( "Transaction is no longer valid: ${trx}", ("trx",trx) );
try
{
push_transaction( trx, skip );
}
catch ( const fc::exception& e )
{
wlog( "Transaction is no longer valid: ${trx}", ("trx",trx) );
failed_tx_count++;
}
}
return _generate_block( when, witness_id, block_signing_private_key );
if( failed_tx_count == 0 )
{
//
// this is in generate_block() so this intensive logging
// (dumping a whole block) should be rate-limited
// to once per block production attempt
//
// TODO: Turn this off again once #261 is resolved.
//
wlog( "Block creation failed even though all tx's are still valid. Block: ${b}", ("b",tmp) );
}
return _generate_block( when, witness_id, block_signing_private_key, false );
}
return tmp;
} FC_CAPTURE_AND_RETHROW( (witness_id) ) }

View file

@ -164,7 +164,8 @@ namespace graphene { namespace chain {
signed_block _generate_block(
const fc::time_point_sec when,
witness_id_type witness_id,
const fc::ecc::private_key& block_signing_private_key
const fc::ecc::private_key& block_signing_private_key,
bool retry_on_failure
);
void pop_block();