Skip to content

Commit

Permalink
Merge pull request #1571 from bitshares/jmj_1465b
Browse files Browse the repository at this point in the history
Do not allow supply to exceed MAX_SUPPLY
  • Loading branch information
jmjatlanta authored Feb 12, 2019
2 parents 805aca3 + d046340 commit 2f66535
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions libraries/chain/hardfork.d/CORE_1465.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// bitshares-core issue #1465 check max_supply before processing call_order_update
#ifndef HARDFORK_CORE_1465_TIME
#define HARDFORK_CORE_1465_TIME (fc::time_point_sec( 1600000000 )) // 2020-09-13 12:26:40
#define SOFTFORK_CORE_1465_TIME (fc::time_point_sec( 1545350400 )) // 2018-12-21 00:00:00
#endif
21 changes: 18 additions & 3 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,25 @@ void_result call_order_update_evaluator::do_evaluate(const call_order_update_ope
("sym", _debt_asset->symbol) );

_dynamic_data_obj = &_debt_asset->dynamic_asset_data_id(d);
FC_ASSERT( next_maintenance_time <= HARDFORK_CORE_1465_TIME
|| _dynamic_data_obj->current_supply + o.delta_debt.amount <= _debt_asset->options.max_supply,
"Borrowing this quantity would exceed MAX_SUPPLY" );

/***
* We have softfork code already in production to prevent exceeding MAX_SUPPLY between 2018-12-21 until HF 1465.
* But we must allow this in replays until 2018-12-21. The HF 1465 code will correct the problem.
* After HF 1465, we MAY be able to remove the cleanup code IF it never executes. We MAY be able to clean
* up the softfork code IF it never executes. We MAY be able to turn the hardfork code into regular code IF
* noone ever attempted this before HF 1465.
*/
if (next_maintenance_time <= SOFTFORK_CORE_1465_TIME)
{
if ( _dynamic_data_obj->current_supply + o.delta_debt.amount <= _debt_asset->options.max_supply )
ilog("Issue 1465... Borrowing and exceeding MAX_SUPPLY. Will be corrected at hardfork time.");
}
else
{
FC_ASSERT( _dynamic_data_obj->current_supply + o.delta_debt.amount <= _debt_asset->options.max_supply,
"Borrowing this quantity would exceed MAX_SUPPLY" );
}

FC_ASSERT( _dynamic_data_obj->current_supply + o.delta_debt.amount >= 0,
"This transaction would bring current supply below zero.");

Expand Down
22 changes: 16 additions & 6 deletions libraries/chain/proposal_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,29 @@ namespace detail {
struct proposal_operation_hardfork_visitor
{
typedef void result_type;
const database& db;
const fc::time_point_sec block_time;
const fc::time_point_sec next_maintenance_time;

proposal_operation_hardfork_visitor( const fc::time_point_sec bt, const fc::time_point_sec nmt )
: block_time(bt), next_maintenance_time(nmt) {}
proposal_operation_hardfork_visitor( const database& _db, const fc::time_point_sec bt )
: db( _db ), block_time(bt), next_maintenance_time( db.get_dynamic_global_properties().next_maintenance_time ) {}

template<typename T>
void operator()(const T &v) const {}

// TODO review and cleanup code below after hard fork
// hf_834
void operator()(const graphene::chain::call_order_update_operation &v) const {

// TODO If this never ASSERTs before HF 1465, it can be removed
FC_ASSERT( block_time < SOFTFORK_CORE_1465_TIME
|| block_time > HARDFORK_CORE_1465_TIME
|| v.delta_debt.asset_id == asset_id_type(113) // CNY
|| v.delta_debt.amount < 0
|| (v.delta_debt.asset_id( db ).bitasset_data_id
&& (*(v.delta_debt.asset_id( db ).bitasset_data_id))( db ).is_prediction_market )
, "Soft fork - preventing proposal with call_order_update!" );

// TODO review and cleanup code below after hard fork
// hf_834
if (next_maintenance_time <= HARDFORK_CORE_834_TIME) {
FC_ASSERT( !v.extensions.value.target_collateral_ratio.valid(),
"Can not set target_collateral_ratio in call_order_update_operation before hardfork 834." );
Expand Down Expand Up @@ -181,8 +192,7 @@ void_result proposal_create_evaluator::do_evaluate(const proposal_create_operati

// Calling the proposal hardfork visitor
const fc::time_point_sec block_time = d.head_block_time();
const fc::time_point_sec next_maint_time = d.get_dynamic_global_properties().next_maintenance_time;
proposal_operation_hardfork_visitor vtor( block_time, next_maint_time );
proposal_operation_hardfork_visitor vtor( d, block_time );
vtor( o );
if( block_time < HARDFORK_CORE_214_TIME )
{ // cannot be removed after hf, unfortunately
Expand Down

0 comments on commit 2f66535

Please sign in to comment.