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

Delegate to pool #2705 #3175

Closed
wants to merge 10 commits into from
22 changes: 22 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,16 @@ void database::notify_post_apply_transaction( const transaction_notification& no
STEEM_TRY_NOTIFY( _post_apply_transaction_signal, note )
}

void database::notify_pre_apply_custom_operation( const custom_operation_notification& note )
{
STEEM_TRY_NOTIFY( _pre_apply_custom_operation_signal, note )
}

void database::notify_post_apply_custom_operation( const custom_operation_notification& note )
{
STEEM_TRY_NOTIFY( _post_apply_custom_operation_signal, note )
}

account_name_type database::get_scheduled_witness( uint32_t slot_num )const
{
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
Expand Down Expand Up @@ -3754,6 +3764,18 @@ boost::signals2::connection database::add_post_apply_transaction_handler( const
return connect_impl(_post_apply_transaction_signal, func, plugin, group, "<-transaction");
}

boost::signals2::connection database::add_pre_apply_custom_operation_handler ( const apply_custom_operation_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_pre_apply_custom_operation_signal, func, plugin, group, "->custom");
}

boost::signals2::connection database::add_post_apply_custom_operation_handler( const apply_custom_operation_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_post_apply_custom_operation_signal, func, plugin, group, "<-custom");
}

