#500 - fix son_wallet_update_operation

This commit is contained in:
Vlad Dobromyslov 2023-01-30 19:27:27 +02:00
parent cb60cbe5d1
commit d89e5e1f23
4 changed files with 58 additions and 30 deletions

View file

@ -64,7 +64,9 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope
FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." );
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.son_wallet_id) != idx.end() ); const auto id = (op.son_wallet_id.instance.value - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(op.sidechain))) / active_sidechain_types.size();
const son_wallet_id_type son_wallet_id{ id };
FC_ASSERT( idx.find(son_wallet_id) != idx.end() );
//auto itr = idx.find(op.son_wallet_id); //auto itr = idx.find(op.son_wallet_id);
//FC_ASSERT( itr->addresses.find(op.sidechain) == itr->addresses.end() || //FC_ASSERT( itr->addresses.find(op.sidechain) == itr->addresses.end() ||
// itr->addresses.at(op.sidechain).empty(), "Sidechain wallet address already set"); // itr->addresses.at(op.sidechain).empty(), "Sidechain wallet address already set");
@ -74,7 +76,9 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope
object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op) object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op)
{ try { { try {
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
auto itr = idx.find(op.son_wallet_id); const auto id = (op.son_wallet_id.instance.value - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(op.sidechain))) / active_sidechain_types.size();
const son_wallet_id_type son_wallet_id{ id };
auto itr = idx.find(son_wallet_id);
if (itr != idx.end()) if (itr != idx.end())
{ {
if (itr->addresses.find(op.sidechain) == itr->addresses.end()) { if (itr->addresses.find(op.sidechain) == itr->addresses.end()) {

View file

@ -448,8 +448,10 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
bool transaction_ok = false; bool transaction_ok = false;
std::string new_pw_address = ""; std::string new_pw_address = "";
son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id; son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id;
const auto id = (swo_id.instance.value - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const son_wallet_id_type op_id{ id };
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(swo_id); const auto swo = idx.find(op_id);
if (swo != idx.end()) { if (swo != idx.end()) {
const auto &active_sons = gpo.active_sons.at(sidechain); const auto &active_sons = gpo.active_sons.at(sidechain);
@ -485,18 +487,20 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
} }
if (po.proposed_transaction.operations.size() >= 2) { if (po.proposed_transaction.operations.size() >= 2) {
object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id; const object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id;
const auto id = (object_id.instance() - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const object_id_type obj_id{ object_id.space(), object_id.type(), id };
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction; std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>(); const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
const auto st = st_idx.find(object_id); const auto st = st_idx.find(obj_id);
if (st == st_idx.end()) { if (st == st_idx.end()) {
std::string tx_str = ""; std::string tx_str = "";
if (object_id.is<son_wallet_id_type>()) { if (obj_id.is<son_wallet_id_type>()) {
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(object_id); const auto swo = idx.find(obj_id);
if (swo != idx.end()) { if (swo != idx.end()) {
tx_str = create_primary_wallet_transaction(*swo, new_pw_address); tx_str = create_primary_wallet_transaction(*swo, new_pw_address);
} }
@ -716,7 +720,10 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) || if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) ||
(active_sw->addresses.at(sidechain).empty())) { (active_sw->addresses.at(sidechain).empty())) {
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id)) { const auto id = active_sw->id.instance() * active_sidechain_types.size() + std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain));
const object_id_type op_id{ active_sw->id.space(), active_sw->id.type(), id };
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
return; return;
} }
@ -729,7 +736,7 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
boost::property_tree::ptree active_pw_pt; boost::property_tree::ptree active_pw_pt;
boost::property_tree::read_json(active_pw_ss, active_pw_pt); boost::property_tree::read_json(active_pw_ss, active_pw_pt);
if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) { if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) {
if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id)) { if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
return; return;
} }
@ -743,7 +750,7 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
son_wallet_update_operation swu_op; son_wallet_update_operation swu_op;
swu_op.payer = gpo.parameters.son_account(); swu_op.payer = gpo.parameters.son_account();
swu_op.son_wallet_id = active_sw->id; swu_op.son_wallet_id = op_id;
swu_op.sidechain = sidechain; swu_op.sidechain = sidechain;
swu_op.address = res.str(); swu_op.address = res.str();
@ -753,9 +760,12 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
std::string new_pw_address = active_pw_pt.get<std::string>("result.address"); std::string new_pw_address = active_pw_pt.get<std::string>("result.address");
std::string tx_str = create_primary_wallet_transaction(*prev_sw, new_pw_address); std::string tx_str = create_primary_wallet_transaction(*prev_sw, new_pw_address);
if (!tx_str.empty()) { if (!tx_str.empty()) {
const auto prev_id = prev_sw->id.instance() * active_sidechain_types.size() + std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain));
const object_id_type prev_op_id{ prev_sw->id.space(), prev_sw->id.type(), prev_id };
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = gpo.parameters.son_account(); stc_op.payer = gpo.parameters.son_account();
stc_op.object_id = prev_sw->id; stc_op.object_id = prev_op_id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = prev_sw->sons.at(sidechain); stc_op.signers = prev_sw->sons.at(sidechain);
@ -769,7 +779,7 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
database.push_transaction(trx, database::validation_steps::skip_block_size_check); database.push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node()) if (plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx)); plugin.app().p2p_node()->broadcast(net::trx_message(trx));
plugin.log_son_proposal_retry(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id); plugin.log_son_proposal_retry(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id);
} catch (fc::exception &e) { } catch (fc::exception &e) {
elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what())); elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what()));
return; return;

