Permalink
Browse files

Some changes

  • Loading branch information...
mvandeberg committed Apr 23, 2018
1 parent 4a189dc commit c2cca25d31d25e44e8dbe076d08f37cea8b06aa7
@@ -945,6 +945,11 @@ inline const void database::push_virtual_operation( const operation& op, bool fo
notify_post_apply_operation( note );
}

void database::notify_pre_apply_block( const signed_block& block )
{
STEEM_TRY_NOTIFY( pre_apply_block, block )
}

void database::notify_applied_block( const signed_block& block )
{
STEEM_TRY_NOTIFY( applied_block, block )
@@ -2666,6 +2671,8 @@ void database::check_free_memory( bool force_print, uint32_t current_block_num )

void database::_apply_block( const signed_block& next_block )
{ try {
notify_pre_apply_block( next_block );

uint32_t next_block_num = next_block.block_num();
//block_id_type next_block_id = next_block.id();

@@ -217,6 +217,7 @@ namespace steem { namespace chain {
void notify_pre_apply_operation( operation_notification& note );
void notify_post_apply_operation( const operation_notification& note );
inline const void push_virtual_operation( const operation& op, bool force = false ); // vops are not needed for low mem. Force will push them on low mem.
void notify_pre_apply_block( const signed_block& block );
void notify_applied_block( const signed_block& block );
void notify_on_pending_transaction( const signed_transaction& tx );
void notify_on_pre_apply_transaction( const signed_transaction& tx );
@@ -228,6 +229,8 @@ namespace steem { namespace chain {
fc::signal<void(const operation_notification&)> pre_apply_operation;
fc::signal<void(const operation_notification&)> post_apply_operation;

fc::signal<void(const signed_block&)> pre_apply_block;

/**
* This signal is emitted after all operations and virtual operation for a
* block have been applied but before the get_applied_operations() are cleared.
@@ -6,6 +6,7 @@
#include <steem/chain/comment_object.hpp>
#include <steem/chain/witness_objects.hpp>
#include <steem/chain/index.hpp>
#include <steem/chain/util/impacted.hpp>

#include <steem/utilities/key_conversion.hpp>
#include <steem/utilities/plugin_utilities.hpp>
@@ -54,8 +55,10 @@ namespace detail {
_timer(io),
_db( appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db() ) {}

void pre_apply_block( const steem::protocol::signed_block& blk );
void pre_transaction( const steem::protocol::signed_transaction& trx );
void pre_operation( const chain::operation_notification& note );
void post_operation( const chain::operation_notification& note );
void on_block( const signed_block& b );

void update_account_bandwidth( const chain::account_object& a, uint32_t trx_size, const bandwidth_type type );
@@ -72,10 +75,14 @@ namespace detail {
std::set< steem::protocol::account_name_type > _witnesses;
boost::asio::deadline_timer _timer;

std::set< steem::protocol::account_name_type > _dupe_customs;

chain::database& _db;
boost::signals2::connection on_pre_apply_block_conn;
boost::signals2::connection pre_apply_connection;
boost::signals2::connection applied_block_connection;
boost::signals2::connection on_pre_apply_transaction_connection;
boost::signals2::connection on_post_apply_operation_conn;
};

struct comment_options_extension_visitor
@@ -216,13 +223,20 @@ namespace detail {
}
};

void witness_plugin_impl::pre_apply_block( const steem::protocol::signed_block& b )
{
_dupe_customs.clear();
}

void witness_plugin_impl::pre_transaction( const steem::protocol::signed_transaction& trx )
{
flat_set< account_name_type > required; vector<authority> other;
trx.get_required_authorities( required, required, required, other );

auto trx_size = fc::raw::pack_size(trx);

STEEM_ASSERT( required.size() > 0, plugin_exception, "Operation must have an impacted account" );

for( const auto& auth : required )
{
const auto& acnt = _db.get_account( auth );
@@ -248,6 +262,28 @@ namespace detail {
}
}

void witness_plugin_impl::post_operation( const chain::operation_notification& note )
{
switch( note.op.which() )
{
case operation::tag< custom_operation >::value:
case operation::tag< custom_json_operation >::value:
case operation::tag< custom_binary_operation >::value:
{
flat_set< account_name_type > impacted;
app::operation_get_impacted_accounts( note.op, impacted );

for( auto& account : impacted )
STEEM_ASSERT( _dupe_customs.insert( account ).second, plugin_exception,
"Account ${a} already submitted a custom json operation this block.",
("a", account) );
}
break;
default:
break;
}
}

void witness_plugin_impl::on_block( const signed_block& b )
{ try {
int64_t max_block_size = _db.get_dynamic_global_properties().maximum_block_size;
@@ -321,6 +357,8 @@ namespace detail {
}
});
}

_dupe_customs.clear();
} FC_LOG_AND_RETHROW() }
#pragma message( "Remove FC_LOG_AND_RETHROW here before appbase release. It exists to help debug a rare lock exception" )

@@ -583,6 +621,8 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m

my->on_pre_apply_transaction_connection = my->_db.on_pre_apply_transaction.connect( 0, [&]( const signed_transaction& tx ){ my->pre_transaction( tx ); } );
my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->pre_operation( note ); } );
my->on_post_apply_operation_conn = my->_db.post_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->post_operation( note ); } );
my->on_pre_apply_block_conn = my->_db.pre_apply_block.connect( 0, [&]( const signed_block& b ){ my->pre_apply_block( b ); } );
my->applied_block_connection = my->_db.applied_block.connect( 0, [&]( const signed_block& b ){ my->on_block( b ); } );

add_plugin_index< account_bandwidth_index >( my->_db );
@@ -593,7 +633,7 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m

void witness_plugin::plugin_startup()
{ try {
ilog("witness plugin: plugin_startup() begin");
ilog("witness plugin: plugin_startup() begin" );
chain::database& d = appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db();

if( !my->_witnesses.empty() )
@@ -615,9 +655,11 @@ void witness_plugin::plugin_shutdown()
{
try
{
chain::util::disconnect_signal( my->on_post_apply_operation_conn );
chain::util::disconnect_signal( my->pre_apply_connection );
chain::util::disconnect_signal( my->applied_block_connection );
chain::util::disconnect_signal( my->on_pre_apply_transaction_connection );
chain::util::disconnect_signal( my->on_pre_apply_block_conn );

my->_timer.cancel();
}

0 comments on commit c2cca25

Please sign in to comment.