Fix repeating tasks that should be executed by scheduled SON only

This commit is contained in:
Srdjan Obucina 2020-02-22 02:15:37 +01:00
parent 5d12cdb4f5
commit 224f01269c
3 changed files with 47 additions and 42 deletions

View file

@ -28,6 +28,7 @@ class peerplays_sidechain_plugin : public graphene::app::plugin
std::unique_ptr<detail::peerplays_sidechain_plugin_impl> my;
std::set<chain::son_id_type>& get_sons();
son_id_type& get_current_son_id();
son_object get_son_object(son_id_type son_id);
bool is_active_son(son_id_type son_id);
std::map<chain::public_key_type, fc::ecc::private_key>& get_private_keys();

View file

@ -35,6 +35,7 @@ class peerplays_sidechain_plugin_impl
void plugin_startup();
std::set<chain::son_id_type>& get_sons();
son_id_type& get_current_son_id();
son_object get_son_object(son_id_type son_id);
bool is_active_son(son_id_type son_id);
std::map<chain::public_key_type, fc::ecc::private_key>& get_private_keys();
@ -55,6 +56,8 @@ class peerplays_sidechain_plugin_impl
bool config_ready_bitcoin;
bool config_ready_peerplays;
son_id_type current_son_id;
std::unique_ptr<peerplays_sidechain::sidechain_net_manager> net_manager;
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
std::set<chain::son_id_type> _sons;
@ -70,6 +73,7 @@ peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidec
config_ready_son(false),
config_ready_bitcoin(false),
config_ready_peerplays(false),
current_son_id(son_id_type(std::numeric_limits<uint32_t>().max())),
net_manager(nullptr)
{
}
@ -225,6 +229,10 @@ std::set<chain::son_id_type>& peerplays_sidechain_plugin_impl::get_sons()
return _sons;
}
son_id_type& peerplays_sidechain_plugin_impl::get_current_son_id() {
return current_son_id;
}
son_object peerplays_sidechain_plugin_impl::get_son_object(son_id_type son_id)
{
const auto& idx = plugin.database().get_index_type<chain::son_index>().indices().get<by_id>();
@ -403,6 +411,8 @@ void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
// check if we control scheduled SON
if( _sons.find( next_son_id ) != _sons.end() ) {
current_son_id = next_son_id;
create_son_down_proposals();
recreate_primary_wallet();
@ -536,6 +546,10 @@ std::set<chain::son_id_type>& peerplays_sidechain_plugin::get_sons()
return my->get_sons();
}
son_id_type& peerplays_sidechain_plugin::get_current_son_id() {
return my->get_current_son_id();
}
son_object peerplays_sidechain_plugin::get_son_object(son_id_type son_id)
{
return my->get_son_object(son_id);

View file

@ -164,29 +164,24 @@ void sidechain_net_handler::process_deposits() {
const chain::global_property_object& gpo = plugin.database().get_global_properties();
for (son_id_type son_id : plugin.get_sons()) {
if (plugin.is_active_son(son_id)) {
son_wallet_deposit_process_operation p_op;
p_op.payer = GRAPHENE_SON_ACCOUNT;
p_op.son_wallet_deposit_id = swdo.id;
son_wallet_deposit_process_operation p_op;
p_op.payer = GRAPHENE_SON_ACCOUNT;
p_op.son_wallet_deposit_id = swdo.id;
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_son_object(plugin.get_current_son_id()).son_account;
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime );
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account;
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime );
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
}
}
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
}
});
}
@ -204,29 +199,24 @@ void sidechain_net_handler::process_withdrawals() {
const chain::global_property_object& gpo = plugin.database().get_global_properties();
for (son_id_type son_id : plugin.get_sons()) {
if (plugin.is_active_son(son_id)) {
son_wallet_withdraw_process_operation p_op;
p_op.payer = GRAPHENE_SON_ACCOUNT;
p_op.son_wallet_withdraw_id = swwo.id;
son_wallet_withdraw_process_operation p_op;
p_op.payer = GRAPHENE_SON_ACCOUNT;
p_op.son_wallet_withdraw_id = swwo.id;
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_son_object(plugin.get_current_son_id()).son_account;
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime );
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account;
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime );
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
}
}
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
}
});
}