11from collections .abc import Sequence
2+ from typing import TYPE_CHECKING
23
34from py_flare_common .fsp .messaging import parse_generic_tx
45from py_flare_common .fsp .messaging .byte_parser import ByteParser
1617from .signature import Signature
1718from .types import ValidateFn
1819
20+ if TYPE_CHECKING :
21+ from observer .validation .validation import ExtractedEntityVotingRound
22+
1923
2024# NOTE:(matej) stupid type cast
2125def _check_type (f : ValidateFn [FtsoSubmit1 , FtsoSubmit2 , SubmitSignatures ]):
@@ -26,7 +30,7 @@ def _check_type(f: ValidateFn[FtsoSubmit1, FtsoSubmit2, SubmitSignatures]):
2630def check_submit_1 (
2731 submit_1 : WParsedPayload [FtsoSubmit1 ] | None ,
2832 message_builder : MessageBuilder ,
29- extracted_round ,
33+ extracted_round : "ExtractedEntityVotingRound[FtsoSubmit1, FtsoSubmit2, SubmitSignatures]" , # noqa: E501
3034 ** _ ,
3135) -> Sequence [Message ]:
3236 issues = []
@@ -37,9 +41,7 @@ def check_submit_1(
3741 # we perform the following checks:
3842 # - submit1 doesn't exist -> error
3943 # - submit1 exists but commit hash length isn't 32 -> error
40- # NOTE: (miha) The protocol accepts the latest submit1 sent in the correct
41- # time interval. We check if there are any submit1 sent before or after interval
42- # and send a warning for those before and a warning for those after
44+ # - submit1 exists but was sent before or after submission window -> warning
4345
4446 if submit_1 is None :
4547 issues .append (mb .build (MessageLevel .ERROR , "no submit1 transaction" ))
@@ -53,26 +55,27 @@ def check_submit_1(
5355 f"submit1 commit hash unexpeted length ({ hash_len } ), expected 32" ,
5456 )
5557 )
56- if len (extracted_round .submit_1_before ) > 0 :
57- issues .append (
58- mb .build (
59- MessageLevel .WARNING ,
60- (
61- "submit 1 transactions sent before correct time interval: "
62- f"{ extracted_round .submit_2_before } "
63- ),
64- )
58+
59+ if early := extracted_round .submit_1 .early :
60+ tx_hashes = ", " .join ([tx .wtx_data .hash .to_0x_hex () for tx in early ])
61+ issues .append (
62+ mb .build (
63+ MessageLevel .WARNING ,
64+ (
65+ "submit1 transactions sent before correct time interval: "
66+ f"{ tx_hashes } "
67+ ),
6568 )
66- if len (extracted_round .submit_1_after ) > 0 :
67- issues .append (
68- mb .build (
69- MessageLevel .WARNING ,
70- (
71- "submit 1 transactions sent after correct time interval: "
72- f"{ extracted_round .submit_2_after } "
73- ),
74- )
69+ )
70+
71+ if late := extracted_round .submit_1 .late :
72+ tx_hashes = ", " .join ([tx .wtx_data .hash .to_0x_hex () for tx in late ])
73+ issues .append (
74+ mb .build (
75+ MessageLevel .WARNING ,
76+ (f"submit1 transactions sent after correct time interval: { tx_hashes } " ),
7577 )
78+ )
7679
7780 return issues
7881
@@ -84,7 +87,7 @@ def check_submit_2(
8487 message_builder : MessageBuilder ,
8588 entity : Entity ,
8689 round : VotingRound ,
87- extracted_round ,
90+ extracted_round : "ExtractedEntityVotingRound[FtsoSubmit1, FtsoSubmit2, SubmitSignatures]" , # noqa: E501
8891 ** _ ,
8992) -> Sequence [Message ]:
9093 issues = []
@@ -101,9 +104,7 @@ def check_submit_2(
101104 # - ftso values have null values -> warning
102105 # - ftso value have values that aren't in range of minimal conditions -> warning
103106 # - ftso values have incorrect length -> warning
104- # NOTE: (miha) The protocol accepts the latest submit2 sent in the correct
105- # time interval. We check if there are any submit2 sent before or after interval
106- # and send a warning for those before and a warning for those after
107+ # - submit2 exists but was sent before or after submission window -> warning
107108
108109 if submit_1 is None and submit_2 is None :
109110 issues .append (mb .build (MessageLevel .ERROR , "no submit2 transaction" ))
@@ -181,26 +182,26 @@ def check_submit_2(
181182 # )
182183 # )
183184
184- if len ( extracted_round .submit_2_before ) > 0 :
185- issues . append (
186- mb . build (
187- MessageLevel . WARNING ,
188- (
189- "submit 2 transactions sent before correct time interval: "
190- f" { extracted_round . submit_2_before } "
191- ),
192- )
185+ if early := extracted_round .submit_2 . early :
186+ tx_hashes = ", " . join ([ tx . wtx_data . hash . to_0x_hex () for tx in early ])
187+ issues . append (
188+ mb . build (
189+ MessageLevel . WARNING ,
190+ (
191+ "submit2 transactions sent before correct time interval: "
192+ f" { tx_hashes } "
193+ ),
193194 )
194- if len (extracted_round .submit_2_after ) > 0 :
195- issues .append (
196- mb .build (
197- MessageLevel .WARNING ,
198- (
199- "submit 2 transactions sent after correct time interval: "
200- f"{ extracted_round .submit_2_after } "
201- ),
202- )
195+ )
196+
197+ if late := extracted_round .submit_2 .late :
198+ tx_hashes = ", " .join ([tx .wtx_data .hash .to_0x_hex () for tx in late ])
199+ issues .append (
200+ mb .build (
201+ MessageLevel .WARNING ,
202+ (f"submit2 transactions sent after correct time interval: { tx_hashes } " ),
203203 )
204+ )
204205
205206 return issues
206207
@@ -212,7 +213,7 @@ def check_submit_signatures(
212213 message_builder : MessageBuilder ,
213214 entity : Entity ,
214215 round : VotingRound ,
215- extracted_round ,
216+ extracted_round : "ExtractedEntityVotingRound[FtsoSubmit1, FtsoSubmit2, SubmitSignatures]" , # noqa: E501
216217 ** _ ,
217218) -> Sequence [Message ]:
218219 issues = []
@@ -227,9 +228,7 @@ def check_submit_signatures(
227228 # - submitSignatures doesn't exist -> error
228229 # - submitSignature was sent after the deadline -> warning
229230 # - signature doesn't match finalization -> error
230- # NOTE: (miha) The protocol accepts the latest submitSignatures sent in the correct
231- # time interval. We check if there are any submitSignatures sent before or after
232- # this interval and send a warning for those before and a warning for those after
231+ # - submitSignature exists but was sent before or after submission window -> warning
233232
234233 if submit_signatures is None :
235234 issues .append (
@@ -250,27 +249,6 @@ def check_submit_signatures(
250249 )
251250 )
252251
253- if len (extracted_round .submit_signatures_before ) > 0 :
254- issues .append (
255- mb .build (
256- MessageLevel .WARNING ,
257- (
258- "submit signatures transactions sent before correct time "
259- f"interval: { extracted_round .submit_signatures_before } "
260- ),
261- )
262- )
263- if len (extracted_round .submit_signatures_after ) > 0 :
264- issues .append (
265- mb .build (
266- MessageLevel .WARNING ,
267- (
268- "submit signatures transactions sent after correct time "
269- f"interval: { extracted_round .submit_signatures_after } "
270- ),
271- )
272- )
273-
274252 if submit_signatures is not None and finalization is not None :
275253 s = Signature .from_parsed_signature (
276254 submit_signatures .parsed_payload .payload .signature
@@ -287,4 +265,16 @@ def check_submit_signatures(
287265 ),
288266 )
289267
268+ if early := extracted_round .submit_signatures .early :
269+ tx_hashes = ", " .join ([tx .wtx_data .hash .to_0x_hex () for tx in early ])
270+ issues .append (
271+ mb .build (
272+ MessageLevel .WARNING ,
273+ (
274+ "submit signatures transactions sent before correct time "
275+ f"interval: { tx_hashes } "
276+ ),
277+ )
278+ )
279+
290280 return issues
0 commit comments