@@ -37,9 +37,8 @@ async fn run_handover(
37
37
next : Vec < ( DecryptionKeyCell , SequencerConfig , CertifierConfig ) > ,
38
38
) {
39
39
const NEXT_COMMITTEE_DELAY : u64 = 15 ;
40
- const NUM_OF_BLOCKS : usize = 50 ;
40
+ const NUM_OF_BLOCKS_PER_EPOCH : usize = 50 ;
41
41
42
- let mut out1 = Vec :: new ( ) ;
43
42
let tasks = TaskTracker :: new ( ) ;
44
43
let ( bcast, _) = broadcast:: channel ( 500 ) ;
45
44
let finish = CancellationToken :: new ( ) ;
@@ -49,18 +48,19 @@ async fn run_handover(
49
48
let a2 = next[ 0 ] . 1 . sailfish_committee ( ) . clone ( ) ;
50
49
let c1 = a1. committee ( ) . id ( ) ;
51
50
let c2 = a2. committee ( ) . id ( ) ;
52
- let num = a1. committee ( ) . size ( ) ;
53
- let quorum = a1. committee ( ) . one_honest_threshold ( ) ;
54
-
55
51
let d2 = next[ 0 ] . 1 . decrypt_committee ( ) . clone ( ) ;
56
52
53
+ let num = a1. committee ( ) . size ( ) ;
54
+ let quorum = a1. committee ( ) . one_honest_threshold ( ) ;
57
55
let diff = a1. diff ( & a2) . count ( ) ;
56
+
58
57
assert ! ( diff > 0 ) ;
59
58
assert_ne ! ( c1, c2) ;
60
59
61
- // run committee 1:
60
+ let mut out1 = Vec :: new ( ) ;
61
+
62
+ // run committee 1 (current):
62
63
for ( _, seq_conf, cert_conf) in & curr {
63
- // Clone the configs so they are owned and can be moved into the async block
64
64
let seq_conf = seq_conf. clone ( ) ;
65
65
let cert_conf = cert_conf. clone ( ) ;
66
66
let ( tx, rx) = mpsc:: unbounded_channel ( ) ;
@@ -72,8 +72,8 @@ async fn run_handover(
72
72
tasks. spawn ( async move {
73
73
let mut s = start_sequencer_with_retry ( seq_conf) . await ;
74
74
let mut c = start_certifier_with_retry ( cert_conf) . await ;
75
- let mut r: Option < sailfish_types :: RoundNumber > = None ;
76
- let handle = c. handle ( ) ;
75
+ let mut r: Option < RoundNumber > = None ;
76
+ let c_handle = c. handle ( ) ;
77
77
78
78
loop {
79
79
select ! {
@@ -85,7 +85,7 @@ async fn run_handover(
85
85
Ok ( Cmd :: Bundle ( bundle) ) => {
86
86
s. add_bundles( once( bundle) ) ;
87
87
}
88
- Err ( err) => panic!( "Command channel error: {err}" )
88
+ Err ( err) => panic!( "command channel error: {err}" )
89
89
} ,
90
90
out = s. next( ) => match out {
91
91
Ok ( o) => {
@@ -97,7 +97,7 @@ async fn run_handover(
97
97
r = Some ( round) ;
98
98
let i = r2b. get( round) ;
99
99
let b = Block :: new( i, * round, hash( & transactions) ) ;
100
- handle . enqueue( b) . await . unwrap( )
100
+ c_handle . enqueue( b) . await . unwrap( )
101
101
}
102
102
Output :: UseCommittee ( round) => {
103
103
c. use_committee( round) . await . unwrap( ) ;
@@ -130,8 +130,7 @@ async fn run_handover(
130
130
key. read ( ) . await ;
131
131
}
132
132
133
- tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
134
-
133
+ // generate bundles
135
134
tasks. spawn ( {
136
135
let ( key, _, _) = & curr[ 0 ] ;
137
136
let key = key. clone ( ) ;
@@ -148,13 +147,16 @@ async fn run_handover(
148
147
}
149
148
} ) ;
150
149
150
+ // wait for the current to become active
151
+ tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
152
+
151
153
// inform about upcoming committee change
152
154
let t = ConsensusTime ( Timestamp :: now ( ) + NEXT_COMMITTEE_DELAY ) ;
153
155
bcast. send ( Cmd :: NextCommittee ( t, a2, d2. 1 ) ) . unwrap ( ) ;
154
156
155
157
let mut out2 = Vec :: new ( ) ;
156
158
157
- // run committee 2:
159
+ // run committee 2 (next) :
158
160
for ( _, seq_conf, cert_conf) in & next {
159
161
let ours = seq_conf. sign_keypair ( ) . public_key ( ) ;
160
162
@@ -176,7 +178,7 @@ async fn run_handover(
176
178
let mut s = start_sequencer_with_retry ( seq_conf) . await ;
177
179
let mut c = start_certifier_with_retry ( cert_conf) . await ;
178
180
let mut r: Option < sailfish_types:: RoundNumber > = None ;
179
- let handle = c. handle ( ) ;
181
+ let c_handle = c. handle ( ) ;
180
182
181
183
loop {
182
184
select ! {
@@ -188,7 +190,7 @@ async fn run_handover(
188
190
Ok ( Cmd :: Bundle ( bundle) ) => {
189
191
s. add_bundles( once( bundle) ) ;
190
192
}
191
- Err ( err) => panic!( "Command channel error: {err}" )
193
+ Err ( err) => panic!( "command channel error: {err}" )
192
194
} ,
193
195
out = s. next( ) => match out {
194
196
Ok ( o) => {
@@ -200,7 +202,7 @@ async fn run_handover(
200
202
r = Some ( round) ;
201
203
let i = r2b. get( round) ;
202
204
let b = Block :: new( i, * round, hash( & transactions) ) ;
203
- handle . enqueue( b) . await . unwrap( )
205
+ c_handle . enqueue( b) . await . unwrap( )
204
206
}
205
207
Output :: UseCommittee ( round) => {
206
208
c. use_committee( round) . await . unwrap( ) ;
@@ -230,7 +232,7 @@ async fn run_handover(
230
232
231
233
let mut map: HashMap < BlockInfo , usize > = HashMap :: new ( ) ;
232
234
233
- for b in 0 ..NUM_OF_BLOCKS {
235
+ for b in 0 ..NUM_OF_BLOCKS_PER_EPOCH {
234
236
map. clear ( ) ;
235
237
info ! ( block = %b) ;
236
238
for ( node, r) in & mut out1 {
@@ -247,7 +249,7 @@ async fn run_handover(
247
249
panic ! ( "outputs do not match" )
248
250
}
249
251
250
- for b in 0 ..NUM_OF_BLOCKS {
252
+ for b in 0 ..NUM_OF_BLOCKS_PER_EPOCH {
251
253
map. clear ( ) ;
252
254
info ! ( block = %b) ;
253
255
for ( node, r) in & mut out2 {
@@ -259,7 +261,7 @@ async fn run_handover(
259
261
. values ( )
260
262
. any ( |n| * n >= min ( diff, quorum. get ( ) ) && * n <= num. get ( ) )
261
263
{
262
- // votes only collected for new nodes
264
+ // votes only collected from new nodes in next
263
265
continue ;
264
266
}
265
267
for ( info, n) in map {
0 commit comments