Skip to content

Commit 85cdda4

Browse files
committed
[fix] hyperledger-iroha#1232: Introduce startup time benchmark
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
1 parent c3adf25 commit 85cdda4

11 files changed

Lines changed: 80 additions & 35 deletions

File tree

benchmark_blockstore/blocks.data

53.9 MB
Binary file not shown.

benchmark_blockstore/blocks.hashes

4.81 KB
Binary file not shown.

benchmark_blockstore/blocks.index

2.41 KB
Binary file not shown.

cli/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ impl Iroha {
291291
genesis_network: genesis,
292292
block_count,
293293
});
294+
295+
if config.exit_after_init {
296+
iroha_logger::error!("Exiting after init due to configuration");
297+
return Err(eyre!("Exiting after init due to configuration"));
298+
}
294299

295300
let block_sync = BlockSynchronizer::from_configuration(
296301
&config.block_sync,

config/iroha_test_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"payload": "282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB831C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"
66
},
77
"DISABLE_PANIC_TERMINAL_COLORS": false,
8+
"EXIT_AFTER_INIT": false,
89
"KURA": {
910
"INIT_MODE": "strict",
1011
"BLOCK_STORE_PATH": "./storage",

config/src/iroha.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ view! {
2222
pub private_key: PrivateKey,
2323
/// Disable coloring of the backtrace and error report on panic
2424
pub disable_panic_terminal_colors: bool,
25+
/// Exit after initialization for startup time testing
26+
pub exit_after_init: bool,
2527
/// `Kura` configuration
2628
#[config(inner)]
2729
pub kura: Box<kura::Configuration>,
@@ -69,6 +71,7 @@ impl Default for ConfigurationProxy {
6971
public_key: None,
7072
private_key: None,
7173
disable_panic_terminal_colors: Some(bool::default()),
74+
exit_after_init: Some(false),
7275
kura: Some(Box::default()),
7376
sumeragi: Some(Box::default()),
7477
torii: Some(Box::default()),
@@ -208,6 +211,7 @@ mod tests {
208211
fn arb_proxy()(
209212
(public_key, private_key) in arb_keys(),
210213
disable_panic_terminal_colors in prop::option::of(Just(true)),
214+
exit_after_init in prop::option::of(Just(true)),
211215
kura in prop::option::of(kura::tests::arb_proxy().prop_map(Box::new)),
212216
sumeragi in (prop::option::of(sumeragi::tests::arb_proxy().prop_map(Box::new))),
213217
torii in (prop::option::of(torii::tests::arb_proxy().prop_map(Box::new))),
@@ -221,8 +225,8 @@ mod tests {
221225
snapshot in prop::option::of(snapshot::tests::arb_proxy().prop_map(Box::new)),
222226
live_query_store in prop::option::of(live_query_store::tests::arb_proxy()),
223227
) -> ConfigurationProxy {
224-
ConfigurationProxy { public_key, private_key, disable_panic_terminal_colors, kura, sumeragi, torii, block_sync, queue,
225-
logger, genesis, wsv, network, telemetry, snapshot, live_query_store }
228+
ConfigurationProxy { public_key, private_key, disable_panic_terminal_colors, exit_after_init, kura, sumeragi, torii, block_sync,
229+
queue, logger, genesis, wsv, network, telemetry, snapshot, live_query_store }
226230
}
227231
}
228232

configs/peer/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"PUBLIC_KEY": null,
33
"PRIVATE_KEY": null,
44
"DISABLE_PANIC_TERMINAL_COLORS": false,
5+
"EXIT_AFTER_INIT": false,
56
"KURA": {
67
"INIT_MODE": "strict",
78
"BLOCK_STORE_PATH": "./storage",

core/src/sumeragi/main_loop.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,7 @@ pub(crate) fn run(
841841
sumeragi
842842
.transaction_cache
843843
// Checking if transactions are in the blockchain is costly
844-
.retain(|tx| {
845-
let expired = sumeragi.queue.is_expired(tx);
846-
if expired {
847-
debug!(?tx, "Transaction expired")
848-
}
849-
expired
850-
});
844+
.retain(|tx| !sumeragi.queue.is_expired(tx));
851845

852846
let mut expired_transactions = Vec::new();
853847
sumeragi.queue.get_transactions_for_block(

core/src/sumeragi/mod.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,24 @@ impl SumeragiHandle {
251251
)
252252
});
253253

254-
let current_topology = match wsv.height() {
255-
0 => {
256-
assert!(!configuration.trusted_peers.peers.is_empty());
257-
Topology::new(configuration.trusted_peers.peers.clone())
258-
}
259-
height => {
260-
let block_ref = kura.get_block_by_height(height).expect(
261-
"Sumeragi could not load block that was reported as present. \
262-
Please check that the block storage was not disconnected.",
263-
);
264-
Topology::recreate_topology(
265-
&block_ref,
266-
0,
267-
wsv.peers_ids().iter().cloned().collect(),
268-
)
269-
}
254+
let mut current_topology = {
255+
assert!(!configuration.trusted_peers.peers.is_empty());
256+
Topology::new(configuration.trusted_peers.peers.clone())
270257
};
271258

272259
let block_iter_except_last =
273260
(&mut blocks_iter).take(block_count.saturating_sub(skip_block_count + 1));
274261
for block in block_iter_except_last {
262+
if wsv.height() == 0 {
263+
current_topology = Topology::new(block.payload().commit_topology.clone());
264+
wsv.world_mut().trusted_peers_ids = current_topology.ordered_peers.clone();
265+
}
266+
267+
let new_topology =
268+
Topology::recreate_topology(&block, 0, wsv.peers_ids().iter().cloned().collect());
269+
270+
current_topology.rotate_all_n(block.payload().header().view_change_index);
271+
275272
let block = ValidBlock::validate(Clone::clone(&block), &current_topology, &mut wsv)
276273
.expect("Kura blocks should be valid")
277274
.commit(&current_topology)
@@ -280,12 +277,26 @@ impl SumeragiHandle {
280277
"Block application in init should not fail. \
281278
Blocks loaded from kura assumed to be valid",
282279
);
280+
current_topology = new_topology;
283281
}
284282

285283
// finalized_wsv is one block behind
286284
let finalized_wsv = wsv.clone();
287285

288286
if let Some(latest_block) = blocks_iter.next() {
287+
if wsv.height() == 0 {
288+
current_topology = Topology::new(latest_block.payload().commit_topology.clone());
289+
wsv.world_mut().trusted_peers_ids = current_topology.ordered_peers.clone();
290+
}
291+
292+
let new_topology = Topology::recreate_topology(
293+
&latest_block,
294+
0,
295+
wsv.peers_ids().iter().cloned().collect(),
296+
);
297+
298+
current_topology.rotate_all_n(latest_block.payload().header().view_change_index);
299+
289300
let latest_block =
290301
ValidBlock::validate(Clone::clone(&latest_block), &current_topology, &mut wsv)
291302
.expect("Kura blocks should be valid")
@@ -295,6 +306,7 @@ impl SumeragiHandle {
295306
"Block application in init should not fail. \
296307
Blocks loaded from kura assumed to be valid",
297308
);
309+
current_topology = new_topology;
298310
}
299311

300312
info!("Sumeragi has finished loading blocks and setting up the WSV");

docs/source/references/config.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The following is the default configuration used by Iroha.
3333
"PUBLIC_KEY": null,
3434
"PRIVATE_KEY": null,
3535
"DISABLE_PANIC_TERMINAL_COLORS": false,
36+
"EXIT_AFTER_INIT": false,
3637
"KURA": {
3738
"INIT_MODE": "strict",
3839
"BLOCK_STORE_PATH": "./storage",
@@ -185,6 +186,16 @@ Has type `Option<bool>`[^1]. Can be configured via environment variable `IROHA_D
185186
false
186187
```
187188

189+
## `exit_after_init`
190+
191+
Exit after initialization for startup time testing
192+
193+
Has type `Option<bool>`[^1]. Can be configured via environment variable `IROHA_EXIT_AFTER_INIT`
194+
195+
```json
196+
false
197+
```
198+
188199
## `genesis`
189200

190201
`GenesisBlock` configuration

0 commit comments

Comments
 (0)