Separate sidechain transaction signed/reported counters by sidechain
This commit is contained in:
parent
143b244ccd
commit
a55a4ecaad
6 changed files with 78 additions and 28 deletions
|
|
@ -210,20 +210,29 @@ void database::pay_sons()
|
|||
if( now < HARDFORK_SON2_TIME ) {
|
||||
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.
|
||||
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);
|
||||
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>();
|
||||
auto son_obj = idx.find( s.owner );
|
||||
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id]);
|
||||
if( now < HARDFORK_SON2_TIME ) {
|
||||
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)
|
||||
{
|
||||
_son_obj.pay_son_fee(pay, *this);
|
||||
|
|
@ -236,8 +245,9 @@ void database::pay_sons()
|
|||
//Reset the tx counter in each son statistics object
|
||||
modify( s, [&]( son_statistics_object& _s)
|
||||
{
|
||||
_s.total_txs_signed += _s.txs_signed;
|
||||
_s.txs_signed = 0;
|
||||
for (const auto &ts : s.txs_signed) {
|
||||
_s.txs_signed.at(ts.first) = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -593,7 +603,7 @@ void database::update_active_committee_members()
|
|||
update_committee_member_total_votes( cm );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update committee authorities
|
||||
if( !committee_members.empty() )
|
||||
{
|
||||
|
|
@ -1243,13 +1253,13 @@ double database::calculate_vesting_factor(const account_object& stake_account)
|
|||
// variables needed
|
||||
const auto number_of_subperiods = vesting_period / vesting_subperiod;
|
||||
double vesting_factor;
|
||||
|
||||
|
||||
// get in what sub period we are
|
||||
uint32_t current_subperiod = get_gpos_current_subperiod();
|
||||
|
||||
|
||||
if(current_subperiod == 0 || current_subperiod > number_of_subperiods) return 0;
|
||||
|
||||
// On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes,
|
||||
// On starting new vesting period, all votes become zero until someone votes, To avoid a situation of zero votes,
|
||||
// changes were done to roll in GPOS rules, the vesting factor will be 1 for whoever votes in 6th sub-period of last vesting period
|
||||
// BLOCKBACK-174 fix
|
||||
if(current_subperiod == 1 && this->head_block_time() >= HARDFORK_GPOS_TIME + vesting_period) //Applicable only from 2nd vesting period
|
||||
|
|
@ -2176,7 +2186,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
}
|
||||
}
|
||||
} tally_helper(*this, gpo);
|
||||
|
||||
|
||||
perform_account_maintenance( tally_helper );
|
||||
struct clear_canary {
|
||||
clear_canary(vector<uint64_t>& target): target(target){}
|
||||
|
|
@ -2222,7 +2232,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
if( !p.pending_parameters->extensions.value.gpos_subperiod.valid() )
|
||||
p.pending_parameters->extensions.value.gpos_subperiod = p.parameters.extensions.value.gpos_subperiod;
|
||||
if( !p.pending_parameters->extensions.value.gpos_vesting_lockin_period.valid() )
|
||||
p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period;
|
||||
p.pending_parameters->extensions.value.gpos_vesting_lockin_period = p.parameters.extensions.value.gpos_vesting_lockin_period;
|
||||
if( !p.pending_parameters->extensions.value.rbac_max_permissions_per_account.valid() )
|
||||
p.pending_parameters->extensions.value.rbac_max_permissions_per_account = p.parameters.extensions.value.rbac_max_permissions_per_account;
|
||||
if( !p.pending_parameters->extensions.value.rbac_max_account_authority_lifetime.valid() )
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ namespace graphene { namespace chain {
|
|||
|
||||
son_id_type owner;
|
||||
// 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
|
||||
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
|
||||
uint64_t total_voted_time = 0;
|
||||
// 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
|
||||
fc::time_point_sec deregistered_timestamp;
|
||||
// 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
|
||||
uint64_t sidechain_txs_reported = 0;
|
||||
flat_map<sidechain_type, uint64_t> sidechain_txs_reported;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
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) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
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) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -491,12 +491,20 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
|
|||
// Modify the transaction signed statistics of Alice's SON
|
||||
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
|
||||
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
|
||||
|
|
@ -506,11 +514,15 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
|
|||
generate_blocks(dpo.next_maintenance_time);
|
||||
generate_block();
|
||||
// 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_obj2->txs_signed, 0);
|
||||
BOOST_REQUIRE_EQUAL(son_stats_obj1->txs_signed.at(sidechain_type::bitcoin), 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_obj2->total_txs_signed, 3);
|
||||
BOOST_REQUIRE_EQUAL(son_stats_obj1->total_txs_signed.at(sidechain_type::bitcoin), 2);
|
||||
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
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue