diff --git a/libraries/blockchain/include/bts/blockchain/checkpoints.hpp b/libraries/blockchain/include/bts/blockchain/checkpoints.hpp index c4b5c9d4c..405515715 100644 --- a/libraries/blockchain/include/bts/blockchain/checkpoints.hpp +++ b/libraries/blockchain/include/bts/blockchain/checkpoints.hpp @@ -11,5 +11,5 @@ const static std::map CHECKPOINT_BLOCK { 400000, bts::blockchain::block_id_type( "053d398b6597d5c61365afd100d87b824bf49f65" ) }, { 500000, bts::blockchain::block_id_type( "f02910a7115fb826984ce3a432cb371d5d7a99b8" ) }, { 600000, bts::blockchain::block_id_type( "f278db8722235343c9db9f077fe67c54a5f25f3b" ) }, - { 622000, bts::blockchain::block_id_type( "8e9880bd7bb1fb49d2aa0fc98b7da8debe0b4de7" ) } + { 632000, bts::blockchain::block_id_type( "aa6526cc642f531b160de4505c4bd6c7a8add026" ) } }; diff --git a/libraries/blockchain/market_operations.cpp b/libraries/blockchain/market_operations.cpp index f24337415..87e02f6d1 100644 --- a/libraries/blockchain/market_operations.cpp +++ b/libraries/blockchain/market_operations.cpp @@ -53,6 +53,13 @@ namespace bts { namespace blockchain { current_bid->last_update = eval_state._current_state->now(); current_bid->balance += this->amount; + // bids do not count toward depth... they can set any price they like and create arbitrary depth + //auto market_stat = eval_state._current_state->get_market_status( bid_index.order_price.quote_asset_id, bid_index.order_price.base_asset_id ); + //if( !market_stat ) + // market_stat = market_status(0,0); + // market_stat->bid_depth += (delta_amount * bid_index.order_price).amount; + //eval_state._current_state->store_market_status( *market_stat ); + eval_state._current_state->store_bid_record( this->bid_index, *current_bid ); //auto check = eval_state._current_state->get_bid_record( this->bid_index ); @@ -104,7 +111,17 @@ namespace bts { namespace blockchain { current_ask->balance += this->amount; FC_ASSERT( current_ask->balance >= 0, "", ("current_ask",current_ask) ); + auto market_stat = eval_state._current_state->get_market_status( ask_index.order_price.quote_asset_id, ask_index.order_price.base_asset_id ); + + if( !market_stat ) + market_stat = market_status( ask_index.order_price.quote_asset_id, ask_index.order_price.base_asset_id, 0, 0 ); + market_stat->ask_depth += delta_amount.amount; + + eval_state._current_state->store_market_status( *market_stat ); + eval_state._current_state->store_ask_record( this->ask_index, *current_ask ); + + //auto check = eval_state._current_state->get_ask_record( this->ask_index ); } FC_CAPTURE_AND_RETHROW( (*this) ) } void short_operation::evaluate( transaction_evaluation_state& eval_state ) @@ -164,6 +181,14 @@ namespace bts { namespace blockchain { current_short->balance += this->amount; FC_ASSERT( current_short->balance >= 0 ); + auto market_stat = eval_state._current_state->get_market_status( short_index.order_price.quote_asset_id, short_index.order_price.base_asset_id ); + if( !market_stat ) + market_stat = market_status( short_index.order_price.quote_asset_id, short_index.order_price.base_asset_id, 0, 0 ); + + market_stat->bid_depth += delta_amount.amount; + + eval_state._current_state->store_market_status( *market_stat ); + eval_state._current_state->store_short_record( this->short_index, *current_short ); } @@ -231,6 +256,12 @@ namespace bts { namespace blockchain { else // withdraw the collateral to the transaction to be deposited at owners discretion / cover fees { eval_state.add_balance( asset( current_cover->collateral_balance, cover_index.order_price.base_asset_id ) ); + + auto market_stat = eval_state._current_state->get_market_status( cover_index.order_price.quote_asset_id, cover_index.order_price.base_asset_id ); + FC_ASSERT( market_stat, "this should be valid for there to even be a position to cover" ); + market_stat->ask_depth -= current_cover->collateral_balance; + + eval_state._current_state->store_market_status( *market_stat ); } } @@ -264,6 +295,12 @@ namespace bts { namespace blockchain { eval_state._current_state->store_collateral_record( market_index_key( new_call_price, this->cover_index.owner), *current_cover ); + + auto market_stat = eval_state._current_state->get_market_status( cover_index.order_price.quote_asset_id, cover_index.order_price.base_asset_id ); + FC_ASSERT( market_stat, "this should be valid for there to even be a position to cover" ); + market_stat->ask_depth += delta_amount.amount; + + eval_state._current_state->store_market_status( *market_stat ); } void remove_collateral_operation::evaluate( transaction_evaluation_state& eval_state ) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index dcc2c0605..07251cfe1 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2334,6 +2334,8 @@ namespace bts { namespace net { namespace detail { ( "type", fetch_items_message_received.item_type ) ( "endpoint", originating_peer->get_remote_endpoint() ) ); + fc::optional last_block_message_sent; + std::list reply_messages; for( const item_hash_t& item_hash : fetch_items_message_received.items_to_fetch ) { @@ -2344,6 +2346,8 @@ namespace bts { namespace net { namespace detail { ( "endpoint", originating_peer->get_remote_endpoint() ) ( "id", requested_message.id() ) ); reply_messages.push_back( requested_message ); + if (fetch_items_message_received.item_type == block_message_type) + last_block_message_sent = requested_message; continue; } catch ( fc::key_not_found_exception& ) @@ -2360,6 +2364,8 @@ namespace bts { namespace net { namespace detail { ( "size", requested_message.size ) ( "endpoint", originating_peer->get_remote_endpoint() ) ); reply_messages.push_back( requested_message ); + if (fetch_items_message_received.item_type == block_message_type) + last_block_message_sent = requested_message; continue; } catch ( fc::key_not_found_exception& ) @@ -2369,6 +2375,16 @@ namespace bts { namespace net { namespace detail { ( "endpoint", originating_peer->get_remote_endpoint() ) ); } } + + // if we sent them a block, update our record of the last block they've seen accordingly + if (last_block_message_sent) + { + bts::client::block_message block = last_block_message_sent->as(); + originating_peer->last_block_delegate_has_seen = block.block_id; + originating_peer->last_block_number_delegate_has_seen = _delegate->get_block_number(block.block_id); + originating_peer->last_block_time_delegate_has_seen = _delegate->get_block_time(block.block_id); + } + for( const message& reply : reply_messages ) originating_peer->send_message( reply ); }