View file

@ -218,8 +218,10 @@ bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po)
bool address_ok = false; bool address_ok = false;
bool transaction_ok = false; bool transaction_ok = false;
const son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id; const son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id;
const auto id = (swo_id.instance.value - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const son_wallet_id_type op_id{ id };
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(swo_id); const auto swo = idx.find(op_id);
if (swo != idx.end()) { if (swo != idx.end()) {
const auto active_sons = gpo.active_sons.at(sidechain); const auto active_sons = gpo.active_sons.at(sidechain);
@ -239,17 +241,19 @@ bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po)
if (po.proposed_transaction.operations.size() >= 2) { if (po.proposed_transaction.operations.size() >= 2) {
const object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id; const object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id;
const auto id = (object_id.instance() - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const object_id_type obj_id{ object_id.space(), object_id.type(), id };
const std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction; const std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>(); const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
const auto st = st_idx.find(object_id); const auto st = st_idx.find(obj_id);
if (st == st_idx.end()) { if (st == st_idx.end()) {
std::string tx_str = ""; std::string tx_str = "";
if (object_id.is<son_wallet_id_type>()) { if (obj_id.is<son_wallet_id_type>()) {
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(object_id); const auto swo = idx.find(obj_id);
if (swo != idx.end()) { if (swo != idx.end()) {
tx_str = create_primary_wallet_transaction(gpo.active_sons.at(sidechain), object_id.operator std::string()); tx_str = create_primary_wallet_transaction(gpo.active_sons.at(sidechain), object_id.operator std::string());
} }
@ -416,11 +420,14 @@ void sidechain_net_handler_ethereum::process_primary_wallet() {
if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) || if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) ||
(active_sw->addresses.at(sidechain).empty())) { (active_sw->addresses.at(sidechain).empty())) {
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id)) { const auto id = active_sw->id.instance() * active_sidechain_types.size() + std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain));
const object_id_type op_id{ active_sw->id.space(), active_sw->id.type(), id };
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
return; return;
} }
if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id)) { if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
return; return;
} }
@ -432,7 +439,7 @@ void sidechain_net_handler_ethereum::process_primary_wallet() {
son_wallet_update_operation swu_op; son_wallet_update_operation swu_op;
swu_op.payer = gpo.parameters.son_account(); swu_op.payer = gpo.parameters.son_account();
swu_op.son_wallet_id = active_sw->id; swu_op.son_wallet_id = op_id;
swu_op.sidechain = sidechain; swu_op.sidechain = sidechain;
swu_op.address = wallet_contract_address; swu_op.address = wallet_contract_address;
proposal_op.proposed_ops.emplace_back(swu_op); proposal_op.proposed_ops.emplace_back(swu_op);
@ -452,11 +459,11 @@ void sidechain_net_handler_ethereum::process_primary_wallet() {
return signers; return signers;
}(); }();
std::string tx_str = create_primary_wallet_transaction(gpo.active_sons.at(sidechain), active_sw->id.operator std::string()); std::string tx_str = create_primary_wallet_transaction(gpo.active_sons.at(sidechain), op_id.operator std::string());
if (!tx_str.empty()) { if (!tx_str.empty()) {
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = gpo.parameters.son_account(); stc_op.payer = gpo.parameters.son_account();
stc_op.object_id = active_sw->id; stc_op.object_id = op_id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = signers; stc_op.signers = signers;
@ -469,7 +476,7 @@ void sidechain_net_handler_ethereum::process_primary_wallet() {
database.push_transaction(trx, database::validation_steps::skip_block_size_check); database.push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node()) if (plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx)); plugin.app().p2p_node()->broadcast(net::trx_message(trx));
plugin.log_son_proposal_retry(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id); plugin.log_son_proposal_retry(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id);
} catch (fc::exception &e) { } catch (fc::exception &e) {
elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what())); elog("Sending proposal for son wallet update operation failed with exception ${e}", ("e", e.what()));
return; return;

