Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 21 additions & 16 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,26 @@ processed_transaction database::validate_transaction( const signed_transaction&
return _apply_transaction( trx );
}

class push_proposal_nesting_guard {
public:
push_proposal_nesting_guard( uint32_t& nesting_counter, const database& db )
: orig_value(nesting_counter), counter(nesting_counter)
{
FC_ASSERT( counter < db.get_global_properties().active_witnesses.size() * 2, "Max proposal nesting depth exceeded!" );
counter++;
}
~push_proposal_nesting_guard()
{
if( --counter != orig_value )
elog( "Unexpected proposal nesting count value: ${n} != ${o}", ("n",counter)("o",orig_value) );
}
private:
const uint32_t orig_value;
uint32_t& counter;
};

processed_transaction database::push_proposal(const proposal_object& proposal)
{ try {
FC_ASSERT( _undo_db.size() < _undo_db.max_size(), "Undo database is full!" );

transaction_evaluation_state eval_state(this);
eval_state._is_proposed_trx = true;

Expand All @@ -279,6 +295,9 @@ processed_transaction database::push_proposal(const proposal_object& proposal)
size_t old_applied_ops_size = _applied_ops.size();

try {
push_proposal_nesting_guard guard( _push_proposal_nesting_depth, *this );
if( _undo_db.size() >= _undo_db.max_size() )
_undo_db.set_max_size( _undo_db.size() + 1 );
auto session = _undo_db.start_undo_session(true);
for( auto& op : proposal.proposed_transaction.operations )
eval_state.operation_results.emplace_back(apply_operation(eval_state, op));
Expand Down Expand Up @@ -571,19 +590,6 @@ processed_transaction database::apply_transaction(const signed_transaction& trx,
return result;
}

class undo_size_restorer {
public:
undo_size_restorer( undo_database& db ) : _db( db ), old_max( db.max_size() ) {
_db.set_max_size( old_max * 2 );
}
~undo_size_restorer() {
_db.set_max_size( old_max );
}
private:
undo_database& _db;
size_t old_max;
};

processed_transaction database::_apply_transaction(const signed_transaction& trx)
{ try {
uint32_t skip = get_node_properties().skip_flags;
Expand Down Expand Up @@ -637,7 +643,6 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx

eval_state.operation_results.reserve(trx.operations.size());

const undo_size_restorer undo_guard( _undo_db );
//Finally process the operations
processed_transaction ptrx(trx);
_current_op_in_trx = 0;
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ namespace graphene { namespace chain {
*/
bool _opened = false;

// Counts nested proposal updates
uint32_t _push_proposal_nesting_depth = 0;

/// Tracks assets affected by bitshares-core issue #453 before hard fork #615 in one block
flat_set<asset_id_type> _issue_453_affected_assets;

Expand Down
54 changes: 53 additions & 1 deletion tests/tests/authority_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ BOOST_FIXTURE_TEST_CASE( max_authority_membership, database_fixture )
});

transaction tx;
processed_transaction ptx;

private_key_type committee_key = init_account_priv_key;
// Sam is the creator of accounts
Expand Down Expand Up @@ -1448,6 +1447,59 @@ BOOST_FIXTURE_TEST_CASE( parent_owner_test, database_fixture )
}
}

BOOST_AUTO_TEST_CASE( nested_execution )
{ try {
ACTORS( (alice)(bob) );
fund( alice );

generate_blocks( HARDFORK_CORE_214_TIME + fc::hours(1) );
set_expiration( db, trx );

const auto& gpo = db.get_global_properties();

proposal_create_operation pco;
pco.expiration_time = db.head_block_time() + fc::minutes(1);
pco.fee_paying_account = alice_id;
proposal_id_type inner;
{
transfer_operation top;
top.from = alice_id;
top.to = bob_id;
top.amount = asset( 10 );
pco.proposed_ops.emplace_back( top );
trx.operations.push_back( pco );
inner = PUSH_TX( db, trx, ~0 ).operation_results.front().get<object_id_type>();
trx.clear();
pco.proposed_ops.clear();
}

std::vector<proposal_id_type> nested;
nested.push_back( inner );
for( size_t i = 0; i < gpo.active_witnesses.size() * 2; i++ )
{
proposal_update_operation pup;
pup.fee_paying_account = alice_id;
pup.proposal = nested.back();
pup.active_approvals_to_add.insert( alice_id );
pco.proposed_ops.emplace_back( pup );
trx.operations.push_back( pco );
nested.push_back( PUSH_TX( db, trx, ~0 ).operation_results.front().get<object_id_type>() );
trx.clear();
pco.proposed_ops.clear();
}

proposal_update_operation pup;
pup.fee_paying_account = alice_id;
pup.proposal = nested.back();
pup.active_approvals_to_add.insert( alice_id );
trx.operations.push_back( pup );
PUSH_TX( db, trx, ~0 );

for( size_t i = 1; i < nested.size(); i++ )
BOOST_CHECK_THROW( db.get<proposal_object>( nested[i] ), fc::assert_exception ); // executed successfully -> object removed
db.get<proposal_object>( inner ); // wasn't executed -> object exists, doesn't throw
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( issue_214 )
{ try {
ACTORS( (alice)(bob) );
Expand Down