-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.py
96 lines (64 loc) · 1.84 KB
/
events.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from dataclasses import dataclass, field
from typing import Union, Optional, Dict, List
from remerkleable.basic import uint64
from eth2spec.phase0 import spec
from random import randint
MESSAGE_TYPE = Union[
spec.Attestation, spec.SignedAggregateAndProof, spec.SignedBeaconBlock
]
"""
For keeping determinism, every Event has gained a field `priority`.
Certain messages do need to have certain priorities:
Messages which directly lead to the creation of other messages do need to have a higher priority than
those who don't:
NextSlot/AttestationOpportunity/AggregationOpportunity > Block > Attestation/AggregatedAttestation
"""
@dataclass
class Event:
time: uint64
priority: int
def __lt__(self, other):
return (
self.priority < other.priority
if self.time == other.time
else self.time < other.time
)
@dataclass
class ValidatorInitializationEvent(Event):
pass
@dataclass
class BeaconNodeInfo(Event):
beacon_nodes: Dict[int, List[int]]
@dataclass
class NextSlotEvent(Event):
slot: int
@dataclass
class LatestVoteOpportunity(Event):
slot: int
@dataclass
class AggregateOpportunity(Event):
slot: int
@dataclass
class TargetedEvent(Event):
toidx: Optional[int]
@dataclass
class ProduceStatisticsEvent(TargetedEvent):
print_event: bool = field(default=False)
@dataclass
class ProduceGraphEvent(TargetedEvent):
show: bool
@dataclass
class MessageEvent(Event):
message: bytes
message_type: str
fromidx: int
toidx: Optional[int]
custom_latency: Optional[int] = field(default=None)
delayed: Optional[int] = field(default=None)
marker: Optional[int] = field(default_factory=lambda: randint(0, 4294967296))
@dataclass
class RequestDeposit(Event):
stake: int
@dataclass
class SimulationEndEvent(Event):
message: Optional[str] = None