Separate sidechain transaction signed/reported counters by sidechain

This commit is contained in:
serkixenos 2021-07-19 13:31:56 +02:00
parent 143b244ccd
commit a55a4ecaad
6 changed files with 78 additions and 28 deletions

View file

@ -210,20 +210,29 @@ void database::pay_sons()
if( now < HARDFORK_SON2_TIME ) { if( now < HARDFORK_SON2_TIME ) {
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]);
} }
weighted_total_txs_signed += (s.txs_signed * son_weight); uint64_t txs_signed = 0;
for (const auto &ts : s.txs_signed) {
txs_signed = txs_signed + ts.second;
}
weighted_total_txs_signed += (txs_signed * son_weight);
}); });
// Now pay off each SON proportional to the number of transactions signed. // Now pay off each SON proportional to the number of transactions signed.
get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now](const object& o) { get_index_type<son_stats_index>().inspect_all_objects([this, &weighted_total_txs_signed, &dpo, &son_budget, &get_weight, &get_weight_before_son2_hf, &now](const object& o) {
const son_statistics_object& s = static_cast<const son_statistics_object&>(o); const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
if(s.txs_signed > 0){ uint64_t txs_signed = 0;
for (const auto &ts : s.txs_signed) {
txs_signed = txs_signed + ts.second;
}
if(txs_signed > 0){
const auto& idx = get_index_type<son_index>().indices().get<by_id>(); const auto& idx = get_index_type<son_index>().indices().get<by_id>();
auto son_obj = idx.find( s.owner ); auto son_obj = idx.find( s.owner );
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id]); auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id]);
if( now < HARDFORK_SON2_TIME ) { if( now < HARDFORK_SON2_TIME ) {
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]); son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id]);
} }
share_type pay = (s.txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
modify( *son_obj, [&]( son_object& _son_obj) modify( *son_obj, [&]( son_object& _son_obj)
{ {
_son_obj.pay_son_fee(pay, *this); _son_obj.pay_son_fee(pay, *this);
@ -236,8 +245,9 @@ void database::pay_sons()
//Reset the tx counter in each son statistics object //Reset the tx counter in each son statistics object
modify( s, [&]( son_statistics_object& _s) modify( s, [&]( son_statistics_object& _s)
{ {
_s.total_txs_signed += _s.txs_signed; for (const auto &ts : s.txs_signed) {
_s.txs_signed = 0; _s.txs_signed.at(ts.first) = 0;
}
}); });
} }
}); });

View file

