Include latest_block_height in lookup response (#627)

This commit is contained in:
Jonathan Zernik 2021-01-12 19:44:30 -08:00 committed by GitHub
parent 5572ee07d0
commit b26c3ea9df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View file

@ -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 {

View file

@ -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,
)

View file

@ -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(