|
5 | 5 | from web3.types import BlockData |
6 | 6 |
|
7 | 7 | import variables |
| 8 | +from blockchain.executor import Executor |
8 | 9 | from blockchain.typings import Web3 |
9 | 10 | from cryptography.verify_signature import compute_vs |
10 | 11 | from metrics.metrics import UNEXPECTED_EXCEPTIONS |
|
20 | 21 | logger = logging.getLogger(__name__) |
21 | 22 |
|
22 | 23 |
|
23 | | -class UnvetterBot: |
| 24 | +def run_unvetter(w3: Web3): |
| 25 | + unvetter = UnvetterBot(w3) |
| 26 | + e = Executor( |
| 27 | + w3, |
| 28 | + unvetter.execute, |
| 29 | + 1, |
| 30 | + variables.MAX_CYCLE_LIFETIME_IN_SECONDS, |
| 31 | + ) |
| 32 | + logger.info({'msg': 'Execute unvetter as daemon.'}) |
| 33 | + e.execute_as_daemon() |
| 34 | + |
24 | 35 |
|
25 | | - fully_initialized = False |
| 36 | + |
| 37 | +class UnvetterBot: |
| 38 | + message_storage: MessageStorage |
26 | 39 |
|
27 | 40 | def __init__(self, w3: Web3): |
28 | 41 | self.w3 = w3 |
29 | 42 |
|
30 | | - if self.w3.lido.deposit_security_module.__class__.__name__ == 'DepositSecurityModuleContractV2': |
31 | | - self.finalize_init() |
32 | | - fully_initialized = True |
| 43 | + def prepare_transport_bus(self): |
| 44 | + if self.message_storage: |
| 45 | + return |
33 | 46 |
|
34 | | - def finalize_init(self): |
35 | 47 | transports = [] |
36 | 48 |
|
37 | 49 | if TransportType.RABBIT in variables.MESSAGE_TRANSPORTS: |
@@ -62,12 +74,11 @@ def finalize_init(self): |
62 | 74 | ) |
63 | 75 |
|
64 | 76 | def execute(self, block: BlockData) -> bool: |
65 | | - if not self.fully_initialized: |
66 | | - if self.w3.lido.deposit_security_module.__class__.__name__ == 'DepositSecurityModuleContractV2': |
67 | | - self.finalize_init() |
68 | | - self.fully_initialized = True |
69 | | - else: |
70 | | - return True |
| 77 | + if self.w3.lido.deposit_security_module.version() == 1: |
| 78 | + logger.warning({'msg': 'DSM version is not supported.'}) |
| 79 | + return True |
| 80 | + else: |
| 81 | + self.prepare_transport_bus() |
71 | 82 |
|
72 | 83 | messages = self.receive_unvet_messages() |
73 | 84 | logger.info({'msg': f'Received {len(messages)} unvet messages.'}) |
@@ -108,8 +119,7 @@ def _send_unvet_message(self, message: UnvetMessage) -> bool: |
108 | 119 |
|
109 | 120 | actual_nonce = self.w3.lido.staking_router.get_staking_module_nonce(module_id) |
110 | 121 |
|
111 | | - if message['nonce'] < actual_nonce: |
112 | | - self._clear_outdated_messages_for_module(module_id, actual_nonce) |
| 122 | + self._clear_outdated_messages_for_module(module_id, actual_nonce) |
113 | 123 |
|
114 | 124 | unvet_tx = self.w3.lido.deposit_security_module.unvet_signing_keys( |
115 | 125 | message['blockNumber'], |
|
0 commit comments