Skip to content

Commit c81ce26

Browse files
jpraynaudAlenar
authored andcommitted
Trigger pending certificate with new immutable file
1 parent 33982e5 commit c81ce26

File tree

2 files changed

+70
-42
lines changed

2 files changed

+70
-42
lines changed

mithril-common/src/digesters/dummy_immutable_db_builder.rs

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ pub struct DummyImmutableDb {
2424
pub non_immutables_files: Vec<PathBuf>,
2525
}
2626

27+
impl DummyImmutableDb {
28+
/// Add an immutable chunk file and its primary & secondary to the dummy DB.
29+
pub fn add_immutable_file(&mut self) {
30+
let last_file_number = self.immutables_files.last().map(|f| f.number).unwrap_or(1);
31+
let mut new_files = write_immutable_trio(None, &self.dir, last_file_number + 1);
32+
33+
self.immutables_files.append(&mut new_files);
34+
}
35+
}
36+
2737
impl DummyImmutablesDbBuilder {
2838
/// [DummyImmutablesDbBuilder] factory, will create a folder with the given `dirname` in the
2939
/// system temp directory, if it exists already it will be cleaned.
@@ -73,21 +83,25 @@ impl DummyImmutablesDbBuilder {
7383
immutable_numbers.sort();
7484

7585
if self.append_uncompleted_trio {
76-
self.write_immutable_trio(match immutable_numbers.last() {
77-
None => 0,
78-
Some(last) => last + 1,
79-
});
86+
write_immutable_trio(
87+
self.file_size,
88+
&self.dir,
89+
match immutable_numbers.last() {
90+
None => 0,
91+
Some(last) => last + 1,
92+
},
93+
);
8094
}
8195

8296
for non_immutable in &self.non_immutables_to_write {
83-
non_immutables_files.push(self.write_dummy_file(non_immutable));
97+
non_immutables_files.push(write_dummy_file(self.file_size, &self.dir, non_immutable));
8498
}
8599

86100
DummyImmutableDb {
87101
dir: self.dir.clone(),
88102
immutables_files: immutable_numbers
89103
.into_iter()
90-
.flat_map(|ifn| self.write_immutable_trio(ifn))
104+
.flat_map(|ifn| write_immutable_trio(self.file_size, &self.dir, ifn))
91105
.collect::<Vec<_>>(),
92106
non_immutables_files,
93107
}
@@ -108,37 +122,41 @@ impl DummyImmutablesDbBuilder {
108122

109123
parent_dir
110124
}
125+
}
111126

112-
fn write_immutable_trio(&self, immutable: ImmutableFileNumber) -> Vec<ImmutableFile> {
113-
let mut result = vec![];
114-
for filename in [
115-
format!("{immutable:05}.chunk"),
116-
format!("{immutable:05}.primary"),
117-
format!("{immutable:05}.secondary"),
118-
] {
119-
let file = self.write_dummy_file(&filename);
120-
result.push(ImmutableFile {
121-
number: immutable.to_owned(),
122-
path: file,
123-
filename: filename.to_string(),
124-
});
125-
}
126-
result
127+
fn write_immutable_trio(
128+
optional_size: Option<u64>,
129+
dir: &Path,
130+
immutable: ImmutableFileNumber,
131+
) -> Vec<ImmutableFile> {
132+
let mut result = vec![];
133+
for filename in [
134+
format!("{immutable:05}.chunk"),
135+
format!("{immutable:05}.primary"),
136+
format!("{immutable:05}.secondary"),
137+
] {
138+
let file = write_dummy_file(optional_size, dir, &filename);
139+
result.push(ImmutableFile {
140+
number: immutable.to_owned(),
141+
path: file,
142+
filename: filename.to_string(),
143+
});
127144
}
145+
result
146+
}
128147

129-
/// Create a file with the given name in the given dir, write some text to it, and then
130-
/// return its path.
131-
fn write_dummy_file(&self, filename: &str) -> PathBuf {
132-
let file = self.dir.join(Path::new(filename));
133-
let mut source_file = File::create(&file).unwrap();
148+
/// Create a file with the given name in the given dir, write some text to it, and then
149+
/// return its path.
150+
fn write_dummy_file(optional_size: Option<u64>, dir: &Path, filename: &str) -> PathBuf {
151+
let file = dir.join(Path::new(filename));
152+
let mut source_file = File::create(&file).unwrap();
134153

135-
write!(source_file, "This is a test file named '{filename}'").unwrap();
154+
write!(source_file, "This is a test file named '{filename}'").unwrap();
136155

137-
if let Some(file_size) = self.file_size {
138-
writeln!(source_file).unwrap();
139-
source_file.set_len(file_size).unwrap();
140-
}
141-
142-
file
156+
if let Some(file_size) = optional_size {
157+
writeln!(source_file).unwrap();
158+
source_file.set_len(file_size).unwrap();
143159
}
160+
161+
file
144162
}

mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,9 @@ pub struct AggregatorParameters {
486486
}
487487

488488
impl AggregatorParameters {
489-
fn new(opts: &MainOpts) -> StdResult<Self> {
490-
// configure a dummy immutable db
491-
let immutable_db = DummyImmutablesDbBuilder::new("load-tester")
492-
.with_immutables(&[1, 2, 3])
493-
.append_immutable_trio()
494-
.build();
495-
489+
fn new(opts: &MainOpts, immutable_db_path: &Path) -> StdResult<Self> {
496490
let bft_node = BftNode {
497-
db_path: immutable_db.dir,
491+
db_path: immutable_db_path.to_path_buf(),
498492
socket_path: PathBuf::new(),
499493
};
500494
let tmp_dir = opts
@@ -644,11 +638,21 @@ async fn bootstrap_aggregator(
644638
Ok(aggregator)
645639
}
646640

641+
fn add_new_immutable_file(aggregator: &Aggregator) -> StdResult<()> {
642+
todo!()
643+
}
644+
647645
#[tokio::main(flavor = "multi_thread")]
648646
async fn main() -> StdResult<()> {
649647
let opts = MainOpts::parse();
648+
// configure a dummy immutable db
649+
let mut immutable_db = DummyImmutablesDbBuilder::new("load-tester")
650+
.with_immutables(&[1, 2, 3])
651+
.append_immutable_trio()
652+
.build();
653+
650654
let _logger_guard = init_logger(&opts);
651-
let args = AggregatorParameters::new(&opts)?;
655+
let args = AggregatorParameters::new(&opts, &immutable_db.dir)?;
652656
let mut current_epoch = Epoch(1);
653657
let protocol_parameters = ProtocolParameters::new(2422, 20973, 0.20);
654658
info!(">> Starting stress test with options: {opts:?}");
@@ -696,6 +700,12 @@ async fn main() -> StdResult<()> {
696700
info!(">> Wait for artifacts to be available...");
697701
wait_for_mithril_stake_distribution_artifacts(&aggregator, Duration::from_secs(30)).await?;
698702

703+
info!(">> Add new immutable file");
704+
immutable_db.add_immutable_file();
705+
706+
info!(">> Wait for pending certificate to be available");
707+
wait_for_pending_certificate(&aggregator, Duration::from_secs(30)).await?;
708+
699709
info!(">> All steps executed successfully, stopping all tasks...");
700710

701711
aggregator.stop().await.unwrap();

0 commit comments

Comments
 (0)