Skip to content

Fix withdrawal claim too early #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libraries/chain/hardfork.d/23.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Issue #23: Withdrawal claims made before the first withdrawal period are incorrectly allowed
// Fork time set to 2017-02-01 00:00:00 UTC
#ifndef HARDFORK_23_TIME
#define HARDFORK_23_TIME (fc::time_point_sec( 1485907200 ))
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <boost/multi_index/composite_key.hpp>

namespace graphene { namespace chain {

/**
* @class withdraw_permission_object
* @brief Grants another account authority to withdraw a limited amount of funds per interval
Expand All @@ -52,14 +51,23 @@ namespace graphene { namespace chain {
asset withdrawal_limit;
/// The duration of a withdrawal period in seconds
uint32_t withdrawal_period_sec = 0;
/// The beginning of the next withdrawal period
/***
* The beginning of the next withdrawal period
* WARNING: Due to caching, this value does not always represent the start of the next or current period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
*/
time_point_sec period_start_time;
/// The time at which this withdraw permission expires
time_point_sec expiration;

/// tracks the total amount
/***
* Tracks the total amount
* WARNING: Due to caching, this value does not always represent the total amount claimed during the current period; it may represent what was claimed during the last claimed period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
*/
share_type claimed_this_period;
/// True if the permission may still be claimed for this period; false if it has already been used

/***
* Determine how much is still available to be claimed during the period that contains a time of interest. This object and function is mainly intended to be used with the "current" time as a parameter. The current time can be obtained from the time of the current head of the blockchain.
*/
asset available_this_period( fc::time_point_sec current_time )const
{
if( current_time >= period_start_time + withdrawal_period_sec )
Expand Down
8 changes: 6 additions & 2 deletions libraries/chain/withdraw_permission_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ object_id_type withdraw_permission_create_evaluator::do_apply(const operation_ty
void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_permission_claim_evaluator::operation_type& op)
{ try {
const database& d = db();
time_point_sec head_block_time = d.head_block_time();

const withdraw_permission_object& permit = op.withdraw_permission(d);
FC_ASSERT(permit.expiration > d.head_block_time() );
FC_ASSERT(permit.expiration > head_block_time);
FC_ASSERT(permit.authorized_account == op.withdraw_to_account);
FC_ASSERT(permit.withdraw_from_account == op.withdraw_from_account);
FC_ASSERT(op.amount_to_withdraw <= permit.available_this_period( d.head_block_time() ) );
if (head_block_time >= HARDFORK_23_TIME) {
FC_ASSERT(permit.period_start_time <= head_block_time);
}
FC_ASSERT(op.amount_to_withdraw <= permit.available_this_period( head_block_time ) );
FC_ASSERT(d.get_balance(op.withdraw_from_account, op.amount_to_withdraw.asset_id) >= op.amount_to_withdraw);

const asset_object& _asset = op.amount_to_withdraw.asset_id(d);
Expand Down
Loading