From b229e7e54c0bd9d594aab8ad7f32f64e988f19f6 Mon Sep 17 00:00:00 2001 From: almogdepaz Date: Mon, 9 Dec 2024 12:53:06 +0200 Subject: [PATCH] handle none --- chia/_tests/util/blockchain_mock.py | 3 ++- chia/consensus/blockchain.py | 3 ++- chia/util/augmented_chain.py | 5 ++++- chia/util/block_cache.py | 3 ++- chia/wallet/wallet_blockchain.py | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/chia/_tests/util/blockchain_mock.py b/chia/_tests/util/blockchain_mock.py index 11fde9585c9d..80a9dca1bf4e 100644 --- a/chia/_tests/util/blockchain_mock.py +++ b/chia/_tests/util/blockchain_mock.py @@ -77,7 +77,8 @@ def contains_block(self, header_hash: bytes32, height: Optional[uint32] = None) return False height = block_rec.height block_hash_from_hh = self.height_to_hash(height) - assert block_hash_from_hh is not None + if block_hash_from_hh is None: + return False assert block_hash_from_hh == header_hash return True diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 773132585080..316043e22b24 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -780,7 +780,8 @@ def contains_block(self, header_hash: bytes32, height: Optional[uint32] = None) return False height = block_rec.height block_hash_from_hh = self.height_to_hash(height) - assert block_hash_from_hh is not None + if block_hash_from_hh is None: + return False assert block_hash_from_hh == header_hash return True diff --git a/chia/util/augmented_chain.py b/chia/util/augmented_chain.py index 5b7489486e49..f101250cd726 100644 --- a/chia/util/augmented_chain.py +++ b/chia/util/augmented_chain.py @@ -123,8 +123,11 @@ def contains_block(self, header_hash: bytes32, height: Optional[uint32] = None) if block_rec is None: return False height = block_rec.height + if not self.contains_height(height): + return False block_hash_from_hh = self.height_to_hash(height) - assert block_hash_from_hh is not None + if block_hash_from_hh is None: + return False assert block_hash_from_hh == header_hash return True diff --git a/chia/util/block_cache.py b/chia/util/block_cache.py index 0a705f3ac2c8..d4c43b20df43 100644 --- a/chia/util/block_cache.py +++ b/chia/util/block_cache.py @@ -54,7 +54,8 @@ def contains_block(self, header_hash: bytes32, height: Optional[uint32] = None) return False height = block_rec.height block_hash_from_hh = self.height_to_hash(height) - assert block_hash_from_hh is not None + if block_hash_from_hh is None: + return False assert block_hash_from_hh == header_hash return True diff --git a/chia/wallet/wallet_blockchain.py b/chia/wallet/wallet_blockchain.py index 548657deb50c..45275190e28c 100644 --- a/chia/wallet/wallet_blockchain.py +++ b/chia/wallet/wallet_blockchain.py @@ -203,7 +203,8 @@ def contains_block(self, header_hash: bytes32, height: Optional[uint32] = None) return False height = block_rec.height block_hash_from_hh = self.height_to_hash(height) - assert block_hash_from_hh is not None + if block_hash_from_hh is None: + return False assert block_hash_from_hh == header_hash return True