boost::signals2::connection database::add_pre_apply_block_handler( const apply_block_handler_t& func,
const abstract_plugin& plugin, int32_t group )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@ namespace steem { namespace protocol {

namespace steem { namespace chain {

using steem::protocol::custom_id_type;

class custom_operation_interpreter
{
public:
virtual void apply( const protocol::custom_json_operation& op ) = 0;
virtual void apply( const protocol::custom_binary_operation & op ) = 0;
virtual steem::protocol::custom_id_type get_custom_id() = 0;
virtual custom_id_type get_custom_id() = 0;
virtual std::shared_ptr< steem::schema::abstract_schema > get_operation_schema() = 0;
};

class custom_operation_notification
{
public:
custom_operation_notification( const custom_id_type& cid ) : custom_id(cid) {}
virtual ~custom_operation_notification() {}

template< typename OpType >
const OpType& get_op()const;
template< typename OpType >
const OpType* maybe_get_op() const;

// const operation_notification& outer_note;
// One day we might implement outer_note, but some core plumbing will need to be re-organized
// to route operation_notification into core evaluators. For now, a plugin that needs this
// information can save it in the pre-eval handler for the custom operation.

custom_id_type custom_id;
uint32_t op_in_custom = 0;
};

} } // steem::chain
37 changes: 23 additions & 14 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace steem { namespace chain {

class database_impl;
class custom_operation_interpreter;
class custom_operation_notification;

namespace util {
struct comment_reward_context;
Expand Down Expand Up @@ -286,12 +287,15 @@ namespace steem { namespace chain {
void notify_irreversible_block( uint32_t block_num );
void notify_pre_apply_transaction( const transaction_notification& note );
void notify_post_apply_transaction( const transaction_notification& note );
void notify_pre_apply_custom_operation( const custom_operation_notification& note );
void notify_post_apply_custom_operation( const custom_operation_notification& note );

using apply_required_action_handler_t = std::function< void(const required_action_notification&) >;
using apply_optional_action_handler_t = std::function< void(const optional_action_notification&) >;
using apply_operation_handler_t = std::function< void(const operation_notification&) >;
using apply_transaction_handler_t = std::function< void(const transaction_notification&) >;
using apply_block_handler_t = std::function< void(const block_notification&) >;
using apply_custom_operation_handler_t = std::function< void(const custom_operation_notification&) >;
using irreversible_block_handler_t = std::function< void(uint32_t) >;
using reindex_handler_t = std::function< void(const reindex_notification&) >;
using generate_optional_actions_handler_t = std::function< void(const generate_optional_actions_notification&) >;
Expand All @@ -309,20 +313,22 @@ namespace steem { namespace chain {

public:

boost::signals2::connection add_pre_apply_required_action_handler ( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_required_action_handler( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_optional_action_handler ( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_optional_action_handler( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_irreversible_block_handler ( const irreversible_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_generate_optional_actions_handler ( const generate_optional_actions_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_required_action_handler ( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_required_action_handler ( const apply_required_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_optional_action_handler ( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_optional_action_handler ( const apply_optional_action_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_operation_handler ( const apply_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_transaction_handler ( const apply_transaction_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_custom_operation_handler ( const apply_custom_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_custom_operation_handler( const apply_custom_operation_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_apply_block_handler ( const apply_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_irreversible_block_handler ( const irreversible_block_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_pre_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_post_reindex_handler ( const reindex_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );
boost::signals2::connection add_generate_optional_actions_handler ( const generate_optional_actions_handler_t& func, const abstract_plugin& plugin, int32_t group = -1 );

//////////////////// db_witness_schedule.cpp ////////////////////

Expand Down Expand Up @@ -662,6 +668,9 @@ namespace steem { namespace chain {
*/
fc::signal<void(const operation_notification&)> _post_apply_operation_signal;

fc::signal<void(const custom_operation_notification&)> _pre_apply_custom_operation_signal;
fc::signal<void(const custom_operation_notification&)> _post_apply_custom_operation_signal;

/**
* This signal is emitted when we start processing a block.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,35 @@ void custom_op_from_variant( const fc::variant& var, CustomOperationType& vo )
}
}

template< typename OpType >
class generic_custom_operation_notification : public custom_operation_notification
{
public:
generic_custom_operation_notification( const custom_id_type& cid, const OpType& o )
: custom_operation_notification(cid), op(o) {}

const OpType& op;
};

template< typename OpType >
const OpType& custom_operation_notification::get_op()const
{
const OpType* maybe_op = maybe_get_op< OpType >();
FC_ASSERT( maybe_op );
return *maybe_op;
}

template< typename OpType >
const OpType* custom_operation_notification::maybe_get_op()const
{
const generic_custom_operation_notification< OpType >* generic_this =
dynamic_cast< const generic_custom_operation_notification< OpType >* >( this );
const OpType* result = nullptr;
if( generic_this )
result = &(generic_this->op);
return result;
}

template< typename CustomOperationType >
class generic_custom_operation_interpreter
: public custom_operation_interpreter, public evaluator_registry< CustomOperationType >
Expand Down Expand Up @@ -167,7 +196,12 @@ class generic_custom_operation_interpreter
{
// gcc errors if this-> is not here
// error message is "declarations in dependent base are not found by unqualified lookup"

generic_custom_operation_notification< CustomOperationType > cnote( custom_id, inner_o );
this->_db.notify_pre_apply_custom_operation( cnote );
this->get_evaluator( inner_o ).apply( inner_o );
this->_db.notify_post_apply_custom_operation( cnote );
++cnote.op_in_custom;
}

plugin_session.squash();
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steem/chain/util/manabar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct manabar
if( !skip_cap_regen )
dt = (dt > params.regen_time) ? params.regen_time : dt;

uint128_t max_mana_dt = uint64_t( params.max_mana >= 0 ? params.max_mana : 0 );
fc::uint128_t max_mana_dt = uint64_t( params.max_mana >= 0 ? params.max_mana : 0 );
max_mana_dt *= dt;
uint64_t u_regen = (max_mana_dt / params.regen_time).to_uint64();
FC_ASSERT( u_regen <= std::numeric_limits< int64_t >::max() );
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,9 @@ void custom_json_evaluator::do_apply( const custom_json_operation& o )

std::shared_ptr< custom_operation_interpreter > eval = d.get_custom_json_evaluator( o.id );
if( !eval )
{
return;
}

try
{
Expand All @@ -2233,7 +2235,9 @@ void custom_json_evaluator::do_apply( const custom_json_operation& o )
catch( const fc::exception& e )
{
if( d.is_producing() )
{
throw e;
}
}
catch(...)
{
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/rc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_library( rc_plugin
resource_count.cpp
resource_user.cpp
rc_curve.cpp
rc_operations.cpp
${HEADERS}
)

Expand Down
6 changes: 6 additions & 0 deletions libraries/plugins/rc/include/steem/plugins/rc/rc_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define STEEM_RC_REGEN_TIME (60*60*24*5)
#define STEEM_RC_MAX_OUTDEL_SLOTS 3
#define STEEM_RC_RECOVERY_SLOT_NUM 1
#define STEEM_RC_MAX_OUTDEL 40
Loading