Permalink
Browse files

Merge pull request #1451 from bitshares/release

Emergency fix for stuck chain release -> master
  • Loading branch information...
pmconrad committed Nov 27, 2018
2 parents a0e7dff + eee685a commit 5b2309931c441412234c3bd09f39b41969c74dcc
Showing with 37 additions and 7 deletions.
  1. +12 −6 libraries/chain/db_maint.cpp
  2. +1 −1 libraries/chain/include/graphene/chain/config.hpp
  3. +24 −0 tests/tests/swan_tests.cpp
@@ -814,11 +814,14 @@ void database::process_bids( const asset_bitasset_data_object& bad )
while( covered < bdd.current_supply && itr != bid_idx.end() && itr->inv_swan_price.quote.asset_id == to_revive_id )
{
const collateral_bid_object& bid = *itr;
asset total_collateral = bid.inv_swan_price.quote * bad.settlement_price;
asset debt_in_bid = bid.inv_swan_price.quote;
if( debt_in_bid.amount > bdd.current_supply )
debt_in_bid.amount = bdd.current_supply;
asset total_collateral = debt_in_bid * bad.settlement_price;
total_collateral += bid.inv_swan_price.base;
price call_price = price::call_price( bid.inv_swan_price.quote, total_collateral, bad.current_feed.maintenance_collateral_ratio );
price call_price = price::call_price( debt_in_bid, total_collateral, bad.current_feed.maintenance_collateral_ratio );
if( ~call_price >= bad.current_feed.settlement_price ) break;
covered += bid.inv_swan_price.quote.amount;
covered += debt_in_bid.amount;
++itr;
}
if( covered < bdd.current_supply ) return;
@@ -830,9 +833,12 @@ void database::process_bids( const asset_bitasset_data_object& bad )
{
const collateral_bid_object& bid = *itr;
++itr;
share_type debt = bid.inv_swan_price.quote.amount;
share_type collateral = (bid.inv_swan_price.quote * bad.settlement_price).amount;
if( bid.inv_swan_price.quote.amount >= to_cover )
asset debt_in_bid = bid.inv_swan_price.quote;
if( debt_in_bid.amount > bdd.current_supply )
debt_in_bid.amount = bdd.current_supply;
share_type debt = debt_in_bid.amount;
share_type collateral = (debt_in_bid * bad.settlement_price).amount;
if( debt >= to_cover )
{
debt = to_cover;
collateral = remaining_fund;
@@ -121,7 +121,7 @@
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
#define GRAPHENE_CURRENT_DB_VERSION "BTS2.18"
#define GRAPHENE_CURRENT_DB_VERSION "BTS2.181127"
#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)
@@ -491,4 +491,28 @@ BOOST_AUTO_TEST_CASE( revive_empty_with_bid )
}
}
/** Creates a black swan, bids on more than outstanding debt
*/
BOOST_AUTO_TEST_CASE( overflow )
{ try {
init_standard_swan( 700 );
wait_for_hf_core_216();
bid_collateral( borrower(), back().amount(2200), swan().amount(GRAPHENE_MAX_SHARE_SUPPLY - 1) );
bid_collateral( borrower2(), back().amount(2100), swan().amount(1399) );
set_feed(1, 2);
wait_for_maintenance();
auto& call_idx = db.get_index_type<call_order_index>().indices().get<by_account>();
auto itr = call_idx.find( boost::make_tuple(_borrower, _swan) );
BOOST_REQUIRE( itr != call_idx.end() );
BOOST_CHECK_EQUAL( 1, itr->debt.value );
itr = call_idx.find( boost::make_tuple(_borrower2, _swan) );
BOOST_REQUIRE( itr != call_idx.end() );
BOOST_CHECK_EQUAL( 1399, itr->debt.value );
BOOST_CHECK( !swan().bitasset_data(db).has_settlement() );
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 5b23099

Please sign in to comment.