Skip to content

Commit

Permalink
Small fixes connected with proposals processing for master - rebase b…
Browse files Browse the repository at this point in the history
…ranch (#142)

* Small fixes of problems pointed by reviewer

* Corrections in unit-tests caused by lack of rounding

* Reverted changes regarding `proposal_pay_operation`

* Reverted changes regarding `proposal_pay_operation` - fix nr 2

* Added ENABLE_STD_ALLOCATOR_SUPPORT=ON switch
  • Loading branch information
Mariusz-Trela authored and vogel76 committed Apr 29, 2019
1 parent e0e1512 commit 31d5bea
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
1 change: 1 addition & 0 deletions Builder.DockerFile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN \
cd build && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_STD_ALLOCATOR_SUPPORT=ON \
-DBUILD_STEEM_TESTNET=ON \
-DLOW_MEMORY_NODE=OFF \
-DCLEAR_VOTES=ON \
Expand Down
4 changes: 0 additions & 4 deletions libraries/chain/include/steem/chain/sps_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class sps_helper
static ProposalObjectIterator remove_proposal( ProposalObjectIterator& proposal,
ProposalIndex& proposalIndex, VotesIndex& votesIndex, const ByVoterIdx& byVoterIdx, sps_removing_reducer& obj_perf )
{
ilog("Erasing all votes associated to proposal: ${p}", ("p", *proposal));

/// Now remove all votes specific to given proposal.
auto propI = byVoterIdx.lower_bound(boost::make_tuple(proposal->proposal_id, account_name_type()));

Expand All @@ -89,8 +87,6 @@ class sps_helper
propI = votesIndex. template erase<by_proposal_voter>(propI);
}

ilog("Erasing proposal: ${p}", ("p", *proposal));

return checker< ByProposalType, false/*Loop*/ >( proposal, proposalIndex, obj_perf );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class sps_processor

const static std::string removing_name;
const static std::string calculating_name;
const static uint32_t total_amount_divider = 100;

//Get number of microseconds for 1 day( daily_ms )
const int64_t daily_seconds = fc::days(1).to_seconds();
Expand Down
9 changes: 0 additions & 9 deletions libraries/chain/sps_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ void create_proposal_evaluator::do_apply( const create_proposal_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_PROPOSALS_HARDFORK ), "Proposals functionality not enabled until hardfork ${hf}", ("hf", STEEM_PROPOSALS_HARDFORK) );

ilog("creating proposal: ${op}", ("op", o));

