Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Cancel all shorts on hardfork
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Mar 23, 2015
1 parent 9edac46 commit 0386f83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
26 changes: 0 additions & 26 deletions libraries/blockchain/chain_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,32 +1126,6 @@ namespace bts { namespace blockchain {
}
}

if( block_data.block_num == BTS_SHORTFIX_FORK_BLOCK_NUM )
{
static const fc::uint128 max_apr = fc::uint128( BTS_BLOCKCHAIN_MAX_SHORT_APR_PCT ) * FC_REAL128_PRECISION / 100;

map<market_index_key, order_record> records;
for( auto iter = _short_db.begin(); iter.valid(); ++iter )
{
const market_index_key& key = iter.key();
if( key.order_price.ratio > max_apr )
records[ key ] = iter.value();
}

wlog( "Block ${n} Hardfork: Resetting interest rates for ${x} short orders", ("n",block_data.block_num)("x",records.size()) );

for( const auto& item : records )
{
market_index_key key = item.first;
const order_record& record = item.second;

// TODO: Use db interface remove and store when implemented
_short_db.remove( key );
key.order_price.ratio = std::min( max_apr, key.order_price.ratio );
_short_db.store( key, record );
}
}

if( block_record.valid() )
{
block_record->processing_time = time_point::now() - start_time;
Expand Down
8 changes: 7 additions & 1 deletion libraries/blockchain/chain_database_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ void chain_database_impl::execute_markets_v1( const fc::time_point_sec timestamp
engine.cancel_all_shorts();
market_transactions.insert( market_transactions.end(), engine._market_transactions.begin(), engine._market_transactions.end() );
}
else if( pending_block_num == BTS_SHORTFIX_FORK_BLOCK_NUM )
{
market_engine_v7 engine( pending_state, *this );
engine.cancel_all_shorts();
market_transactions.insert( market_transactions.end(), engine._market_transactions.begin(), engine._market_transactions.end() );
}

const auto dirty_markets = self->get_dirty_markets();
for( const auto& market_pair : dirty_markets )
{
FC_ASSERT( market_pair.first > market_pair.second );
if( pending_block_num > BTS_V0_4_21_FORK_BLOCK_NUM )
if( pending_block_num > BTS_V0_4_21_FORK_BLOCK_NUM && pending_block_num != BTS_SHORTFIX_FORK_BLOCK_NUM )
{
market_engine_v7 engine( pending_state, *this );
if( engine.execute( market_pair.first, market_pair.second, timestamp ) )
Expand Down

0 comments on commit 0386f83

Please sign in to comment.