Skip to content

Commit

Permalink
[refactor] #2664: Introduce new wsv
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara committed Mar 20, 2024
1 parent 8bc754e commit 26ac620
Show file tree
Hide file tree
Showing 56 changed files with 4,206 additions and 3,120 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ parity-scale-codec = { version = "3.6.5", default-features = false }
json5 = "0.4.1"
toml = "0.8.8"

storage = { git = "https://github.com/Erigara/storage.git", rev = "232843aab94770089ecbffe8c8e8cb24c9cedb62" }

[workspace.lints]
rustdoc.private_doc_tests = "deny"

Expand Down
33 changes: 19 additions & 14 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use iroha_core::{
handler::ThreadHandler,
kiso::KisoHandle,
kura::Kura,
prelude::{World, WorldStateView},
query::store::LiveQueryStore,
queue::Queue,
smartcontracts::isi::Registrable as _,
snapshot::{
try_read_snapshot, SnapshotMaker, SnapshotMakerHandle, TryReadError as TryReadSnapshotError,
},
state::{State, World},
sumeragi::{SumeragiHandle, SumeragiStartArgs},
IrohaNetwork,
};
Expand Down Expand Up @@ -61,6 +61,8 @@ pub struct Iroha {
pub torii: Option<Torii>,
/// Snapshot service. Might be not started depending on the config.
pub snapshot_maker: Option<SnapshotMakerHandle>,
/// State of blockchain
pub state: Arc<State>,
/// Thread handlers
thread_handlers: Vec<ThreadHandler>,

Expand Down Expand Up @@ -218,36 +220,36 @@ impl Iroha {

let block_count = kura.init()?;

let wsv = match try_read_snapshot(
let state = match try_read_snapshot(
&config.snapshot.store_dir,
&kura,
live_query_store_handle.clone(),
block_count,
) {
Ok(wsv) => {
Ok(state) => {
iroha_logger::info!(
at_height = wsv.height(),
"Successfully loaded WSV from a snapshot"
at_height = state.view().height(),
"Successfully loaded state from a snapshot"
);
Some(wsv)
Some(state)
}
Err(TryReadSnapshotError::NotFound) => {
iroha_logger::info!("Didn't find a snapshot of WSV, creating an empty one");
iroha_logger::info!("Didn't find a snapshot of state, creating an empty one");
None
}
Err(error) => {
iroha_logger::warn!(%error, "Failed to load WSV from a snapshot, creating an empty one");
iroha_logger::warn!(%error, "Failed to load state from a snapshot, creating an empty one");
None
}
}.unwrap_or_else(|| {
WorldStateView::from_config(
State::from_config(
config.chain_wide,
world,
Arc::clone(&kura),
live_query_store_handle.clone(),
)

});
let state = Arc::new(state);

let queue = Arc::new(Queue::from_config(config.queue));
match Self::start_telemetry(&logger, &config).await? {
Expand All @@ -261,7 +263,7 @@ impl Iroha {
sumeragi_config: config.sumeragi.clone(),
common_config: config.common.clone(),
events_sender: events_sender.clone(),
wsv,
state: Arc::clone(&state),
queue: Arc::clone(&queue),
kura: Arc::clone(&kura),
network: network.clone(),
Expand All @@ -279,6 +281,7 @@ impl Iroha {
Arc::clone(&kura),
config.common.peer_id(),
network.clone(),
Arc::clone(&state),
)
.start();

Expand All @@ -287,7 +290,7 @@ impl Iroha {
config.transaction_gossiper,
network.clone(),
Arc::clone(&queue),
sumeragi.clone(),
Arc::clone(&state),
)
.start();

Expand All @@ -307,8 +310,8 @@ impl Iroha {
}
.start();

let snapshot_maker =
SnapshotMaker::from_config(&config.snapshot, &sumeragi).map(SnapshotMaker::start);
let snapshot_maker = SnapshotMaker::from_config(&config.snapshot, Arc::clone(&state))
.map(SnapshotMaker::start);

let kiso = KisoHandle::new(config.clone());

Expand All @@ -322,6 +325,7 @@ impl Iroha {
sumeragi.clone(),
live_query_store_handle,
Arc::clone(&kura),
Arc::clone(&state),
);

Self::spawn_config_updates_broadcasting(kiso.clone(), logger.clone());
Expand All @@ -338,6 +342,7 @@ impl Iroha {
kura,
torii,
snapshot_maker,
state,
thread_handlers: vec![kura_thread_handler],
#[cfg(debug_assertions)]
freeze_status,
Expand Down
10 changes: 5 additions & 5 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ impl Config {
}

let blocks_out_of_measure = 2 + MeasurerUnit::PREPARATION_BLOCKS_NUMBER * self.peers;
let blocks_wsv = network
let state_view = network
.genesis
.iroha
.as_ref()
.expect("Must be some")
.sumeragi
.wsv_clone();
let mut blocks = blocks_wsv.all_blocks().skip(blocks_out_of_measure as usize);
.state
.view();
let mut blocks = state_view.all_blocks().skip(blocks_out_of_measure as usize);
let (txs_accepted, txs_rejected) = (0..self.blocks)
.map(|_| {
let block = blocks
.next()
.expect("The block is not yet in WSV. Need more sleep?");
.expect("The block is not yet in state. Need more sleep?");
(
block.transactions().filter(|tx| tx.error.is_none()).count(),
block.transactions().filter(|tx| tx.error.is_some()).count(),
Expand Down
Binary file modified configs/swarm/executor.wasm
100755 → 100644
Binary file not shown.
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ iroha_telemetry = { workspace = true }
iroha_primitives = { workspace = true }
iroha_genesis = { workspace = true }
iroha_wasm_codec = { workspace = true }
storage = { workspace = true, features = ["serde"] }

async-trait = { workspace = true }
dashmap = { workspace = true }
Expand Down
50 changes: 27 additions & 23 deletions core/benches/blocks/apply_blocks.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use eyre::Result;
use iroha_core::{block::CommittedBlock, prelude::*};
use iroha_core::{block::CommittedBlock, prelude::*, state::State};
use iroha_data_model::prelude::*;

#[path = "./common.rs"]
mod common;

use common::*;

pub struct WsvApplyBlocks {
wsv: WorldStateView,
pub struct StateApplyBlocks {
state: State,
blocks: Vec<CommittedBlock>,
}

impl WsvApplyBlocks {
/// Create [`WorldStateView`] and blocks for benchmarking
impl StateApplyBlocks {
/// Create [`State`] and blocks for benchmarking
///
/// # Errors
/// - Failed to parse [`AccountId`]
Expand All @@ -25,28 +25,36 @@ impl WsvApplyBlocks {
let assets_per_domain = 1000;
let account_id: AccountId = "alice@wonderland".parse()?;
let key_pair = KeyPair::random();
let wsv = build_wsv(rt, &account_id, &key_pair);
let state = build_state(rt, &account_id, &key_pair);

let nth = 100;
let instructions = [
populate_wsv(domains, accounts_per_domain, assets_per_domain, &account_id),
populate_state(domains, accounts_per_domain, assets_per_domain, &account_id),
delete_every_nth(domains, accounts_per_domain, assets_per_domain, nth),
restore_every_nth(domains, accounts_per_domain, assets_per_domain, nth),
];

let blocks = {
// Clone wsv because it will be changed during creation of block
let mut wsv = wsv.clone();
// Create empty state because it will be changed during creation of block
let state = build_state(rt, &account_id, &key_pair);
instructions
.into_iter()
.map(|instructions| {
let block = create_block(&mut wsv, instructions, account_id.clone(), &key_pair);
wsv.apply_without_execution(&block).map(|()| block)
.map(|instructions| -> Result<_> {
let mut state_block = state.block(false);
let block = create_block(
&mut state_block,
instructions,
account_id.clone(),
&key_pair,
);
state_block.apply_without_execution(&block)?;
state_block.commit();
Ok(block)
})
.collect::<Result<Vec<_>, _>>()?
};

Ok(Self { wsv, blocks })
Ok(Self { state, blocks })
}

/// Run benchmark body.
Expand All @@ -56,17 +64,13 @@ impl WsvApplyBlocks {
/// - Failed to apply block
///
/// # Panics
/// If wsv isn't one block ahead of finalized wsv.
pub fn measure(Self { wsv, blocks }: &Self) -> Result<()> {
let mut finalized_wsv = wsv.clone();
let mut wsv = finalized_wsv.clone();

assert_eq!(wsv.height(), 0);
/// If state height isn't updated after applying block
pub fn measure(Self { state, blocks }: &Self) -> Result<()> {
for (block, i) in blocks.iter().zip(1..) {
finalized_wsv = wsv.clone();
wsv.apply(block)?;
assert_eq!(wsv.height(), i);
assert_eq!(wsv.height(), finalized_wsv.height() + 1);
let mut state_block = state.block(false);
state_block.apply(block)?;
assert_eq!(state_block.height(), i);
state_block.commit();
}

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions core/benches/blocks/apply_blocks_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mod apply_blocks;

use apply_blocks::WsvApplyBlocks;
use apply_blocks::StateApplyBlocks;
use criterion::{criterion_group, criterion_main, Criterion};

fn apply_blocks(c: &mut Criterion) {
Expand All @@ -14,15 +14,15 @@ fn apply_blocks(c: &mut Criterion) {
group.significance_level(0.1).sample_size(10);
group.bench_function("apply_blocks", |b| {
b.iter_batched_ref(
|| WsvApplyBlocks::setup(rt.handle()).expect("Failed to setup benchmark"),
|| StateApplyBlocks::setup(rt.handle()).expect("Failed to setup benchmark"),
|bench| {
WsvApplyBlocks::measure(bench).expect("Failed to execute benchmark");
StateApplyBlocks::measure(bench).expect("Failed to execute benchmark");
},
criterion::BatchSize::SmallInput,
);
});
group.finish();
}

criterion_group!(wsv, apply_blocks);
criterion_main!(wsv);
criterion_group!(state, apply_blocks);
criterion_main!(state);
6 changes: 3 additions & 3 deletions core/benches/blocks/apply_blocks_oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

mod apply_blocks;

use apply_blocks::WsvApplyBlocks;
use apply_blocks::StateApplyBlocks;

fn main() {
let rt = tokio::runtime::Builder::new_multi_thread()
Expand All @@ -19,6 +19,6 @@ fn main() {
iroha_logger::test_logger();
}
iroha_logger::info!("Starting...");
let bench = WsvApplyBlocks::setup(rt.handle()).expect("Failed to setup benchmark");
WsvApplyBlocks::measure(&bench).expect("Failed to execute benchmark");
let bench = StateApplyBlocks::setup(rt.handle()).expect("Failed to setup benchmark");
StateApplyBlocks::measure(&bench).expect("Failed to execute benchmark");
}
Loading

0 comments on commit 26ac620

Please sign in to comment.