Skip to content

Commit

Permalink
refactor(verification): remove VertexVerifier from TransactionVerifier
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Nov 27, 2023
1 parent 21a6883 commit b3974c0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 83 deletions.
3 changes: 2 additions & 1 deletion hathor/transaction/resources/create_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def _verify_unsigned_skip_pow(self, tx: Transaction) -> None:
verifiers = self.manager.verification_service.verifiers
verifiers.tx.verify_number_of_inputs(tx)
verifiers.vertex.verify_number_of_outputs(tx)
verifiers.tx.verify_outputs(tx)
verifiers.vertex.verify_outputs(tx)
verifiers.tx.verify_output_token_indexes(tx)
verifiers.vertex.verify_sigops_output(tx)
verifiers.tx.verify_sigops_input(tx)
# need to run verify_inputs first to check if all inputs exist
Expand Down
17 changes: 4 additions & 13 deletions hathor/verification/transaction_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,15 @@
from hathor.transaction.transaction import TokenInfo
from hathor.transaction.util import get_deposit_amount, get_withdraw_amount
from hathor.types import TokenUid, VertexId
from hathor.verification.vertex_verifier import VertexVerifier

cpu = get_cpu_profiler()


class TransactionVerifier:
__slots__ = ('_settings', '_vertex_verifier', '_daa')

def __init__(
self,
*,
settings: HathorSettings,
vertex_verifier: VertexVerifier,
daa: DifficultyAdjustmentAlgorithm,
) -> None:
__slots__ = ('_settings', '_daa')

def __init__(self, *, settings: HathorSettings, daa: DifficultyAdjustmentAlgorithm) -> None:
self._settings = settings
self._vertex_verifier = vertex_verifier
self._daa = daa

def verify_parents_basic(self, tx: Transaction) -> None:
Expand Down Expand Up @@ -177,12 +169,11 @@ def verify_number_of_inputs(self, tx: Transaction) -> None:
if not tx.is_genesis:
raise NoInputError('Transaction must have at least one input')

def verify_outputs(self, tx: Transaction) -> None:
def verify_output_token_indexes(self, tx: Transaction) -> None:
"""Verify outputs reference an existing token uid in the tokens list
:raises InvalidToken: output references non existent token uid
"""
self._vertex_verifier.verify_outputs(tx)
for output in tx.outputs:
# check index is valid
if output.get_token_index() > len(tx.tokens):
Expand Down
3 changes: 2 additions & 1 deletion hathor/verification/verification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def _verify_without_storage_tx(self, tx: Transaction) -> None:
"""
self.verifiers.vertex.verify_pow(tx)
self.verifiers.tx.verify_number_of_inputs(tx)
self.verifiers.tx.verify_outputs(tx)
self.verifiers.vertex.verify_outputs(tx)
self.verifiers.tx.verify_output_token_indexes(tx)
self.verifiers.vertex.verify_sigops_output(tx)

def _verify_without_storage_token_creation_tx(self, tx: TokenCreationTransaction) -> None:
Expand Down
2 changes: 1 addition & 1 deletion hathor/verification/vertex_verifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create(
"""
block_verifier = BlockVerifier(settings=settings, daa=daa, feature_service=feature_service)
merge_mined_block_verifier = MergeMinedBlockVerifier()
tx_verifier = TransactionVerifier(settings=settings, vertex_verifier=vertex_verifier, daa=daa)
tx_verifier = TransactionVerifier(settings=settings, daa=daa)
token_creation_tx_verifier = TokenCreationTransactionVerifier(settings=settings)

return VertexVerifiers(
Expand Down
3 changes: 2 additions & 1 deletion tests/tx/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ def _test_txout_script_limit(self, offset):
_output = TxOutput(value, script)

tx = Transaction(inputs=[_input], outputs=[_output], storage=self.tx_storage)
self._verifiers.tx.verify_outputs(tx)
self._verifiers.vertex.verify_outputs(tx)
self._verifiers.tx.verify_output_token_indexes(tx)

def test_txout_script_limit_exceeded(self):
with self.assertRaises(InvalidOutputScriptSize):
Expand Down
Loading

0 comments on commit b3974c0

Please sign in to comment.