From b80587e5b54a31f1200facc34f1df47f4c45be57 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 5 Nov 2015 17:12:57 -0500 Subject: [PATCH] Prevent margin call from being triggered unless feed < call #436 --- libraries/chain/db_market.cpp | 31 +++++++++---------- .../chain/include/graphene/chain/hardfork.hpp | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 0a280a81..f45fed6d 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -416,15 +417,8 @@ bool database::check_call_orders(const asset_object& mia, bool enable_black_swan auto limit_itr = limit_price_index.lower_bound( max_price ); auto limit_end = limit_price_index.upper_bound( min_price ); - if( limit_itr == limit_end ) { - /* - if( head_block_num() > 300000 ) - ilog( "no orders below between: ${p} and: ${m}", - ("p", bitasset.current_feed.max_short_squeeze_price()) - ("m", max_price) ); - */ + if( limit_itr == limit_end ) return false; - } auto call_min = price::min( bitasset.options.short_backing_asset, mia.id ); auto call_max = price::max( bitasset.options.short_backing_asset, mia.id ); @@ -434,14 +428,6 @@ bool database::check_call_orders(const asset_object& mia, bool enable_black_swan bool filled_limit = false; bool margin_called = false; - /* - if( head_block_num() >= 11510 && head_block_num() <= 11512) { - idump(("enter loop") ); - auto tmp = call_itr; - while( tmp != call_end ) { edump( (*tmp) ); ++tmp; } - } - */ - while( !check_for_blackswan( mia, enable_black_swan ) && call_itr != call_end ) { bool filled_call = false; @@ -457,9 +443,22 @@ bool database::check_call_orders(const asset_object& mia, bool enable_black_swan match_price.validate(); + // would be margin called, but there is no matching order #436 + bool feed_protected = ( bitasset.current_feed.settlement_price > ~call_itr->call_price ); + if( feed_protected && (head_block_time() > HARDFORK_436_TIME) ) + return margin_called; + + // would be margin called, but there is no matching order if( match_price > ~call_itr->call_price ) return margin_called; + if( feed_protected ) + { + ilog( "Feed protected margin call executing (HARDFORK_436_TIME not here yet)" ); + idump( (*call_itr) ); + idump( (*limit_itr) ); + } + // idump((*call_itr)); // idump((*limit_itr)); diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index c5e50f03..7f5da1a8 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -27,3 +27,4 @@ #define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) #define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 )) #define HARDFORK_419_TIME (fc::time_point_sec( 1446652800 )) +#define HARDFORK_436_TIME (fc::time_point_sec( 2000000000 ))