Add check to prevent deposit/withdrawal double processing

This commit is contained in:
Srdjan Obucina 2020-03-23 06:20:06 +01:00
parent dff785667e
commit f0eb24522c
2 changed files with 25 additions and 27 deletions

View file

@ -23,22 +23,22 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_uid>(); const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_uid>();
auto itr = idx.find(op.sidechain_uid); auto itr = idx.find(op.sidechain_uid);
if (itr == idx.end()) { if (itr == idx.end()) {
const auto& new_son_wallet_deposit_object = db().create<son_wallet_deposit_object>( [&]( son_wallet_deposit_object& swto ){ const auto& new_son_wallet_deposit_object = db().create<son_wallet_deposit_object>( [&]( son_wallet_deposit_object& swdo ){
swto.timestamp = op.timestamp; swdo.timestamp = op.timestamp;
swto.sidechain = op.sidechain; swdo.sidechain = op.sidechain;
swto.sidechain_uid = op.sidechain_uid; swdo.sidechain_uid = op.sidechain_uid;
swto.sidechain_transaction_id = op.sidechain_transaction_id; swdo.sidechain_transaction_id = op.sidechain_transaction_id;
swto.sidechain_from = op.sidechain_from; swdo.sidechain_from = op.sidechain_from;
swto.sidechain_to = op.sidechain_to; swdo.sidechain_to = op.sidechain_to;
swto.sidechain_currency = op.sidechain_currency; swdo.sidechain_currency = op.sidechain_currency;
swto.sidechain_amount = op.sidechain_amount; swdo.sidechain_amount = op.sidechain_amount;
swto.peerplays_from = op.peerplays_from; swdo.peerplays_from = op.peerplays_from;
swto.peerplays_to = op.peerplays_to; swdo.peerplays_to = op.peerplays_to;
swto.peerplays_asset = op.peerplays_asset; swdo.peerplays_asset = op.peerplays_asset;
auto &gpo = db().get_global_properties(); auto &gpo = db().get_global_properties();
for (auto &si : gpo.active_sons) { for (auto &si : gpo.active_sons) {
swto.expected_reports.insert(si.son_id); swdo.expected_reports.insert(si.son_id);
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(si.son_id); auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(si.son_id);
db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) {
@ -49,14 +49,14 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
}); });
} }
swto.received_reports.insert(op.son_id); swdo.received_reports.insert(op.son_id);
swto.processed = false; swdo.processed = false;
}); });
return new_son_wallet_deposit_object.id; return new_son_wallet_deposit_object.id;
} else { } else {
db().modify(*itr, [&op](son_wallet_deposit_object &swto) { db().modify(*itr, [&op](son_wallet_deposit_object &swdo) {
swto.received_reports.insert(op.son_id); swdo.received_reports.insert(op.son_id);
}); });
auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(op.son_id); auto stats_itr = db().get_index_type<son_stats_index>().indices().get<by_owner>().find(op.son_id);
db().modify(*stats_itr, [&op](son_statistics_object &sso) { db().modify(*stats_itr, [&op](son_statistics_object &sso) {
@ -74,6 +74,7 @@ void_result process_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_d
const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto& itr = idx.find(op.son_wallet_deposit_id); const auto& itr = idx.find(op.son_wallet_deposit_id);
FC_ASSERT(itr != idx.end(), "Son wallet deposit not found"); FC_ASSERT(itr != idx.end(), "Son wallet deposit not found");
FC_ASSERT(!itr->processed, "Son wallet deposit is already processed");
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }
@ -83,11 +84,9 @@ object_id_type process_son_wallet_deposit_evaluator::do_apply(const son_wallet_d
auto itr = idx.find(op.son_wallet_deposit_id); auto itr = idx.find(op.son_wallet_deposit_id);
if(itr != idx.end()) if(itr != idx.end())
{ {
if (itr->processed == false) { db().modify(*itr, [&op](son_wallet_deposit_object &swdo) {
db().modify(*itr, [&op](son_wallet_deposit_object &swto) { swdo.processed = true;
swto.processed = true; });
});
}
} }
return op.son_wallet_deposit_id; return op.son_wallet_deposit_id;
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -73,6 +73,7 @@ void_result process_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_
const auto& idx = db().get_index_type<son_wallet_withdraw_index>().indices().get<by_id>(); const auto& idx = db().get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto& itr = idx.find(op.son_wallet_withdraw_id); const auto& itr = idx.find(op.son_wallet_withdraw_id);
FC_ASSERT(itr != idx.end(), "Son wallet withdraw not found"); FC_ASSERT(itr != idx.end(), "Son wallet withdraw not found");
FC_ASSERT(!itr->processed, "Son wallet withdraw is already processed");
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }
@ -82,11 +83,9 @@ object_id_type process_son_wallet_withdraw_evaluator::do_apply(const son_wallet_
auto itr = idx.find(op.son_wallet_withdraw_id); auto itr = idx.find(op.son_wallet_withdraw_id);
if(itr != idx.end()) if(itr != idx.end())
{ {
if (itr->processed == false) { db().modify(*itr, [&op](son_wallet_withdraw_object &swwo) {
db().modify(*itr, [&op](son_wallet_withdraw_object &swto) { swwo.processed = true;
swto.processed = true; });
});
}
} }
return op.son_wallet_withdraw_id; return op.son_wallet_withdraw_id;
} FC_CAPTURE_AND_RETHROW( (op) ) } } FC_CAPTURE_AND_RETHROW( (op) ) }