From dbf73509ba5f74b13a8bab01702c5a2c17410cdb Mon Sep 17 00:00:00 2001 From: satyakoneru Date: Thu, 5 Mar 2020 02:21:15 +1100 Subject: [PATCH] SON118 - Add tx sign metrics for SON rewards (#302) --- libraries/chain/db_maint.cpp | 1 + libraries/chain/include/graphene/chain/son_object.hpp | 3 +++ libraries/chain/sidechain_transaction_evaluator.cpp | 4 ++++ tests/tests/sidechain_transaction_tests.cpp | 6 ++++++ tests/tests/son_operations_tests.cpp | 3 +++ 5 files changed, 17 insertions(+) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 3c1685b3..16a9ff95 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -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; }); } diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index 7a73a312..0d4a7317 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -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 @@ -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) diff --git a/libraries/chain/sidechain_transaction_evaluator.cpp b/libraries/chain/sidechain_transaction_evaluator.cpp index 7a684b79..a77c7f64 100644 --- a/libraries/chain/sidechain_transaction_evaluator.cpp +++ b/libraries/chain/sidechain_transaction_evaluator.cpp @@ -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)) diff --git a/tests/tests/sidechain_transaction_tests.cpp b/tests/tests/sidechain_transaction_tests.cpp index 0246d009..25e319f0 100644 --- a/tests/tests/sidechain_transaction_tests.cpp +++ b/tests/tests/sidechain_transaction_tests.cpp @@ -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); diff --git a/tests/tests/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index 13e3cf1f..9f3c0937 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -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);