-
Notifications
You must be signed in to change notification settings - Fork 75
/
soft_only.rs
454 lines (403 loc) · 11.1 KB
/
soft_only.rs
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
use std::time::Duration;
use astria_conductor::{
config::CommitLevel,
Conductor,
Config,
};
use astria_core::generated::execution::v1alpha2::{
GetCommitmentStateRequest,
GetGenesisInfoRequest,
};
use futures::future::{
join,
join4,
};
use telemetry::metrics;
use tokio::time::timeout;
use crate::{
commitment_state,
genesis_info,
helpers::{
make_config,
mount_genesis,
spawn_conductor,
MockGrpc,
},
mount_abci_info,
mount_executed_block,
mount_get_commitment_state,
mount_get_filtered_sequencer_block,
mount_get_genesis_info,
mount_sequencer_genesis,
mount_update_commitment_state,
SEQUENCER_CHAIN_ID,
};
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn simple() {
let test_conductor = spawn_conductor(CommitLevel::SoftOnly).await;
mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 1,
celestia_block_variance: 10,
);
mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,
);
mount_sequencer_genesis!(test_conductor);
mount_abci_info!(
test_conductor,
latest_sequencer_height: 3,
);
mount_get_filtered_sequencer_block!(
test_conductor,
sequencer_height: 3,
);
let execute_block = mount_executed_block!(
test_conductor,
number: 2,
hash: [2; 64],
parent: [1; 64],
);
let update_commitment_state = mount_update_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 2,
hash: [2; 64],
parent: [1; 64],
),
base_celestia_height: 1,
);
timeout(
Duration::from_millis(1000),
join(
execute_block.wait_until_satisfied(),
update_commitment_state.wait_until_satisfied(),
),
)
.await
.expect(
"conductor should have executed the soft block and updated the soft commitment state \
within 1000ms",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn submits_two_heights_in_succession() {
let test_conductor = spawn_conductor(CommitLevel::SoftOnly).await;
mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 1,
celestia_block_variance: 10,
);
mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,
);
mount_sequencer_genesis!(test_conductor);
mount_abci_info!(
test_conductor,
latest_sequencer_height: 4,
);
mount_get_filtered_sequencer_block!(
test_conductor,
sequencer_height: 3,
);
mount_get_filtered_sequencer_block!(
test_conductor,
sequencer_height: 4,
);
let execute_block_number_2 = mount_executed_block!(
test_conductor,
mock_name: "first_execute",
number: 2,
hash: [2; 64],
parent: [1; 64],
);
let update_commitment_state_number_2 = mount_update_commitment_state!(
test_conductor,
mock_name: "first_update",
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 2,
hash: [2; 64],
parent: [1; 64],
),
base_celestia_height: 1,
);
let execute_block_number_3 = mount_executed_block!(
test_conductor,
mock_name: "second_execute",
number: 3,
hash: [3; 64],
parent: [2; 64],
);
let update_commitment_state_number_3 = mount_update_commitment_state!(
test_conductor,
mock_name: "second_update",
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 3,
hash: [3; 64],
parent: [2; 64],
),
base_celestia_height: 1,
);
timeout(
Duration::from_millis(1000),
join4(
execute_block_number_2.wait_until_satisfied(),
update_commitment_state_number_2.wait_until_satisfied(),
execute_block_number_3.wait_until_satisfied(),
update_commitment_state_number_3.wait_until_satisfied(),
),
)
.await
.expect(
"conductor should have executed the soft block and updated the soft commitment state \
within 1000ms",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn skips_already_executed_heights() {
let test_conductor = spawn_conductor(CommitLevel::SoftOnly).await;
mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 1,
celestia_block_variance: 10,
);
mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 5,
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,
);
mount_sequencer_genesis!(test_conductor);
mount_abci_info!(
test_conductor,
latest_sequencer_height: 7,
);
mount_get_filtered_sequencer_block!(
test_conductor,
sequencer_height: 7,
);
let execute_block = mount_executed_block!(
test_conductor,
number: 6,
hash: [2; 64],
parent: [1; 64],
);
let update_commitment_state = mount_update_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 6,
hash: [2; 64],
parent: [1; 64],
),
base_celestia_height: 1,
);
timeout(
Duration::from_millis(1000),
join(
execute_block.wait_until_satisfied(),
update_commitment_state.wait_until_satisfied(),
),
)
.await
.expect(
"conductor should have executed the soft block and updated the soft commitment state \
within 1000ms",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn requests_from_later_genesis_height() {
let test_conductor = spawn_conductor(CommitLevel::SoftOnly).await;
mount_get_genesis_info!(
test_conductor,
sequencer_genesis_block_height: 10,
celestia_block_variance: 10,
);
mount_get_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,
);
mount_sequencer_genesis!(test_conductor);
mount_abci_info!(
test_conductor,
latest_sequencer_height: 12,
);
mount_get_filtered_sequencer_block!(
test_conductor,
sequencer_height: 12,
);
let execute_block = mount_executed_block!(
test_conductor,
number: 2,
hash: [2; 64],
parent: [1; 64],
);
let update_commitment_state = mount_update_commitment_state!(
test_conductor,
firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 2,
hash: [2; 64],
parent: [1; 64],
),
base_celestia_height: 1
);
timeout(
Duration::from_millis(1000),
join(
execute_block.wait_until_satisfied(),
update_commitment_state.wait_until_satisfied(),
),
)
.await
.expect(
"conductor should have executed the soft block and updated the soft commitment state \
within 1000ms",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn exits_on_sequencer_chain_id_mismatch() {
use astria_grpc_mock::{
matcher,
response as GrpcResponse,
Mock as GrpcMock,
};
// We have to create our own test conductor and perform mounts manually because `TestConductor`
// implements the `Drop` trait, which disallows us from taking ownership of its tasks and
// awaiting their completion.
let mock_grpc = MockGrpc::spawn().await;
let mock_http = wiremock::MockServer::start().await;
let config = Config {
celestia_node_http_url: mock_http.uri(),
execution_rpc_url: format!("http://{}", mock_grpc.local_addr),
sequencer_cometbft_url: mock_http.uri(),
sequencer_grpc_url: format!("http://{}", mock_grpc.local_addr),
execution_commit_level: CommitLevel::SoftOnly,
..make_config()
};
let (metrics, _) = metrics::ConfigBuilder::new()
.set_global_recorder(false)
.build(&())
.unwrap();
let metrics = Box::leak(Box::new(metrics));
let conductor = {
let conductor = Conductor::new(config, metrics).unwrap();
conductor.spawn()
};
GrpcMock::for_rpc_given(
"get_genesis_info",
matcher::message_type::<GetGenesisInfoRequest>(),
)
.respond_with(GrpcResponse::constant_response(
genesis_info!(sequencer_genesis_block_height: 1,
celestia_block_variance: 10,),
))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;
GrpcMock::for_rpc_given(
"get_commitment_state",
matcher::message_type::<GetCommitmentStateRequest>(),
)
.respond_with(GrpcResponse::constant_response(commitment_state!(firm: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
soft: (
number: 1,
hash: [1; 64],
parent: [0; 64],
),
base_celestia_height: 1,)))
.expect(0..)
.mount(&mock_grpc.mock_server)
.await;
let bad_chain_id = "bad_chain_id";
mount_genesis(&mock_http, bad_chain_id).await;
let res = conductor.await;
match res {
Ok(Ok(())) => panic!("conductor should have exited with an error, no error received"),
Ok(Err(e)) => {
let mut source = e.source();
while source.is_some() {
let err = source.unwrap();
if err.to_string().contains(
format!(
"expected chain id `{SEQUENCER_CHAIN_ID}` does not match actual: \
`{bad_chain_id}`"
)
.as_str(),
) {
return;
}
source = err.source();
}
panic!("conductor did not exit with incorrect error: {e}")
}
Err(e) => panic!("conductor handle resulted in an error: {e}"),
}
}