node.cpp: Check the attacker/buggy client before updating items ids

The peer is an attacker or buggy, which means the item_hashes_received is
not correct.

Move the check before updating items ids to save some time in this case.
This commit is contained in:
Wei Yang 2018-05-30 16:30:03 +08:00 committed by gladcow
parent 1cb494e686
commit 83b19d0b84

View file

@ -2649,11 +2649,6 @@ namespace graphene { namespace net { namespace detail {
if (!item_hashes_received.empty() && !originating_peer->ids_of_items_to_get.empty()) if (!item_hashes_received.empty() && !originating_peer->ids_of_items_to_get.empty())
assert(item_hashes_received.front() != originating_peer->ids_of_items_to_get.back()); assert(item_hashes_received.front() != originating_peer->ids_of_items_to_get.back());
// append the remaining items to the peer's list
boost::push_back(originating_peer->ids_of_items_to_get, item_hashes_received);
originating_peer->number_of_unfetched_item_ids = blockchain_item_ids_inventory_message_received.total_remaining_item_count;
// at any given time, there's a maximum number of blocks that can possibly be out there // at any given time, there's a maximum number of blocks that can possibly be out there
// [(now - genesis time) / block interval]. If they offer us more blocks than that, // [(now - genesis time) / block interval]. If they offer us more blocks than that,
// they must be an attacker or have a buggy client. // they must be an attacker or have a buggy client.
@ -2676,6 +2671,12 @@ namespace graphene { namespace net { namespace detail {
return; return;
} }
// append the remaining items to the peer's list
boost::push_back(originating_peer->ids_of_items_to_get, item_hashes_received);
originating_peer->number_of_unfetched_item_ids = blockchain_item_ids_inventory_message_received.total_remaining_item_count;
uint32_t new_number_of_unfetched_items = calculate_unsynced_block_count_from_all_peers(); uint32_t new_number_of_unfetched_items = calculate_unsynced_block_count_from_all_peers();
if (new_number_of_unfetched_items != _total_number_of_unfetched_items) if (new_number_of_unfetched_items != _total_number_of_unfetched_items)
_delegate->sync_status(blockchain_item_ids_inventory_message_received.item_type, _delegate->sync_status(blockchain_item_ids_inventory_message_received.item_type,