Fix repeating tasks that should be executed by scheduled SON only
This commit is contained in:
parent
5d12cdb4f5
commit
224f01269c
3 changed files with 47 additions and 42 deletions
|
|
@ -28,6 +28,7 @@ class peerplays_sidechain_plugin : public graphene::app::plugin
|
||||||
std::unique_ptr<detail::peerplays_sidechain_plugin_impl> my;
|
std::unique_ptr<detail::peerplays_sidechain_plugin_impl> my;
|
||||||
|
|
||||||
std::set<chain::son_id_type>& get_sons();
|
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);
|
son_object get_son_object(son_id_type son_id);
|
||||||
bool is_active_son(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();
|
std::map<chain::public_key_type, fc::ecc::private_key>& get_private_keys();
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class peerplays_sidechain_plugin_impl
|
||||||
void plugin_startup();
|
void plugin_startup();
|
||||||
|
|
||||||
std::set<chain::son_id_type>& get_sons();
|
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);
|
son_object get_son_object(son_id_type son_id);
|
||||||
bool is_active_son(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();
|
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_bitcoin;
|
||||||
bool config_ready_peerplays;
|
bool config_ready_peerplays;
|
||||||
|
|
||||||
|
son_id_type current_son_id;
|
||||||
|
|
||||||
std::unique_ptr<peerplays_sidechain::sidechain_net_manager> net_manager;
|
std::unique_ptr<peerplays_sidechain::sidechain_net_manager> net_manager;
|
||||||
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
|
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
|
||||||
std::set<chain::son_id_type> _sons;
|
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_son(false),
|
||||||
config_ready_bitcoin(false),
|
config_ready_bitcoin(false),
|
||||||
config_ready_peerplays(false),
|
config_ready_peerplays(false),
|
||||||
|
current_son_id(son_id_type(std::numeric_limits<uint32_t>().max())),
|
||||||
net_manager(nullptr)
|
net_manager(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -225,6 +229,10 @@ std::set<chain::son_id_type>& peerplays_sidechain_plugin_impl::get_sons()
|
||||||
return _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)
|
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>();
|
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
|
// check if we control scheduled SON
|
||||||
if( _sons.find( next_son_id ) != _sons.end() ) {
|
if( _sons.find( next_son_id ) != _sons.end() ) {
|
||||||
|
|
||||||
|
current_son_id = next_son_id;
|
||||||
|
|
||||||
create_son_down_proposals();
|
create_son_down_proposals();
|
||||||
|
|
||||||
recreate_primary_wallet();
|
recreate_primary_wallet();
|
||||||
|
|
@ -536,6 +546,10 @@ std::set<chain::son_id_type>& peerplays_sidechain_plugin::get_sons()
|
||||||
return my->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)
|
son_object peerplays_sidechain_plugin::get_son_object(son_id_type son_id)
|
||||||
{
|
{
|
||||||
return my->get_son_object(son_id);
|
return my->get_son_object(son_id);
|
||||||
|
|
|
||||||
|
|
@ -164,20 +164,17 @@ void sidechain_net_handler::process_deposits() {
|
||||||
|
|
||||||
const chain::global_property_object& gpo = plugin.database().get_global_properties();
|
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;
|
son_wallet_deposit_process_operation p_op;
|
||||||
p_op.payer = GRAPHENE_SON_ACCOUNT;
|
p_op.payer = GRAPHENE_SON_ACCOUNT;
|
||||||
p_op.son_wallet_deposit_id = swdo.id;
|
p_op.son_wallet_deposit_id = swdo.id;
|
||||||
|
|
||||||
proposal_create_operation proposal_op;
|
proposal_create_operation proposal_op;
|
||||||
proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account;
|
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 ) );
|
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
|
||||||
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
|
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_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);
|
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
|
||||||
trx.validate();
|
trx.validate();
|
||||||
try {
|
try {
|
||||||
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
|
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||||
|
|
@ -186,8 +183,6 @@ void sidechain_net_handler::process_deposits() {
|
||||||
} catch(fc::exception e){
|
} catch(fc::exception e){
|
||||||
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
|
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,20 +199,17 @@ void sidechain_net_handler::process_withdrawals() {
|
||||||
|
|
||||||
const chain::global_property_object& gpo = plugin.database().get_global_properties();
|
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;
|
son_wallet_withdraw_process_operation p_op;
|
||||||
p_op.payer = GRAPHENE_SON_ACCOUNT;
|
p_op.payer = GRAPHENE_SON_ACCOUNT;
|
||||||
p_op.son_wallet_withdraw_id = swwo.id;
|
p_op.son_wallet_withdraw_id = swwo.id;
|
||||||
|
|
||||||
proposal_create_operation proposal_op;
|
proposal_create_operation proposal_op;
|
||||||
proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account;
|
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 ) );
|
proposal_op.proposed_ops.emplace_back( op_wrapper( p_op ) );
|
||||||
uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3;
|
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_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);
|
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
|
||||||
trx.validate();
|
trx.validate();
|
||||||
try {
|
try {
|
||||||
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
|
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||||
|
|
@ -226,8 +218,6 @@ void sidechain_net_handler::process_withdrawals() {
|
||||||
} catch(fc::exception e){
|
} catch(fc::exception e){
|
||||||
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
|
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue