Skip to content

Commit 42b4d01

Browse files
committed
refactor(e2e): enhance assertions logs with aggregator name
1 parent 0b21674 commit 42b4d01

File tree

5 files changed

+48
-36
lines changed

5 files changed

+48
-36
lines changed

mithril-test-lab/mithril-end-to-end/src/assertions/check.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub async fn assert_node_producing_mithril_stake_distribution(
6060
fetch_last_mithril_stake_distribution_hash(url.clone()).await
6161
}) {
6262
AttemptResult::Ok(hash) => {
63-
info!("Aggregator produced a mithril stake distribution"; "hash" => &hash);
63+
info!("Aggregator produced a mithril stake distribution"; "hash" => &hash, "aggregator" => &aggregator.name());
6464
Ok(hash)
6565
}
6666
AttemptResult::Err(error) => Err(error),
@@ -112,7 +112,7 @@ pub async fn assert_signer_is_signing_mithril_stake_distribution(
112112
fetch_mithril_stake_distribution_message(url.clone(), expected_epoch_min).await
113113
}) {
114114
AttemptResult::Ok(stake_distribution) => {
115-
info!("Signer signed a mithril stake distribution"; "certificate_hash" => &stake_distribution.certificate_hash);
115+
info!("Signer signed a mithril stake distribution"; "certificate_hash" => &stake_distribution.certificate_hash, "aggregator" => &aggregator.name());
116116
Ok(stake_distribution.certificate_hash)
117117
}
118118
AttemptResult::Err(error) => Err(error),
@@ -146,7 +146,7 @@ pub async fn assert_node_producing_snapshot(aggregator: &Aggregator) -> StdResul
146146
fetch_last_snapshot_digest(url.clone()).await
147147
}) {
148148
AttemptResult::Ok(digest) => {
149-
info!("Aggregator produced a snapshot"; "digest" => &digest);
149+
info!("Aggregator produced a snapshot"; "digest" => &digest, "aggregator" => &aggregator.name());
150150
Ok(digest)
151151
}
152152
AttemptResult::Err(error) => Err(error),
@@ -189,7 +189,7 @@ pub async fn assert_signer_is_signing_snapshot(
189189
fetch_snapshot_message(url.clone(), expected_epoch_min).await
190190
}) {
191191
AttemptResult::Ok(snapshot) => {
192-
info!("Signer signed a snapshot"; "certificate_hash" => &snapshot.certificate_hash);
192+
info!("Signer signed a snapshot"; "certificate_hash" => &snapshot.certificate_hash, "aggregator" => &aggregator.name());
193193
Ok(snapshot.certificate_hash)
194194
}
195195
AttemptResult::Err(error) => {
@@ -223,7 +223,7 @@ pub async fn assert_node_producing_cardano_database_snapshot(
223223
fetch_last_cardano_database_snapshot_hash(url.clone()).await
224224
}) {
225225
AttemptResult::Ok(hash) => {
226-
info!("Aggregator produced a Cardano database snapshot"; "hash" => &hash);
226+
info!("Aggregator produced a Cardano database snapshot"; "hash" => &hash, "aggregator" => &aggregator.name());
227227
Ok(hash)
228228
}
229229
AttemptResult::Err(error) => Err(error),
@@ -268,7 +268,7 @@ pub async fn assert_signer_is_signing_cardano_database_snapshot(
268268
fetch_cardano_database_snapshot_message(url.clone(), expected_epoch_min).await
269269
}) {
270270
AttemptResult::Ok(snapshot) => {
271-
info!("Signer signed a snapshot"; "certificate_hash" => &snapshot.certificate_hash);
271+
info!("Signer signed a snapshot"; "certificate_hash" => &snapshot.certificate_hash, "aggregator" => &aggregator.name());
272272
Ok(snapshot.certificate_hash)
273273
}
274274
AttemptResult::Err(error) => Err(error),
@@ -310,7 +310,7 @@ pub async fn assert_node_producing_cardano_database_digests_map(
310310
fetch_cardano_database_digests_map(url.clone()).await
311311
}) {
312312
AttemptResult::Ok(cardano_database_digests_map) => {
313-
info!("Aggregator produced a Cardano database digests map"; "total_digests" => &cardano_database_digests_map.len());
313+
info!("Aggregator produced a Cardano database digests map"; "total_digests" => &cardano_database_digests_map.len(), "aggregator" => &aggregator.name());
314314
Ok(cardano_database_digests_map)
315315
}
316316
AttemptResult::Err(error) => Err(error),
@@ -329,7 +329,7 @@ pub async fn assert_node_producing_cardano_transactions(
329329
aggregator: &Aggregator,
330330
) -> StdResult<String> {
331331
let url = format!("{}/artifact/cardano-transactions", aggregator.endpoint());
332-
info!("Waiting for the aggregator to produce a Cardano transactions artifact"; "aggregator" => &aggregator.name());
332+
info!("Waiting for the aggregator to produce a Cardano transactions artifact"; "aggregator" => &aggregator.name(), "aggregator" => &aggregator.name());
333333

334334
async fn fetch_last_cardano_transaction_snapshot_hash(
335335
url: String,
@@ -348,7 +348,7 @@ pub async fn assert_node_producing_cardano_transactions(
348348
fetch_last_cardano_transaction_snapshot_hash(url.clone()).await
349349
}) {
350350
AttemptResult::Ok(hash) => {
351-
info!("Aggregator produced a Cardano transactions artifact"; "hash" => &hash);
351+
info!("Aggregator produced a Cardano transactions artifact"; "hash" => &hash, "aggregator" => &aggregator.name());
352352
Ok(hash)
353353
}
354354
AttemptResult::Err(error) => Err(error),
@@ -394,7 +394,7 @@ pub async fn assert_signer_is_signing_cardano_transactions(
394394
fetch_cardano_transaction_snapshot_message(url.clone(), expected_epoch_min).await
395395
}) {
396396
AttemptResult::Ok(artifact) => {
397-
info!("Signer signed a Cardano transactions artifact"; "certificate_hash" => &artifact.certificate_hash);
397+
info!("Signer signed a Cardano transactions artifact"; "certificate_hash" => &artifact.certificate_hash, "aggregator" => &aggregator.name());
398398
Ok(artifact.certificate_hash)
399399
}
400400
AttemptResult::Err(error) => Err(error),
@@ -438,7 +438,7 @@ pub async fn assert_node_producing_cardano_stake_distribution(
438438
fetch_last_cardano_stake_distribution_message(url.clone()).await
439439
}) {
440440
AttemptResult::Ok((hash, epoch)) => {
441-
info!("Aggregator produced a Cardano stake distribution"; "hash" => &hash, "epoch" => #?epoch);
441+
info!("Aggregator produced a Cardano stake distribution"; "hash" => &hash, "epoch" => #?epoch, "aggregator" => &aggregator.name());
442442
Ok((hash, epoch))
443443
}
444444
AttemptResult::Err(error) => Err(error),
@@ -490,7 +490,7 @@ pub async fn assert_signer_is_signing_cardano_stake_distribution(
490490
fetch_cardano_stake_distribution_message(url.clone(), expected_epoch_min).await
491491
}) {
492492
AttemptResult::Ok(cardano_stake_distribution) => {
493-
info!("Signer signed a Cardano stake distribution"; "certificate_hash" => &cardano_stake_distribution.certificate_hash);
493+
info!("Signer signed a Cardano stake distribution"; "certificate_hash" => &cardano_stake_distribution.certificate_hash, "aggregator" => &aggregator.name());
494494
Ok(cardano_stake_distribution.certificate_hash)
495495
}
496496
AttemptResult::Err(error) => Err(error),
@@ -529,7 +529,8 @@ pub async fn assert_is_creating_certificate_with_enough_signers(
529529
info!(
530530
"Certificate is signed by expected number of signers: {} >= {} ",
531531
certificate.metadata.signers.len(),
532-
total_signers_expected
532+
total_signers_expected ;
533+
"aggregator" => &aggregator.name()
533534
);
534535
Ok(())
535536
} else {

mithril-test-lab/mithril-end-to-end/src/assertions/exec.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mithril_common::StdResult;
66
use slog_scope::info;
77

88
pub async fn bootstrap_genesis_certificate(aggregator: &Aggregator) -> StdResult<()> {
9-
info!("Bootstrap genesis certificate");
9+
info!("Bootstrap genesis certificate"; "aggregator" => &aggregator.name());
1010

1111
// A slave aggregator needs to wait few cycles of the state machine to be able to bootstrap
1212
// This should be removed when the aggregator is able to synchronize its certificate chain from another aggregator
@@ -17,11 +17,11 @@ pub async fn bootstrap_genesis_certificate(aggregator: &Aggregator) -> StdResult
1717
.await;
1818
}
1919

20-
info!("> stopping aggregator");
20+
info!("> stopping aggregator"; "aggregator" => &aggregator.name());
2121
aggregator.stop().await?;
22-
info!("> bootstrapping genesis using signers registered two epochs ago...");
22+
info!("> bootstrapping genesis using signers registered two epochs ago..."; "aggregator" => &aggregator.name());
2323
aggregator.bootstrap_genesis().await?;
24-
info!("> done, restarting aggregator");
24+
info!("> done, restarting aggregator"; "aggregator" => &aggregator.name());
2525
aggregator.serve().await?;
2626

2727
Ok(())
@@ -33,17 +33,17 @@ pub async fn register_era_marker(
3333
mithril_era: &str,
3434
era_epoch: Epoch,
3535
) -> StdResult<()> {
36-
info!("Register '{mithril_era}' era marker");
36+
info!("Register '{mithril_era}' era marker"; "aggregator" => &aggregator.name());
3737

38-
info!("> generating era marker tx datum...");
38+
info!("> generating era marker tx datum..."; "aggregator" => &aggregator.name());
3939
let tx_datum_file_path = devnet
4040
.artifacts_dir()
4141
.join(PathBuf::from("era-tx-datum.txt".to_string()));
4242
aggregator
4343
.era_generate_tx_datum(&tx_datum_file_path, mithril_era, era_epoch)
4444
.await?;
4545

46-
info!("> writing '{mithril_era}' era marker on the Cardano chain...");
46+
info!("> writing '{mithril_era}' era marker on the Cardano chain..."; "aggregator" => &aggregator.name());
4747
devnet.write_era_marker(&tx_datum_file_path).await?;
4848

4949
Ok(())
@@ -66,7 +66,7 @@ pub async fn transfer_funds(devnet: &Devnet) -> StdResult<()> {
6666
}
6767

6868
pub async fn update_protocol_parameters(aggregator: &Aggregator) -> StdResult<()> {
69-
info!("Update protocol parameters");
69+
info!("Update protocol parameters"; "aggregator" => &aggregator.name());
7070

7171
info!("> stopping aggregator");
7272
aggregator.stop().await?;
@@ -76,13 +76,12 @@ pub async fn update_protocol_parameters(aggregator: &Aggregator) -> StdResult<()
7676
phi_f: 0.80,
7777
};
7878
info!(
79-
"> updating protocol parameters to {:?}...",
80-
protocol_parameters_new
79+
"> updating protocol parameters to {protocol_parameters_new:?}..."; "aggregator" => &aggregator.name()
8180
);
8281
aggregator
8382
.set_protocol_parameters(&protocol_parameters_new)
8483
.await;
85-
info!("> done, restarting aggregator");
84+
info!("> done, restarting aggregator"; "aggregator" => &aggregator.name());
8685
aggregator.serve().await?;
8786

8887
Ok(())

mithril-test-lab/mithril-end-to-end/src/assertions/wait.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
use crate::{attempt, utils::AttemptResult};
1+
use crate::{attempt, utils::AttemptResult, Aggregator};
22
use anyhow::{anyhow, Context};
33
use mithril_common::{
44
chain_observer::ChainObserver, digesters::ImmutableFile, entities::Epoch,
55
messages::EpochSettingsMessage, StdResult,
66
};
77
use reqwest::StatusCode;
88
use slog_scope::{info, warn};
9-
use std::{path::Path, sync::Arc, time::Duration};
9+
use std::{sync::Arc, time::Duration};
1010

11-
pub async fn wait_for_enough_immutable(db_directory: &Path) -> StdResult<()> {
12-
info!("Waiting that enough immutable have been written in the devnet");
11+
pub async fn wait_for_enough_immutable(aggregator: &Aggregator) -> StdResult<()> {
12+
info!("Waiting that enough immutable have been written in the devnet"; "aggregator" => aggregator.name());
1313

14+
let db_directory = aggregator.db_directory();
1415
match attempt!(24, Duration::from_secs(5), {
1516
match ImmutableFile::list_completed_in_dir(db_directory)
1617
.with_context(|| {
@@ -34,9 +35,10 @@ pub async fn wait_for_enough_immutable(db_directory: &Path) -> StdResult<()> {
3435
}
3536
}
3637

37-
pub async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> StdResult<EpochSettingsMessage> {
38+
pub async fn wait_for_epoch_settings(aggregator: &Aggregator) -> StdResult<EpochSettingsMessage> {
39+
let aggregator_endpoint = aggregator.endpoint();
3840
let url = format!("{aggregator_endpoint}/epoch-settings");
39-
info!("Waiting for the aggregator to expose epoch settings");
41+
info!("Waiting for the aggregator to expose epoch settings"; "aggregator" => aggregator.name());
4042

4143
match attempt!(20, Duration::from_millis(1000), {
4244
match reqwest::get(url.clone()).await {
@@ -52,7 +54,8 @@ pub async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> StdResult<Epo
5254
s if s.is_server_error() => {
5355
warn!(
5456
"Server error while waiting for the Aggregator, http code: {}",
55-
s
57+
s;
58+
"aggregator" => aggregator.name()
5659
);
5760
Ok(None)
5861
}
@@ -70,12 +73,14 @@ pub async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> StdResult<Epo
7073
}
7174

7275
pub async fn wait_for_target_epoch(
76+
aggregator: &Aggregator,
7377
chain_observer: Arc<dyn ChainObserver>,
7478
target_epoch: Epoch,
7579
wait_reason: String,
7680
) -> StdResult<()> {
7781
info!(
7882
"Waiting for the cardano network to be at the target epoch: {}", wait_reason;
83+
"aggregator" => aggregator.name(),
7984
"target_epoch" => ?target_epoch
8085
);
8186

@@ -96,7 +101,7 @@ pub async fn wait_for_target_epoch(
96101
}
97102
}) {
98103
AttemptResult::Ok(_) => {
99-
info!("Target epoch reached!"; "target_epoch" => ?target_epoch);
104+
info!("Target epoch reached!"; "aggregator" => aggregator.name(), "target_epoch" => ?target_epoch);
100105
Ok(())
101106
}
102107
AttemptResult::Err(error) => Err(error),

mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Spec {
9999
chain_observer: Arc<dyn ChainObserver>,
100100
infrastructure: &MithrilInfrastructure,
101101
) -> StdResult<()> {
102-
assertions::wait_for_enough_immutable(aggregator.db_directory()).await?;
102+
assertions::wait_for_enough_immutable(aggregator).await?;
103103
let start_epoch = chain_observer
104104
.get_current_epoch()
105105
.await?
@@ -108,18 +108,20 @@ impl Spec {
108108
// Wait 4 epochs after start epoch for the aggregator to be able to bootstrap a genesis certificate
109109
let mut target_epoch = start_epoch + 4;
110110
assertions::wait_for_target_epoch(
111+
aggregator,
111112
chain_observer.clone(),
112113
target_epoch,
113114
"minimal epoch for the aggregator to be able to bootstrap genesis certificate"
114115
.to_string(),
115116
)
116117
.await?;
117118
assertions::bootstrap_genesis_certificate(aggregator).await?;
118-
assertions::wait_for_epoch_settings(&aggregator.endpoint()).await?;
119+
assertions::wait_for_epoch_settings(aggregator).await?;
119120

120121
// Wait 2 epochs before changing stake distribution, so that we use at least one original stake distribution
121122
target_epoch += 2;
122123
assertions::wait_for_target_epoch(
124+
aggregator,
123125
chain_observer.clone(),
124126
target_epoch,
125127
"epoch after which the stake distribution will change".to_string(),
@@ -135,6 +137,7 @@ impl Spec {
135137
// Wait 2 epochs before changing protocol parameters
136138
target_epoch += 2;
137139
assertions::wait_for_target_epoch(
140+
aggregator,
138141
chain_observer.clone(),
139142
target_epoch,
140143
"epoch after which the protocol parameters will change".to_string(),
@@ -145,6 +148,7 @@ impl Spec {
145148
// Wait 6 epochs after protocol parameters update, so that we make sure that we use new protocol parameters as well as new stake distribution a few times
146149
target_epoch += 6;
147150
assertions::wait_for_target_epoch(
151+
aggregator,
148152
chain_observer.clone(),
149153
target_epoch,
150154
"epoch after which the certificate chain will be long enough to catch most common troubles with stake distribution and protocol parameters".to_string(),
@@ -162,6 +166,7 @@ impl Spec {
162166
infrastructure.register_switch_to_next_era(next_era).await?;
163167
target_epoch += 5;
164168
assertions::wait_for_target_epoch(
169+
aggregator,
165170
chain_observer.clone(),
166171
target_epoch,
167172
"epoch after which the era switch will have triggered".to_string(),
@@ -173,6 +178,7 @@ impl Spec {
173178
assertions::bootstrap_genesis_certificate(aggregator).await?;
174179
target_epoch += 5;
175180
assertions::wait_for_target_epoch(
181+
aggregator,
176182
chain_observer.clone(),
177183
target_epoch,
178184
"epoch after which the re-genesis on era switch will be completed".to_string(),

mithril-test-lab/mithril-end-to-end/src/run_only.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl RunOnly {
5858
chain_observer: Arc<dyn ChainObserver>,
5959
infrastructure: &MithrilInfrastructure,
6060
) -> StdResult<()> {
61-
assertions::wait_for_enough_immutable(aggregator.db_directory()).await?;
61+
assertions::wait_for_enough_immutable(aggregator).await?;
6262
let start_epoch = chain_observer
6363
.get_current_epoch()
6464
.await?
@@ -67,14 +67,15 @@ impl RunOnly {
6767
// Wait 3 epochs after start epoch for the aggregator to be able to bootstrap a genesis certificate
6868
let target_epoch = start_epoch + 3;
6969
assertions::wait_for_target_epoch(
70+
aggregator,
7071
chain_observer,
7172
target_epoch,
7273
"minimal epoch for the aggregator to be able to bootstrap genesis certificate"
7374
.to_string(),
7475
)
7576
.await?;
7677
assertions::bootstrap_genesis_certificate(aggregator).await?;
77-
assertions::wait_for_epoch_settings(&aggregator.endpoint()).await?;
78+
assertions::wait_for_epoch_settings(aggregator).await?;
7879

7980
if aggregator.is_first() {
8081
// Transfer some funds on the devnet to have some Cardano transactions to sign

0 commit comments

Comments
 (0)