Skip to content
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

Fix bidding #1830

Merged
merged 3 commits into from
Aug 20, 2019
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
4 changes: 4 additions & 0 deletions libraries/chain/hardfork.d/CORE_1692.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// bitshares-core issue #1692 validation check of bid_collateral
#ifndef HARDFORK_CORE_1692_TIME
#define HARDFORK_CORE_1692_TIME (fc::time_point_sec( 1600000000 ) ) // Sep 2020
#endif
23 changes: 16 additions & 7 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,6 @@ void_result bid_collateral_evaluator::do_evaluate(const bid_collateral_operation

FC_ASSERT( !_bitasset_data->is_prediction_market, "Cannot bid on a prediction market!" );

if( o.additional_collateral.amount > 0 )
{
FC_ASSERT( d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)) >= o.additional_collateral,
"Cannot bid ${c} collateral when payer only has ${b}", ("c", o.additional_collateral.amount)
("b", d.get_balance(*_paying_account, o.additional_collateral.asset_id(d)).amount) );
}

const collateral_bid_index& bids = d.get_index_type<collateral_bid_index>();
const auto& index = bids.indices().get<by_account>();
const auto& bid = index.find( boost::make_tuple( o.debt_covered.asset_id, o.bidder ) );
Expand All @@ -406,6 +399,22 @@ void_result bid_collateral_evaluator::do_evaluate(const bid_collateral_operation
else
FC_ASSERT( o.debt_covered.amount > 0, "Can't find bid to cancel?!");

if( o.additional_collateral.amount > 0 )
{
if( _bid && d.head_block_time() >= HARDFORK_CORE_1692_TIME ) // TODO: see if HF check can be removed after HF
{
asset delta = o.additional_collateral - _bid->get_additional_collateral();
FC_ASSERT( d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)) >= delta,
"Cannot increase bid from ${oc} to ${nc} collateral when payer only has ${b}",
("oc", _bid->get_additional_collateral().amount)("nc", o.additional_collateral.amount)
("b", d.get_balance(*_paying_account, o.additional_collateral.asset_id(d)).amount) );
} else
abitmore marked this conversation as resolved.
Show resolved Hide resolved
FC_ASSERT( d.get_balance( *_paying_account,
_bitasset_data->options.short_backing_asset(d) ) >= o.additional_collateral,
"Cannot bid ${c} collateral when payer only has ${b}", ("c", o.additional_collateral.amount)
("b", d.get_balance(*_paying_account, o.additional_collateral.asset_id(d)).amount) );
}

return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }

Expand Down
24 changes: 24 additions & 0 deletions tests/tests/swan_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ BOOST_AUTO_TEST_CASE( recollateralize )
}
}

/** Creates a black swan, bid, adjust bid before/after hf_1692
*/
BOOST_AUTO_TEST_CASE( bid_issue_1692 )
{ try {
init_standard_swan( 700 );

generate_blocks( HARDFORK_CORE_1692_TIME - 30 );

int64_t b2_balance = get_balance( borrower2(), back() );
bid_collateral( borrower2(), back().amount(1000), swan().amount(100) );
BOOST_CHECK_EQUAL( get_balance( borrower2(), back() ), b2_balance - 1000 );
GRAPHENE_REQUIRE_THROW( bid_collateral( borrower2(), back().amount(b2_balance), swan().amount(200) ),
fc::assert_exception );
GRAPHENE_REQUIRE_THROW( bid_collateral( borrower2(), back().amount(b2_balance-999), swan().amount(200) ),
fc::assert_exception );

generate_blocks( HARDFORK_CORE_1692_TIME + 30 );

bid_collateral( borrower2(), back().amount(b2_balance-999), swan().amount(200) );
BOOST_CHECK_EQUAL( get_balance( borrower2(), back() ), 999 );
bid_collateral( borrower2(), back().amount(b2_balance), swan().amount(200) );
BOOST_CHECK_EQUAL( get_balance( borrower2(), back() ), 0 );
} FC_LOG_AND_RETHROW() }

/** Creates a black swan, settles all debts, recovers price feed - asset should be revived
*/
BOOST_AUTO_TEST_CASE( revive_empty_recovered )
Expand Down