View file

@ -209,8 +209,10 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
bool address_ok = false; bool address_ok = false;
bool transaction_ok = false; bool transaction_ok = false;
son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id; son_wallet_id_type swo_id = op_obj_idx_0.get<son_wallet_update_operation>().son_wallet_id;
const auto id = (swo_id.instance.value - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const son_wallet_id_type op_id{ id };
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(swo_id); const auto swo = idx.find(op_id);
if (swo != idx.end()) { if (swo != idx.end()) {
auto active_sons = gpo.active_sons.at(sidechain); auto active_sons = gpo.active_sons.at(sidechain);
@ -229,18 +231,20 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
} }
if (po.proposed_transaction.operations.size() >= 2) { if (po.proposed_transaction.operations.size() >= 2) {
object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id; const object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id;
const auto id = (object_id.instance() - std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain))) / active_sidechain_types.size();
const object_id_type obj_id{ object_id.space(), object_id.type(), id };
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction; std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>(); const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
const auto st = st_idx.find(object_id); const auto st = st_idx.find(obj_id);
if (st == st_idx.end()) { if (st == st_idx.end()) {
std::string tx_str = ""; std::string tx_str = "";
if (object_id.is<son_wallet_id_type>()) { if (obj_id.is<son_wallet_id_type>()) {
const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
const auto swo = idx.find(object_id); const auto swo = idx.find(obj_id);
if (swo != idx.end()) { if (swo != idx.end()) {
std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str));
@ -486,7 +490,10 @@ void sidechain_net_handler_hive::process_primary_wallet() {
if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) || if ((active_sw->addresses.find(sidechain) == active_sw->addresses.end()) ||
(active_sw->addresses.at(sidechain).empty())) { (active_sw->addresses.at(sidechain).empty())) {
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, active_sw->id)) { const auto id = active_sw->id.instance() * active_sidechain_types.size() + std::distance(active_sidechain_types.begin(), active_sidechain_types.find(sidechain));
const object_id_type op_id{ active_sw->id.space(), active_sw->id.type(), id };
if (proposal_exists(chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
return; return;
} }
@ -542,7 +549,7 @@ void sidechain_net_handler_hive::process_primary_wallet() {
son_wallet_update_operation swu_op; son_wallet_update_operation swu_op;
swu_op.payer = gpo.parameters.son_account(); swu_op.payer = gpo.parameters.son_account();
swu_op.son_wallet_id = active_sw->id; swu_op.son_wallet_id = op_id;
swu_op.sidechain = sidechain; swu_op.sidechain = sidechain;
swu_op.address = wallet_account_name; swu_op.address = wallet_account_name;
@ -565,7 +572,7 @@ void sidechain_net_handler_hive::process_primary_wallet() {
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = gpo.parameters.son_account(); stc_op.payer = gpo.parameters.son_account();
stc_op.object_id = active_sw->id; stc_op.object_id = op_id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = signers; stc_op.signers = signers;