|
24 | 24 | from hathor.consensus.transaction_consensus import TransactionConsensusAlgorithmFactory |
25 | 25 | from hathor.execution_manager import non_critical_code |
26 | 26 | from hathor.feature_activation.feature import Feature |
| 27 | +from hathor.nanocontracts.exception import NCInvalidSignature |
27 | 28 | from hathor.nanocontracts.execution import NCBlockExecutor |
28 | 29 | from hathor.profiler import get_cpu_profiler |
29 | 30 | from hathor.pubsub import HathorEvents, PubSubManager |
30 | 31 | from hathor.transaction import BaseTransaction, Block, Transaction |
31 | | -from hathor.transaction.exceptions import RewardLocked |
| 32 | +from hathor.transaction.exceptions import InvalidInputData, RewardLocked, TooManySigOps |
32 | 33 | from hathor.util import not_none |
| 34 | +from hathor.verification.verification_params import VerificationParams |
33 | 35 |
|
34 | 36 | if TYPE_CHECKING: |
35 | 37 | from hathor.conf.settings import HathorSettings |
@@ -431,6 +433,9 @@ def _feature_activation_rules(self, tx: Transaction, new_best_block: Block) -> b |
431 | 433 | case Feature.COUNT_CHECKDATASIG_OP: |
432 | 434 | if not self._checkdatasig_count_rule(tx): |
433 | 435 | return False |
| 436 | + case Feature.OPCODES_V2: |
| 437 | + if not self._opcodes_v2_activation_rule(tx, new_best_block): |
| 438 | + return False |
434 | 439 | case ( |
435 | 440 | Feature.INCREASE_MAX_MERKLE_PATH_LENGTH |
436 | 441 | | Feature.NOP_FEATURE_1 |
@@ -491,8 +496,41 @@ def _checkdatasig_count_rule(self, tx: Transaction) -> bool: |
491 | 496 | # a fail and the tx will be removed from the mempool. |
492 | 497 | try: |
493 | 498 | VertexVerifier._verify_sigops_output(settings=self._settings, vertex=tx, enable_checkdatasig_count=True) |
494 | | - except Exception: |
| 499 | + except Exception as e: |
| 500 | + if not isinstance(e, TooManySigOps): |
| 501 | + self.log.exception('unexpected exception in mempool-reverification') |
| 502 | + return False |
| 503 | + return True |
| 504 | + |
| 505 | + def _opcodes_v2_activation_rule(self, tx: Transaction, new_best_block: Block) -> bool: |
| 506 | + """Check whether a tx became invalid because of the opcodes V2 feature.""" |
| 507 | + from hathor.verification.nano_header_verifier import NanoHeaderVerifier |
| 508 | + from hathor.verification.transaction_verifier import TransactionVerifier |
| 509 | + |
| 510 | + # We check all txs regardless of the feature state, because this rule |
| 511 | + # already prohibited mempool txs before the block feature activation. |
| 512 | + |
| 513 | + params = VerificationParams.default_for_mempool(best_block=new_best_block) |
| 514 | + |
| 515 | + # Any exception in the inputs verification will be considered |
| 516 | + # a fail and the tx will be removed from the mempool. |
| 517 | + try: |
| 518 | + TransactionVerifier._verify_inputs(self._settings, tx, params, skip_script=False) |
| 519 | + except Exception as e: |
| 520 | + if not isinstance(e, InvalidInputData): |
| 521 | + self.log.exception('unexpected exception in mempool-reverification') |
495 | 522 | return False |
| 523 | + |
| 524 | + # Any exception in the nc_signature verification will be considered |
| 525 | + # a fail and the tx will be removed from the mempool. |
| 526 | + if tx.is_nano_contract(): |
| 527 | + try: |
| 528 | + NanoHeaderVerifier._verify_nc_signature(self._settings, tx, params) |
| 529 | + except Exception as e: |
| 530 | + if not isinstance(e, NCInvalidSignature): |
| 531 | + self.log.exception('unexpected exception in mempool-reverification') |
| 532 | + return False |
| 533 | + |
496 | 534 | return True |
497 | 535 |
|
498 | 536 |
|
|
0 commit comments