@ -31,9 +31,9 @@ namespace graphene { namespace chain {
son_id_type owner; son_id_type owner;
// Lifetime total transactions signed // Lifetime total transactions signed
uint64_t total_txs_signed = 0; flat_map<sidechain_type, uint64_t> total_txs_signed;
// Transactions signed since the last son payouts // Transactions signed since the last son payouts
uint64_t txs_signed = 0; flat_map<sidechain_type, uint64_t> txs_signed;
// Total Voted Active time i.e. duration selected as part of voted active SONs // Total Voted Active time i.e. duration selected as part of voted active SONs
uint64_t total_voted_time = 0; uint64_t total_voted_time = 0;
// Total Downtime barring the current down time in seconds, used for stats to present to user // Total Downtime barring the current down time in seconds, used for stats to present to user
@ -47,9 +47,9 @@ namespace graphene { namespace chain {
// Deregistered Timestamp // Deregistered Timestamp
fc::time_point_sec deregistered_timestamp; fc::time_point_sec deregistered_timestamp;
// Total sidechain transactions reported by SON network while SON was active // Total sidechain transactions reported by SON network while SON was active
uint64_t total_sidechain_txs_reported = 0; flat_map<sidechain_type, uint64_t> total_sidechain_txs_reported;
// Sidechain transactions reported by this SON // Sidechain transactions reported by this SON
uint64_t sidechain_txs_reported = 0; flat_map<sidechain_type, uint64_t> sidechain_txs_reported;
}; };
/** /**

View file

@ -97,7 +97,15 @@ object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_tr
}); });
db().modify(son_obj->statistics(db()), [&](son_statistics_object& sso) { db().modify(son_obj->statistics(db()), [&](son_statistics_object& sso) {
sso.txs_signed += 1; if (sso.total_txs_signed.find(sto_obj->sidechain) == sso.total_txs_signed.end()) {
sso.total_txs_signed[sto_obj->sidechain] = 0;
}
sso.total_txs_signed[sto_obj->sidechain] += 1;
if (sso.txs_signed.find(sto_obj->sidechain) == sso.txs_signed.end()) {
sso.txs_signed[sto_obj->sidechain] = 0;
}
sso.txs_signed[sto_obj->sidechain] += 1;
}); });
return op.sidechain_transaction_id; return op.sidechain_transaction_id;

View file

@ -84,9 +84,16 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
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) {
sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) {
sso.total_sidechain_txs_reported[op.sidechain] = 0;
}
sso.total_sidechain_txs_reported[op.sidechain] += 1;
if (si.son_id == op.son_id) { if (si.son_id == op.son_id) {
sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) {
sso.sidechain_txs_reported[op.sidechain] = 0;
}
sso.sidechain_txs_reported[op.sidechain] += 1;
} }
}); });
} }
@ -122,7 +129,10 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
}); });
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) {
sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) {
sso.sidechain_txs_reported[op.sidechain] = 0;
}
sso.sidechain_txs_reported[op.sidechain] += 1;
}); });
return (*itr).id; return (*itr).id;
} }

View file

@ -82,9 +82,16 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w
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) {
sso.total_sidechain_txs_reported = sso.total_sidechain_txs_reported + 1; if (sso.total_sidechain_txs_reported.find(op.sidechain) == sso.total_sidechain_txs_reported.end()) {
sso.total_sidechain_txs_reported[op.sidechain] = 0;
}
sso.total_sidechain_txs_reported[op.sidechain] += 1;
if (si.son_id == op.son_id) { if (si.son_id == op.son_id) {
sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) {
sso.sidechain_txs_reported[op.sidechain] = 0;
}
sso.sidechain_txs_reported[op.sidechain] += 1;
} }
}); });
} }
@ -120,7 +127,10 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w
}); });
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) {
sso.sidechain_txs_reported = sso.sidechain_txs_reported + 1; if (sso.sidechain_txs_reported.find(op.sidechain) == sso.sidechain_txs_reported.end()) {
sso.sidechain_txs_reported[op.sidechain] = 0;
}
sso.sidechain_txs_reported[op.sidechain] += 1;
}); });
return (*itr).id; return (*itr).id;
} }

View file

@ -491,12 +491,20 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
// Modify the transaction signed statistics of Alice's SON // Modify the transaction signed statistics of Alice's SON
db.modify( *son_stats_obj1, [&]( son_statistics_object& _s) db.modify( *son_stats_obj1, [&]( son_statistics_object& _s)
{ {
_s.txs_signed = 2; _s.txs_signed[sidechain_type::bitcoin] = 2;
_s.txs_signed[sidechain_type::hive] = 4;
_s.total_txs_signed[sidechain_type::bitcoin] = 2;
_s.total_txs_signed[sidechain_type::hive] = 4;
}); });
// Modify the transaction signed statistics of Bob's SON // Modify the transaction signed statistics of Bob's SON
db.modify( *son_stats_obj2, [&]( son_statistics_object& _s) db.modify( *son_stats_obj2, [&]( son_statistics_object& _s)
{ {
_s.txs_signed = 3; _s.txs_signed[sidechain_type::bitcoin] = 3;
_s.txs_signed[sidechain_type::hive] = 6;
_s.total_txs_signed[sidechain_type::bitcoin] = 3;
_s.total_txs_signed[sidechain_type::hive] = 6;
}); });
// Note the balances before the maintenance // Note the balances before the maintenance
@ -506,11 +514,15 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
generate_blocks(dpo.next_maintenance_time); generate_blocks(dpo.next_maintenance_time);
generate_block(); generate_block();
// Check if the signed transaction statistics are reset for both SONs // Check if the signed transaction statistics are reset for both SONs
BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed, 0); BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::bitcoin), 0);
BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed, 0); BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::hive), 0);
BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::bitcoin), 0);
BOOST_REQUIRE_EQUAL(son_stats_obj2->txs_signed.at(sidechain_type::hive), 0);
BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed, 2); BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::bitcoin), 2);
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed, 3); BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::hive), 4);
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::bitcoin), 3);
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed.at(sidechain_type::hive), 6);
// Check that Alice and Bob are paid for signing the transactions in the previous day/cycle // Check that Alice and Bob are paid for signing the transactions in the previous day/cycle
BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 80+obj1_balance); BOOST_REQUIRE_EQUAL(db.get_balance(obj1->son_account, asset_id_type()).amount.value, 80+obj1_balance);
BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance); BOOST_REQUIRE_EQUAL(db.get_balance(obj2->son_account, asset_id_type()).amount.value, 120+obj2_balance);