Skip to content

Commit accff6d

Browse files
authored
Merge branch 'main' into remove-pre-commit-hooks
2 parents 503c6a8 + 952db04 commit accff6d

File tree

11 files changed

+119
-114
lines changed

11 files changed

+119
-114
lines changed

src/catalyst-toolbox/catalyst-toolbox/src/vote_check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl CheckNode {
6464
}))
6565
.build();
6666

67-
let inner = JormungandrBootstrapper::default()
68-
.with_node_config(node_config)
67+
let inner = JormungandrBootstrapper::default_with_config(node_config)
6968
.passive()
7069
.with_block0_hash(Hash::from_str(&genesis_block_hash).unwrap())
7170
.with_jormungandr(jormungandr_bin.unwrap_or_else(|| PathBuf::from(JORMUNGANDR_APP)))

src/jormungandr/testing/jormungandr-automation/src/jormungandr/starter/params/builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ impl Default for JormungandrBootstrapper {
4545
}
4646

4747
impl JormungandrBootstrapper {
48+
//This function is meant to be used instead of JormungandrBootstrapper::default().with_node_config(node_config)
49+
//This is because the Default trait for JormungandrBootstrapper instanciates a NodeConfig struct that will be overwritten
50+
//by the NodeConfig passed by the .with_node_config() function. NodeConfig calls the function get_available_port()
51+
//that makes operations on an Atomic variable and "flags" some ports as being used, both operations that would
52+
//be better to not duplicate for performance and debbugging reasons.
53+
pub fn default_with_config(node_config: NodeConfig) -> Self {
54+
Self {
55+
node_config: Box::new(NodeConfigManager {
56+
node_config,
57+
file: None,
58+
}),
59+
genesis: Default::default(),
60+
secret: Default::default(),
61+
leadership_mode: LeadershipMode::Leader,
62+
jormungandr_app: None,
63+
verbose: true,
64+
rewards_history: false,
65+
}
66+
}
67+
4868
pub fn passive(mut self) -> Self {
4969
self.leadership_mode = LeadershipMode::Passive;
5070
self

src/jormungandr/testing/jormungandr-integration-tests/src/context.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ impl TestContext {
3030
}
3131

3232
pub fn start_node(&self, temp_dir: TempDir) -> Result<JormungandrProcess, StartupError> {
33-
let mut bootstrapper = JormungandrBootstrapper::default()
34-
.with_block0_configuration(self.block0_config.clone())
35-
.with_node_config(self.node_config.clone())
36-
.with_secret(self.secret_factory.clone());
33+
let mut bootstrapper =
34+
JormungandrBootstrapper::default_with_config(self.node_config.clone())
35+
.with_block0_configuration(self.block0_config.clone())
36+
.with_secret(self.secret_factory.clone());
3737
if self.reward_history {
3838
bootstrapper = bootstrapper.with_rewards_history();
3939
}
4040
bootstrapper.start(temp_dir)
4141
}
4242

4343
pub(crate) fn starter(&self, temp_dir: TempDir) -> Result<Starter, StartupError> {
44-
let mut bootstrapper = JormungandrBootstrapper::default()
45-
.with_block0_configuration(self.block0_config.clone())
46-
.with_node_config(self.node_config.clone())
47-
.with_secret(self.secret_factory.clone());
44+
let mut bootstrapper =
45+
JormungandrBootstrapper::default_with_config(self.node_config.clone())
46+
.with_block0_configuration(self.block0_config.clone())
47+
.with_secret(self.secret_factory.clone());
4848
if self.reward_history {
4949
bootstrapper = bootstrapper.with_rewards_history();
5050
}

src/jormungandr/testing/jormungandr-integration-tests/src/jormungandr/bft/start_node.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ pub fn test_jormungandr_passive_node_starts_successfully() {
2828
.build();
2929
let jormungandr_leader = test_context.start_node(leader_temp_dir).unwrap();
3030

31-
let jormungandr_passive = JormungandrBootstrapper::default()
32-
.passive()
33-
.with_block0_hash(test_context.block0_config().to_block_hash())
34-
.with_node_config(
35-
NodeConfigBuilder::default()
36-
.with_trusted_peers(vec![jormungandr_leader.to_trusted_peer()])
37-
.build(),
38-
)
39-
.start(passive_temp_dir)
40-
.unwrap();
31+
let jormungandr_passive = JormungandrBootstrapper::default_with_config(
32+
NodeConfigBuilder::default()
33+
.with_trusted_peers(vec![jormungandr_leader.to_trusted_peer()])
34+
.build(),
35+
)
36+
.passive()
37+
.with_block0_hash(test_context.block0_config().to_block_hash())
38+
.start(passive_temp_dir)
39+
.unwrap();
4140

4241
jormungandr_passive.assert_no_errors_in_log();
4342
jormungandr_leader.assert_no_errors_in_log();
@@ -49,18 +48,17 @@ pub fn test_jormungandr_passive_node_without_trusted_peers_fails_to_start() {
4948

5049
let block0 = Block0ConfigurationBuilder::minimal_setup().build();
5150

52-
JormungandrBootstrapper::default()
53-
.passive()
54-
.with_block0_hash(block0.to_block_hash())
55-
.with_node_config(
56-
NodeConfigBuilder::default()
57-
.with_trusted_peers(vec![])
58-
.build(),
59-
)
60-
.into_starter(temp_dir)
61-
.unwrap()
62-
.start_should_fail_with_message("no trusted peers specified")
63-
.unwrap();
51+
JormungandrBootstrapper::default_with_config(
52+
NodeConfigBuilder::default()
53+
.with_trusted_peers(vec![])
54+
.build(),
55+
)
56+
.passive()
57+
.with_block0_hash(block0.to_block_hash())
58+
.into_starter(temp_dir)
59+
.unwrap()
60+
.start_should_fail_with_message("no trusted peers specified")
61+
.unwrap();
6462
}
6563

6664
#[test]

src/jormungandr/testing/jormungandr-integration-tests/src/jormungandr/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ fn block0_with_incorrect_hash(consensus: ConsensusType) {
9797
.with_trusted_peers(vec![adversary.to_trusted_peer()])
9898
.build();
9999

100-
JormungandrBootstrapper::default()
100+
JormungandrBootstrapper::default_with_config(passive_params)
101101
.passive()
102102
.with_block0_hash(adversary.genesis_block_hash())
103-
.with_node_config(passive_params)
104103
.into_starter(passive_temp_dir)
105104
.unwrap()
106105
.start_with_fail_in_logs("failed to download block")

src/jormungandr/testing/jormungandr-integration-tests/src/jormungandr/mempool.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,18 @@ fn expired_fragment_should_be_rejected_by_passive_bft_node() {
513513

514514
let leader = context.start_node(leader_dir).unwrap();
515515

516-
let passive = JormungandrBootstrapper::default()
517-
.passive()
518-
.with_node_config(
519-
NodeConfigBuilder::default()
520-
.with_trusted_peers(vec![leader.to_trusted_peer()])
521-
.with_log_level("debug")
522-
.build(),
523-
)
524-
.with_block0_hash(context.block0_config().to_block_hash())
525-
.into_starter(passive_dir)
526-
.unwrap()
527-
.start()
528-
.unwrap();
516+
let passive = JormungandrBootstrapper::default_with_config(
517+
NodeConfigBuilder::default()
518+
.with_trusted_peers(vec![leader.to_trusted_peer()])
519+
.with_log_level("debug")
520+
.build(),
521+
)
522+
.passive()
523+
.with_block0_hash(context.block0_config().to_block_hash())
524+
.into_starter(passive_dir)
525+
.unwrap()
526+
.start()
527+
.unwrap();
529528

530529
let fragment_sender = FragmentSender::from_settings_with_setup(
531530
&passive.rest().settings().unwrap(),

src/jormungandr/testing/jormungandr-integration-tests/src/networking/testnet.rs

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -96,44 +96,39 @@ impl TestnetConfig {
9696
}
9797

9898
pub fn make_leader_config(&self, temp_dir: &TempDir) -> JormungandrParams {
99-
JormungandrBootstrapper::default()
100-
.with_block0_hash(self.block0_hash())
101-
.with_node_config(
102-
NodeConfigBuilder::default()
103-
.with_storage(temp_dir.child("storage").to_path_buf())
104-
.with_log(Log(LogEntry {
105-
format: "json".to_string(),
106-
level: "info".to_string(),
107-
output: LogOutput::File(temp_dir.child("leader.log").path().to_path_buf()),
108-
}))
109-
.with_trusted_peers(self.trusted_peers.clone())
110-
.with_public_address(format!(
111-
"/ip4/{}/tcp/{}",
112-
self.public_ip, self.public_port
113-
))
114-
.build(),
115-
)
116-
.build(temp_dir)
117-
.unwrap()
99+
JormungandrBootstrapper::default_with_config(
100+
NodeConfigBuilder::default()
101+
.with_storage(temp_dir.child("storage").to_path_buf())
102+
.with_log(Log(LogEntry {
103+
format: "json".to_string(),
104+
level: "info".to_string(),
105+
output: LogOutput::File(temp_dir.child("leader.log").path().to_path_buf()),
106+
}))
107+
.with_trusted_peers(self.trusted_peers.clone())
108+
.with_public_address(format!("/ip4/{}/tcp/{}", self.public_ip, self.public_port))
109+
.build(),
110+
)
111+
.with_block0_hash(self.block0_hash())
112+
.build(temp_dir)
113+
.unwrap()
118114
}
119115

120116
pub fn make_passive_config(&self, temp_dir: &TempDir) -> JormungandrParams {
121-
JormungandrBootstrapper::default()
122-
.passive()
123-
.with_block0_hash(self.block0_hash())
124-
.with_node_config(
125-
NodeConfigBuilder::default()
126-
.with_storage(temp_dir.child("storage").to_path_buf())
127-
.with_log(Log(LogEntry {
128-
format: "json".to_string(),
129-
level: "info".to_string(),
130-
output: LogOutput::File(temp_dir.child("passive.log").path().to_path_buf()),
131-
}))
132-
.with_trusted_peers(self.trusted_peers.clone())
133-
.build(),
134-
)
135-
.build(temp_dir)
136-
.unwrap()
117+
JormungandrBootstrapper::default_with_config(
118+
NodeConfigBuilder::default()
119+
.with_storage(temp_dir.child("storage").to_path_buf())
120+
.with_log(Log(LogEntry {
121+
format: "json".to_string(),
122+
level: "info".to_string(),
123+
output: LogOutput::File(temp_dir.child("passive.log").path().to_path_buf()),
124+
}))
125+
.with_trusted_peers(self.trusted_peers.clone())
126+
.build(),
127+
)
128+
.passive()
129+
.with_block0_hash(self.block0_hash())
130+
.build(temp_dir)
131+
.unwrap()
137132
}
138133

139134
pub fn make_passive_legacy_config(
@@ -213,15 +208,14 @@ fn bootstrap_current(testnet_config: TestnetConfig, network_alias: &str) {
213208
)
214209
.print();
215210

216-
let config = JormungandrBootstrapper::default()
217-
.with_block0_hash(testnet_config.block0_hash())
218-
.with_node_config(
219-
NodeConfigBuilder::default()
220-
.with_trusted_peers(vec![jormungandr_from_storage.to_trusted_peer()])
221-
.build(),
222-
)
223-
.build(&temp_dir)
224-
.unwrap();
211+
let config = JormungandrBootstrapper::default_with_config(
212+
NodeConfigBuilder::default()
213+
.with_trusted_peers(vec![jormungandr_from_storage.to_trusted_peer()])
214+
.build(),
215+
)
216+
.with_block0_hash(testnet_config.block0_hash())
217+
.build(&temp_dir)
218+
.unwrap();
225219

226220
let _jormungandr_from_local_trusted_peer = Starter::default()
227221
.config(config)
@@ -250,15 +244,14 @@ fn bootstrap_legacy(testnet_config: TestnetConfig, network_prefix: &str) {
250244
.start()
251245
.unwrap();
252246

253-
let config = JormungandrBootstrapper::default()
254-
.with_block0_hash(testnet_config.block0_hash())
255-
.with_node_config(
256-
NodeConfigBuilder::default()
257-
.with_trusted_peers(vec![legacy_jormungandr.to_trusted_peer()])
258-
.build(),
259-
)
260-
.build(&temp_dir)
261-
.unwrap();
247+
let config = JormungandrBootstrapper::default_with_config(
248+
NodeConfigBuilder::default()
249+
.with_trusted_peers(vec![legacy_jormungandr.to_trusted_peer()])
250+
.build(),
251+
)
252+
.with_block0_hash(testnet_config.block0_hash())
253+
.build(&temp_dir)
254+
.unwrap();
262255

263256
// bootstrap latest node from legacy node peer
264257
let new_jormungandr_from_local_trusted_peer = Starter::default()

src/jormungandr/testing/jormungandr-integration-tests/src/non_functional/bootstrap.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ pub fn bootstrap_from_100_mb_storage() {
4949
let temp_dir = jormungandr.steal_temp_dir().unwrap().try_into().unwrap();
5050
jormungandr.shutdown();
5151

52-
let mut jormungandr = JormungandrBootstrapper::default()
53-
.with_node_config(test_context.node_config())
52+
let mut jormungandr = JormungandrBootstrapper::default_with_config(test_context.node_config())
5453
.with_block0_configuration(test_context.block0_config())
5554
.into_starter(temp_dir)
5655
.unwrap()
@@ -66,8 +65,7 @@ pub fn bootstrap_from_100_mb_storage() {
6665
let temp_dir = jormungandr.steal_temp_dir().unwrap().try_into().unwrap();
6766
jormungandr.stop();
6867

69-
let _jormungandr = JormungandrBootstrapper::default()
70-
.with_node_config(test_context.node_config())
68+
let _jormungandr = JormungandrBootstrapper::default_with_config(test_context.node_config())
7169
.with_block0_configuration(test_context.block0_config())
7270
.into_starter(temp_dir)
7371
.unwrap()

src/jormungandr/testing/jormungandr-integration-tests/src/non_functional/compatibility.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ fn test_upgrade_and_downgrade_from_legacy_to_master(version: Version, temp_dir:
150150
.unwrap();
151151
// upgrade node to newest
152152

153-
let jormungandr = JormungandrBootstrapper::default()
154-
.with_block0_configuration(legacy_test_context.block0_config())
155-
.with_node_config(NodeConfigBuilder::default().with_storage(storage).build())
156-
.with_secret(legacy_test_context.test_context.secret_factory.clone())
157-
.start(temp_dir)
158-
.unwrap();
153+
let jormungandr = JormungandrBootstrapper::default_with_config(
154+
NodeConfigBuilder::default().with_storage(storage).build(),
155+
)
156+
.with_block0_configuration(legacy_test_context.block0_config())
157+
.with_secret(legacy_test_context.test_context.secret_factory.clone())
158+
.start(temp_dir)
159+
.unwrap();
159160

160161
fragment_sender
161162
.send_transactions_round_trip(10, &mut sender, &mut receiver, &jormungandr, 100.into())

src/jormungandr/testing/jormungandr-integration-tests/src/startup.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ pub fn start_stake_pool(
297297
.with_certs(initial_certs.into_iter().map(Initial::Cert).collect())
298298
.build();
299299

300-
JormungandrBootstrapper::default()
300+
JormungandrBootstrapper::default_with_config(node_config_builder.build())
301301
.with_block0_configuration(block0_config)
302302
.with_secret(secret)
303-
.with_node_config(node_config_builder.build())
304303
.into_starter(temp_dir)?
305304
.start()
306305
.map(|process| (process, stake_pools))

0 commit comments

Comments
 (0)