@@ -149,9 +149,29 @@ def verify_reward_locked(self, tx: Transaction) -> None:
149
149
self .verify_reward_locked_for_height (tx , best_height )
150
150
151
151
@staticmethod
152
- def verify_reward_locked_for_height (tx : Transaction , best_height : int , * , verify_min_height : bool = False ) -> None :
153
- """Will raise `RewardLocked` if any reward is spent before the best block height is enough, considering both
154
- the block rewards spent by this tx itself, and the inherited `min_height`."""
152
+ def verify_reward_locked_for_height (
153
+ tx : Transaction ,
154
+ best_height : int ,
155
+ * ,
156
+ assert_min_height_verification : bool = True
157
+ ) -> None :
158
+ """
159
+ Will raise `RewardLocked` if any reward is spent before the best block height is enough, considering both
160
+ the block rewards spent by this tx itself, and the inherited `min_height`.
161
+
162
+ Args:
163
+ tx: the transaction to be verified.
164
+ best_height: the height of the best chain to be used for verification.
165
+ assert_min_height_verification: whether the inherited `min_height` verification must pass.
166
+
167
+ Note: for verification of new transactions, `assert_min_height_verification` must be `True`. This
168
+ verification is always expected to pass for new txs, as a failure would mean one of its dependencies would
169
+ have failed too. So an `AssertionError` is raised if it fails.
170
+
171
+ However, when txs are being re-verified for Reward Lock during a reorg, it's possible that txs may fail
172
+ their inherited `min_height` verification. So in that case `assert_min_height_verification` is `False`,
173
+ and a normal `RewardLocked` exception is raised instead.
174
+ """
155
175
assert tx .storage is not None
156
176
info = get_spent_reward_locked_info (tx , tx .storage )
157
177
if info is not None :
@@ -161,12 +181,11 @@ def verify_reward_locked_for_height(tx: Transaction, best_height: int, *, verify
161
181
assert meta .min_height is not None
162
182
# We use +1 here because a tx is valid if it can be confirmed by the next block
163
183
if best_height + 1 < meta .min_height :
164
- if verify_min_height :
165
- raise RewardLocked (
166
- f'Tx { tx .hash_hex } has min_height={ meta .min_height } , but the best_height={ best_height } .'
167
- )
168
- else :
169
- raise AssertionError ('a new tx should never be invalid by its inherited min_height' )
184
+ if assert_min_height_verification :
185
+ raise AssertionError ('a new tx should never be invalid by its inherited min_height.' )
186
+ raise RewardLocked (
187
+ f'Tx { tx .hash_hex } has min_height={ meta .min_height } , but the best_height={ best_height } .'
188
+ )
170
189
171
190
def verify_number_of_inputs (self , tx : Transaction ) -> None :
172
191
"""Verify number of inputs is in a valid range"""
0 commit comments