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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
use std::{
collections::HashMap,
fmt::{self, Display, Formatter},
};
use crate::{
components::small_network::GossipedAddress,
types::{
json_compatibility::ExecutionResult, Block, BlockHash, BlockHeader, Deploy, DeployHash,
DeployHeader, FinalizedBlock, Item, ProtoBlock,
},
utils::Source,
};
#[derive(Debug)]
#[must_use]
pub enum NetworkAnnouncement<I, P> {
MessageReceived {
sender: I,
payload: P,
},
GossipOurAddress(GossipedAddress),
NewPeer(I),
}
impl<I, P> Display for NetworkAnnouncement<I, P>
where
I: Display,
P: Display,
{
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
NetworkAnnouncement::MessageReceived { sender, payload } => {
write!(formatter, "received from {}: {}", sender, payload)
}
NetworkAnnouncement::GossipOurAddress(_) => write!(formatter, "gossip our address"),
NetworkAnnouncement::NewPeer(id) => {
write!(formatter, "new peer connection established to {}", id)
}
}
}
}
#[derive(Debug)]
#[must_use]
pub enum ApiServerAnnouncement {
DeployReceived {
deploy: Box<Deploy>,
},
}
impl Display for ApiServerAnnouncement {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
ApiServerAnnouncement::DeployReceived { deploy } => {
write!(formatter, "api server received {}", deploy.id())
}
}
}
}
#[derive(Debug)]
pub enum DeployAcceptorAnnouncement<I> {
AcceptedNewDeploy {
deploy: Box<Deploy>,
source: Source<I>,
},
InvalidDeploy {
deploy: Box<Deploy>,
source: Source<I>,
},
}
impl<I: Display> Display for DeployAcceptorAnnouncement<I> {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
DeployAcceptorAnnouncement::AcceptedNewDeploy { deploy, source } => write!(
formatter,
"accepted new deploy {} from {}",
deploy.id(),
source
),
DeployAcceptorAnnouncement::InvalidDeploy { deploy, source } => {
write!(formatter, "invalid deploy {} from {}", deploy.id(), source)
}
}
}
}
#[derive(Debug)]
pub enum ConsensusAnnouncement {
Proposed(ProtoBlock),
Finalized(Box<FinalizedBlock>),
Orphaned(ProtoBlock),
Handled(Box<BlockHeader>),
}
impl Display for ConsensusAnnouncement {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
ConsensusAnnouncement::Proposed(block) => {
write!(formatter, "proposed proto block {}", block)
}
ConsensusAnnouncement::Finalized(block) => {
write!(formatter, "finalized proto block {}", block)
}
ConsensusAnnouncement::Orphaned(block) => {
write!(formatter, "orphaned proto block {}", block)
}
ConsensusAnnouncement::Handled(block_header) => write!(
formatter,
"Linear chain block has been handled by consensus, height={}, hash={}",
block_header.height(),
block_header.hash()
),
}
}
}
#[derive(Debug)]
pub enum BlockExecutorAnnouncement {
LinearChainBlock {
block: Block,
execution_results: HashMap<DeployHash, (DeployHeader, ExecutionResult)>,
},
}
impl Display for BlockExecutorAnnouncement {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
BlockExecutorAnnouncement::LinearChainBlock { block, .. } => {
write!(f, "created linear chain block {}", block.hash())
}
}
}
}
#[derive(Debug)]
pub enum GossiperAnnouncement<T: Item> {
NewCompleteItem(T::Id),
}
impl<T: Item> Display for GossiperAnnouncement<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
GossiperAnnouncement::NewCompleteItem(item) => write!(f, "new complete item {}", item),
}
}
}
#[derive(Debug)]
pub enum LinearChainAnnouncement {
BlockAdded {
block_hash: BlockHash,
block_header: Box<BlockHeader>,
},
}
impl Display for LinearChainAnnouncement {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
LinearChainAnnouncement::BlockAdded { block_hash, .. } => {
write!(f, "block added {}", block_hash)
}
}
}
}