Skip to content

Commit

Permalink
Merge pull request steemit#3098 from steemit/2870-aa-generate-block
Browse files Browse the repository at this point in the history
AA Block Generation
  • Loading branch information
Michael Vandeberg authored Oct 26, 2018
2 parents 1fc4e2f + bce4f8e commit c617f50
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
5 changes: 2 additions & 3 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ namespace steem { namespace chain {
void check_free_memory( bool force_print, uint32_t current_block_num );

void apply_transaction( const signed_transaction& trx, uint32_t skip = skip_nothing );
void apply_required_action( const required_automated_action& a );
void apply_optional_action( const optional_automated_action& a );

optional< chainbase::database::session >& pending_transaction_session();

Expand Down Expand Up @@ -499,10 +501,7 @@ namespace steem { namespace chain {
void apply_operation( const operation& op );

void process_required_actions( const required_automated_actions& actions );
void apply_required_action( const required_automated_action& a );

void process_optional_actions( const optional_automated_actions& actions );
void apply_optional_action( const optional_automated_action& a );

///Steps involved in applying a new block
///@{
Expand Down
61 changes: 61 additions & 0 deletions libraries/plugins/witness/block_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <steem/chain/database_exceptions.hpp>
#include <steem/chain/db_with.hpp>
#include <steem/chain/pending_required_action_object.hpp>
#include <steem/chain/pending_optional_action_object.hpp>
#include <steem/chain/witness_objects.hpp>

#include <fc/macros.hpp>
Expand Down Expand Up @@ -170,6 +172,65 @@ void block_producer::apply_pending_transactions(
wlog( "Postponed ${n} transactions due to block size limit", ("n", postponed_tx_count) );
}

const auto& pending_required_action_idx = _db.get_index< chain::pending_required_action_index, chain::by_id >();
auto pending_required_itr = pending_required_action_idx.begin();
chain::required_automated_actions required_actions;

while( pending_required_itr != pending_required_action_idx.end() )
{
uint64_t new_total_size = total_block_size + fc::raw::pack_size( pending_required_itr->action );

if( new_total_size >= maximum_block_size )
break;

try
{
auto temp_session = _db.start_undo_session();
_db.apply_required_action( pending_required_itr->action );
temp_session.squash();
total_block_size = new_total_size;
required_actions.push_back( pending_required_itr->action );
++pending_required_itr;
}
catch( fc::exception& e )
{
FC_RETHROW_EXCEPTION( e, warn, "A required automatic action was rejected. ${a} ${e}", ("a", pending_required_itr->action)("e", e.to_detail_string()) );
}
}

if( required_actions.size() )
{
pending_block.extensions.insert( required_actions );
}

const auto& pending_optional_action_idx = _db.get_index< chain::pending_optional_action_index, chain::by_id >();
auto pending_optional_itr = pending_optional_action_idx.begin();
chain::optional_automated_actions optional_actions;

while( pending_optional_itr != pending_optional_action_idx.end() )
{
uint64_t new_total_size = total_block_size + fc::raw::pack_size( pending_optional_itr->action );

if( new_total_size >= maximum_block_size )
break;

try
{
auto temp_session = _db.start_undo_session();
_db.apply_optional_action( pending_optional_itr->action );
temp_session.squash();
total_block_size = new_total_size;
optional_actions.push_back( pending_optional_itr->action );
}
catch( fc::exception& ) {}
++pending_optional_itr;
}

if( optional_actions.size() )
{
pending_block.extensions.insert( optional_actions );
}

_db.pending_transaction_session().reset();

pending_block.transaction_merkle_root = pending_block.calculate_merkle_root();
Expand Down

0 comments on commit c617f50

Please sign in to comment.