-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaemon.py
More file actions
74 lines (61 loc) · 2.36 KB
/
daemon.py
File metadata and controls
74 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""A daemon to run tests on settlements.
An infinite loop is started which listens to CoW Protocol trade events. If such an event happens,
the correstonding transaction hash is added to the queue of the individual tests.
If a settlement failes a test, an error level message is logged.
"""
# pylint: disable=logging-fstring-interpolation
import time
from typing import Optional
from src.apis.web3api import Web3API
from src.apis.orderbookapi import OrderbookAPI
from src.monitoring_tests.solver_competition_surplus_test import (
SolverCompetitionSurplusTest,
)
from src.monitoring_tests.mev_blocker_kickbacks_test import (
MEVBlockerRefundsMonitoringTest,
)
from src.monitoring_tests.high_score_test import (
HighScoreTest,
)
from src.monitoring_tests.price_sensitivity_test import PriceSensitivityTest
from src.constants import SLEEP_TIME_IN_SEC, CHAIN_ID_TO_NAME
def main() -> None:
"""
daemon function that runs as highlighted in docstring.
"""
web3_api = Web3API()
chain_id = web3_api.get_chain_id()
chain_name = CHAIN_ID_TO_NAME[chain_id]
orderbook_api = OrderbookAPI(chain_name)
# initialize tests
tests = [
SolverCompetitionSurplusTest(orderbook_api),
HighScoreTest(orderbook_api),
PriceSensitivityTest(orderbook_api),
]
# special case for mainnet as MEV Blocker only exists on mainnet
if chain_name == "mainnet":
tests.append(MEVBlockerRefundsMonitoringTest(web3_api))
start_block: Optional[int] = None
web3_api.logger.debug("Start infinite loop")
while True:
time.sleep(SLEEP_TIME_IN_SEC)
if start_block is None:
start_block = web3_api.get_current_block_number()
continue
end_block = web3_api.get_current_block_number()
if end_block is None:
continue
tx_hashes = web3_api.get_tx_hashes_by_block(start_block, end_block)
if not tx_hashes:
continue
web3_api.logger.debug(f"{len(tx_hashes)} hashes found: {tx_hashes}")
for test in tests:
test.add_hashes_to_queue(tx_hashes)
web3_api.logger.debug(f"Running test ({test}) for hashes {test.tx_hashes}.")
test.run_queue()
web3_api.logger.debug(f"Test ({test}) completed.")
start_block = end_block + 1
if __name__ == "__main__":
# sleep time can be set here in seconds
main()