/** start date can be earlier than head_block_time - otherwise creating a proposal can be difficult,
since passed date should be adjusted by potential transaction execution delay (i.e. 3 sec
as a time for processed next block).
Expand Down Expand Up @@ -79,11 +77,6 @@ void update_proposal_votes_evaluator::do_apply( const update_proposal_votes_oper
{
FC_ASSERT( _db.has_hardfork( STEEM_PROPOSALS_HARDFORK ), "Proposals functionality not enabled until hardfork ${hf}", ("hf", STEEM_PROPOSALS_HARDFORK) );

ilog("voting proposal: ${op}", ("op", o));

if( o.proposal_ids.empty() )
return;

const auto& pidx = _db.get_index< proposal_index >().indices().get< by_proposal_id >();
const auto& pvidx = _db.get_index< proposal_vote_index >().indices().get< by_voter_proposal >();

Expand Down Expand Up @@ -121,8 +114,6 @@ void remove_proposal_evaluator::do_apply(const remove_proposal_operation& op)
{
FC_ASSERT( _db.has_hardfork( STEEM_PROPOSALS_HARDFORK ), "Proposals functionality not enabled until hardfork ${hf}", ("hf", STEEM_PROPOSALS_HARDFORK) );

ilog("Attempting to evaluate remove_proposal_operation: ${o}", ("o", op));

sps_helper::remove_proposals( _db, op.proposal_ids, op.proposal_owner );

/*
Expand Down
30 changes: 22 additions & 8 deletions libraries/chain/sps_objects/sps_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ uint64_t sps_processor::calculate_votes( const proposal_id_type& id )
//If _voter has set proxy, then his votes aren't taken into consideration
if( _voter.proxy == STEEM_PROXY_TO_SELF_ACCOUNT )
{
auto sum = std::accumulate( _voter.proxied_vsf_votes.begin(),
_voter.proxied_vsf_votes.end(),
_voter.vesting_shares.amount );
auto sum = _voter.witness_vote_weight();
ret += sum.value;
}

Expand Down Expand Up @@ -120,7 +118,7 @@ asset sps_processor::get_treasury_fund()

asset sps_processor::get_daily_inflation()
{
//temporary
FC_TODO( "to invent how to get inflation needed for STEEM_TREASURY_ACCOUNT" )
return asset( 0, SBD_SYMBOL );
}

Expand All @@ -138,8 +136,11 @@ asset sps_processor::calculate_maintenance_budget( const time_point_sec& head_ti
auto passed_time_seconds = ( head_time - db.get_dynamic_global_properties().last_budget_time ).to_seconds();

//Calculate daily_budget_limit
auto daily_budget_limit = treasury_fund.amount.value / 100 + daily_inflation.amount.value;
daily_budget_limit = daily_budget_limit * ( static_cast< double >( passed_time_seconds ) / daily_seconds );
int64_t daily_budget_limit = treasury_fund.amount.value / total_amount_divider + daily_inflation.amount.value;

uint64_t ratio = ( passed_time_seconds * STEEM_100_PERCENT ) / daily_seconds;
uint128_t numerator = daily_budget_limit * ratio;
daily_budget_limit = ( numerator / STEEM_100_PERCENT ).to_int64();

//Transfer daily_proposal_inflation to `treasury account`
transfer_daily_inflation_to_treasury( daily_inflation );
Expand All @@ -149,6 +150,19 @@ asset sps_processor::calculate_maintenance_budget( const time_point_sec& head_ti

void sps_processor::transfer_daily_inflation_to_treasury( const asset& daily_inflation )
{
/*
Now `daily_inflation` is always zero. Take a look at `get_daily_inflation`
Comment from Michael Vandeberg:
Is this printing new SBD?
That's not how we have handled inflation in the past.
Either inflation should be paid, per block,
in to the treasury account in database::process_funds or added to a temp fund in the dgpo
that is then transferred in to the treasury account during maintenance.
*/
FC_TODO( "to choose how to transfer inflation into STEEM_TREASURY_ACCOUNT" )
if( daily_inflation.amount.value > 0 )
{
const auto& treasury_account = db.get_account( STEEM_TREASURY_ACCOUNT );
Expand All @@ -164,7 +178,7 @@ void sps_processor::transfer_payments( const time_point_sec& head_time, asset& m
const auto& treasury_account = db.get_account(STEEM_TREASURY_ACCOUNT);

auto passed_time_seconds = ( head_time - db.get_dynamic_global_properties().last_budget_time ).to_seconds();
double ratio = static_cast< double >( passed_time_seconds ) / daily_seconds;
uint64_t ratio = ( passed_time_seconds * STEEM_100_PERCENT ) / daily_seconds;

auto processing = [this, &treasury_account]( const proposal_object& _item, const asset& payment )
{
Expand All @@ -186,7 +200,7 @@ void sps_processor::transfer_payments( const time_point_sec& head_time, asset& m
if( _item.total_votes == 0 )
break;

auto period_pay = asset( ratio * _item.daily_pay.amount.value, _item.daily_pay.symbol );
auto period_pay = asset( ( ratio * _item.daily_pay.amount.value ) / STEEM_100_PERCENT, _item.daily_pay.symbol );

if( period_pay >= maintenance_budget_limit )
{
Expand Down
18 changes: 11 additions & 7 deletions tests/tests/proposal_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ BOOST_AUTO_TEST_CASE( generating_payments )
auto start_date = db->head_block_time();
auto end_date = start_date + fc::days( 2 );

auto daily_pay = asset( 48, SBD_SYMBOL );
auto hourly_pay = asset( daily_pay.amount.value / 24, SBD_SYMBOL );
auto daily_pay = ASSET( "48.000 TBD" );
auto hourly_pay = ASSET( "1.996 TBD" );// hourly_pay != ASSET( "2.000 TBD" ) because lack of rounding

FUND( creator, ASSET( "160.000 TESTS" ) );
FUND( creator, ASSET( "80.000 TBD" ) );
Expand Down Expand Up @@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE( generating_payments_01 )
auto end_date = start_date + end_time_shift;

auto daily_pay = ASSET( "24.000 TBD" );
auto paid = ASSET( "5.000 TBD" );//because only 5 hours
auto paid = ASSET( "4.990 TBD" );// paid != ASSET( "5.000 TBD" ) because lack of rounding

FUND( STEEM_TREASURY_ACCOUNT, ASSET( "5000000.000 TBD" ) );
//=====================preparing=====================
Expand Down Expand Up @@ -424,7 +424,8 @@ BOOST_AUTO_TEST_CASE( generating_payments_03 )
`tester01` - got payout
`tester02` - no payout, because of lack of votes
*/
payment_checker( { ASSET( "1.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "0.000 TBD" ) } );
payment_checker( { ASSET( "0.998 TBD" ), ASSET( "0.998 TBD" ), ASSET( "0.000 TBD" ) } );
//ideally: ASSET( "1.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "0.000 TBD" ) but there is lack of rounding

{
BOOST_TEST_MESSAGE( "Setting proxy. The account `tester01` don't want to vote. Every decision is made by account `tester00`" );
Expand All @@ -445,7 +446,8 @@ BOOST_AUTO_TEST_CASE( generating_payments_03 )
`tester01` - no payout, because this account set proxy
`tester02` - no payout, because of lack of votes
*/
payment_checker( { ASSET( "2.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "0.000 TBD" ) } );
payment_checker( { ASSET( "1.996 TBD" ), ASSET( "0.998 TBD" ), ASSET( "0.000 TBD" ) } );
//ideally: ASSET( "2.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "0.000 TBD" ) but there is lack of rounding

vote_proposal( tester02_account, {2}, true/*approve*/, inits[ tester02_account ] );
generate_block();
Expand All @@ -456,7 +458,8 @@ BOOST_AUTO_TEST_CASE( generating_payments_03 )
`tester01` - no payout, because this account set proxy
`tester02` - got payout, because voted for his proposal
*/
payment_checker( { ASSET( "3.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "2082.346 TBD" ) } );
payment_checker( { ASSET( "2.994 TBD" ), ASSET( "0.998 TBD" ), ASSET( "2079.015 TBD" ) } );
//ideally: ASSET( "3.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "2082.346 TBD" ) but there is lack of rounding

{
BOOST_TEST_MESSAGE( "Proxy doesn't exist. Now proposal with id = 3 has the most votes. This proposal grabs all payouts." );
Expand All @@ -477,7 +480,8 @@ BOOST_AUTO_TEST_CASE( generating_payments_03 )
`tester01` - no payout, because is not enough money
`tester02` - got payout, because voted for his proposal
*/
payment_checker( { ASSET( "3.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "4164.824 TBD" ) } );
payment_checker( { ASSET( "2.994 TBD" ), ASSET( "0.998 TBD" ), ASSET( "4158.162 TBD" ) } );
//ideally: ASSET( "3.000 TBD" ), ASSET( "1.000 TBD" ), ASSET( "4164.824 TBD" ) but there is lack of rounding

validate_database();
}
Expand Down

0 comments on commit 31d5bea

Please sign in to comment.