From efea41dc8bf32d267fc15eec2fa2c6f76b77be4c Mon Sep 17 00:00:00 2001 From: almog Date: Wed, 16 Dec 2020 12:24:41 +0200 Subject: [PATCH] pass ci sync test, logs --- src/full_node/full_node.py | 43 +++++++++++++++------------------- src/full_node/full_node_api.py | 1 + src/full_node/weight_proof.py | 1 + 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/full_node/full_node.py b/src/full_node/full_node.py index 9e2c2d0d4a..9f6105b8bd 100644 --- a/src/full_node/full_node.py +++ b/src/full_node/full_node.py @@ -290,38 +290,33 @@ class FullNode: if self._shut_down: return + heaviest_peak: Optional[FullBlock] = None for header_hash, potential_peak_block in potential_peaks: - if potential_peak_block.weight > highest_weight: - highest_weight = potential_peak_block.weight - target_peak_sb_height = potential_peak_block.sub_block_height - peak_hash = potential_peak_block.header_hash + if potential_peak_block.weight > heaviest_peak.weight: + heaviest_peak = potential_peak_block - if self.blockchain.get_peak() is not None and highest_weight <= self.blockchain.get_peak().weight: + if self.blockchain.get_peak() is not None and heaviest_peak.weight <= self.blockchain.get_peak().weight: self.log.info("Not performing sync, already caught up.") return + # chain shorter then a sub-epoch self.log.info(f"Peak height {target_peak_sb_height}") - # send weight proof message, continue on first response - - # begin wjb make double sure we have fork_point - valid, fork_point_height = await self._fetch_and_validate_weight_proof( - peak_hash, self.server.get_full_node_connections(), target_peak_sb_height - ) - - if valid: - self.sync_store.add_potential_fork_point(peak_hash, fork_point_height) - # end wjb - if target_peak_sb_height < self.constants.SUB_EPOCH_SUB_BLOCKS: self.log.info("first sub epoch, dont use weight proofs") - # todo work on this flow so we dont fetch redundant blocks return await self.sync_from_fork_point(-1, sync_start_time, target_peak_sb_height) - self.log.info(f"get peak {peak_hash}") - fork_point = self.sync_store.get_potential_fork_point(peak_hash) - if fork_point is None: + + # todo move this to when peaks are received + valid, fork_point_height = await self._fetch_and_validate_weight_proof( + heaviest_peak.header_hash, self.server.get_full_node_connections(), target_peak_sb_height + ) + + # todo should not happen + self.log.info(f"get peak {heaviest_peak.header_hash}") + if fork_point_height is None or not valid: self.log.error("No fork point for peak") - return - await self.sync_from_fork_point(max(0, fork_point - 1), sync_start_time, target_peak_sb_height) + return await self.sync_from_fork_point(-1, sync_start_time, target_peak_sb_height) + + return await self.sync_from_fork_point(fork_point_height - 1, sync_start_time, target_peak_sb_height) except asyncio.CancelledError: self.log.warning("Syncing failed, CancelledError") except Exception as e: @@ -417,11 +412,11 @@ class FullNode: "request_proof_of_weight", full_node_protocol.RequestProofOfWeight(target_peak_sb_height, peak_hash), peers, - 60 + 60, ) if response is None: - self.log.error("response was None") + self.log.error(f"weight proof response for peak {peak_hash} was None") return False, uint32(0) cache = await init_block_cache(self.blockchain) diff --git a/src/full_node/full_node_api.py b/src/full_node/full_node_api.py index 0d5c0fa01f..650c7f2f24 100644 --- a/src/full_node/full_node_api.py +++ b/src/full_node/full_node_api.py @@ -191,6 +191,7 @@ class FullNodeAPI: self.full_node.weight_proof_handler.set_block_cache(cache) wp = await self.full_node.weight_proof_handler.create_proof_of_weight(request.tip) if wp is None: + self.log.error(f"failed creating weight proof for peak {request.tip}") return None return Message("respond_proof_of_weight", full_node_protocol.RespondProofOfWeight(wp, request.tip)) diff --git a/src/full_node/weight_proof.py b/src/full_node/weight_proof.py index 2d069a3dad..e0ba2e8a5c 100644 --- a/src/full_node/weight_proof.py +++ b/src/full_node/weight_proof.py @@ -105,6 +105,7 @@ class WeightProofHandler: # sub epoch summaries validate hashes assert self.block_cache is not None assert len(weight_proof.sub_epochs) > 0 + self.log.info(f"validate weight proof") summaries = self.validate_sub_epoch_summaries(weight_proof) if summaries is None: return False, uint32(0)