diff --git a/proto/squeak_server.proto b/proto/squeak_server.proto index 2fead599..09e25d96 100644 --- a/proto/squeak_server.proto +++ b/proto/squeak_server.proto @@ -61,11 +61,14 @@ message GetSqueakReply { } message LookupSqueaksReply { - /// Hash of the squeak to get. - repeated bytes hashes = 1; + /// Height of the latest block. + int32 latest_block_height = 1; /// Hash of the squeak to get. - repeated string allowed_addresses = 2; + repeated bytes hashes = 2; + + /// Hash of the squeak to get. + repeated string allowed_addresses = 3; } message GetOfferReply { diff --git a/squeaknode/server/squeak_server_handler.py b/squeaknode/server/squeak_server_handler.py index f6d60086..fb0e70f5 100644 --- a/squeaknode/server/squeak_server_handler.py +++ b/squeaknode/server/squeak_server_handler.py @@ -43,7 +43,9 @@ class SqueakServerHandler(object): "Got number of allowed addresses from db: {}".format( len(allowed_addresses)) ) + latest_block_height = self.squeak_controller.get_best_block_height() return squeak_server_pb2.LookupSqueaksReply( + latest_block_height=latest_block_height, hashes=hashes, allowed_addresses=allowed_addresses, ) diff --git a/squeaknode/sync/peer_task.py b/squeaknode/sync/peer_task.py index ddf72d59..df036001 100644 --- a/squeaknode/sync/peer_task.py +++ b/squeaknode/sync/peer_task.py @@ -39,7 +39,8 @@ class PeerSyncTask: hashes_to_download = set(remote_hashes) - set(local_hashes) # Download squeaks for the hashes - # TODO: catch exception downloading individual squeak + # TODO: catch exception downloading individual squeak. + # TODO: check if hash belongs to correct range after downloading. for hash in hashes_to_download: if self.peer_connection.stopped(): return @@ -70,6 +71,11 @@ class PeerSyncTask: addresses, min_block, max_block) remote_hashes = lookup_result.hashes allowed_addresses = lookup_result.allowed_addresses + peer_latest_block = lookup_result.latest_block_height + + max_block = min(max_block, peer_latest_block) + if max_block < min_block: + return # Get local hashes local_hashes = self._get_local_unlocked_hashes(