From 83b19d0b8487fe048a65410cd3f99cf78d4e39b1 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Wed, 30 May 2018 16:30:03 +0800 Subject: [PATCH] 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. --- libraries/net/node.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index a38199fd..7a978017 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2649,11 +2649,6 @@ namespace graphene { namespace net { namespace detail { 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()); - // 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 // [(now - genesis time) / block interval]. If they offer us more blocks than that, // they must be an attacker or have a buggy client. @@ -2676,6 +2671,12 @@ namespace graphene { namespace net { namespace detail { 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(); if (new_number_of_unfetched_items != _total_number_of_unfetched_items) _delegate->sync_status(blockchain_item_ids_inventory_message_received.item_type,