Skip to content

Commit

Permalink
SON118 - Add tx sign metrics for SON rewards (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra19XX authored Mar 4, 2020
1 parent d6e6bed commit dbf7350
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ 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;
});
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/graphene/chain/son_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace graphene { namespace chain {
static const uint8_t type_id = impl_son_statistics_object_type;

son_id_type owner;
// Lifetime total transactions signed
uint64_t total_txs_signed = 0;
// Transactions signed since the last son payouts
uint64_t txs_signed = 0;
// Total Downtime barring the current down time in seconds, used for stats to present to user
Expand Down Expand Up @@ -103,6 +105,7 @@ FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
FC_REFLECT_DERIVED( graphene::chain::son_statistics_object,
(graphene::db::object),
(owner)
(total_txs_signed)
(txs_signed)
(total_downtime)
(current_interval_downtime)
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/sidechain_transaction_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ object_id_type bitcoin_transaction_sign_evaluator::do_apply(const bitcoin_transa
po.proposed_transaction.operations[0] = bitcoin_transaction_send_op;
});

db().modify( son_obj->statistics( db() ), [&]( son_statistics_object& sso ) {
sso.txs_signed += 1;
} );

update_proposal(op);
}
FC_CAPTURE_AND_RETHROW((op))
Expand Down
6 changes: 6 additions & 0 deletions tests/tests/sidechain_transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ BOOST_AUTO_TEST_CASE(bitcoin_transaction_send_test)

BOOST_REQUIRE(btobj->processed == false);

auto stats1 = son_obj1->statistics( db );
auto stats2 = son_obj2->statistics( db );

BOOST_REQUIRE(stats1.txs_signed == 1);
BOOST_REQUIRE(stats2.txs_signed == 1);

auto sigs = btobj->signatures;

BOOST_REQUIRE(sigs[son_obj1->id][0] == a1);
Expand Down
3 changes: 3 additions & 0 deletions tests/tests/son_operations_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ BOOST_AUTO_TEST_CASE( son_pay_test )
// 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->total_txs_signed, 2);
BOOST_REQUIRE_EQUAL(son_stats_obj2->total_txs_signed, 3);
// 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);
Expand Down

0 comments on commit dbf7350

Please sign in to comment.