Skip to content

Commit

Permalink
[refactor]: remove WorldSnapshot and StateSnapshot
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 21, 2024
1 parent a60cfeb commit e1e8a1a
Show file tree
Hide file tree
Showing 26 changed files with 436 additions and 513 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -134,7 +134,7 @@ 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" }
storage = { git = "https://github.com/Erigara/storage.git", rev = "79689ae68573bfe4c4d80d902c726d84fec22257" }

[workspace.lints]
rustdoc.private_doc_tests = "deny"
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Expand Up @@ -22,7 +22,7 @@ use iroha_core::{
snapshot::{
try_read_snapshot, SnapshotMaker, SnapshotMakerHandle, TryReadError as TryReadSnapshotError,
},
state::{State, World},
state::{State, StateReadOnly, World},
sumeragi::{SumeragiHandle, SumeragiStartArgs},
IrohaNetwork,
};
Expand Down
7 changes: 6 additions & 1 deletion core/src/block_sync.rs
Expand Up @@ -10,7 +10,12 @@ use iroha_p2p::Post;
use parity_scale_codec::{Decode, Encode};
use tokio::sync::mpsc;

use crate::{kura::Kura, state::State, sumeragi::SumeragiHandle, IrohaNetwork, NetworkMessage};
use crate::{
kura::Kura,
state::{State, StateReadOnly},
sumeragi::SumeragiHandle,
IrohaNetwork, NetworkMessage,
};

/// [`BlockSynchronizer`] actor handle.
#[derive(Clone)]
Expand Down
14 changes: 7 additions & 7 deletions core/src/executor.rs
Expand Up @@ -17,7 +17,7 @@ use serde::{

use crate::{
smartcontracts::{wasm, Execute as _},
state::{deserialize::WasmSeed, StateSnapshot, StateTransaction},
state::{deserialize::WasmSeed, StateReadOnly, StateTransaction},
};

impl From<wasm::error::Error> for ValidationFail {
Expand Down Expand Up @@ -213,9 +213,9 @@ impl Executor {
/// - Failed to prepare runtime for WASM execution;
/// - Failed to execute the entrypoint of the WASM blob;
/// - Executor denied the operation.
pub fn validate_query(
pub fn validate_query<S: StateReadOnly>(
&self,
state_snapshot: &StateSnapshot<'_>,
state_ro: &S,
authority: &AccountId,
query: QueryBox,
) -> Result<(), ValidationFail> {
Expand All @@ -224,13 +224,13 @@ impl Executor {
match self {
Self::Initial => Ok(()),
Self::UserProvided(UserProvidedExecutor(loaded_executor)) => {
let runtime = wasm::RuntimeBuilder::<wasm::state::executor::ValidateQuery>::new()
.with_engine(state_snapshot.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_snapshot.config.executor_runtime)
let runtime = wasm::RuntimeBuilder::<wasm::state::executor::ValidateQuery<S>>::new()
.with_engine(state_ro.engine().clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs
.with_config(state_ro.config().executor_runtime)
.build()?;

runtime.execute_executor_validate_query(
state_snapshot,
state_ro,
authority,
&loaded_executor.module,
query,
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Expand Up @@ -161,7 +161,7 @@ pub mod prelude {
#[doc(inline)]
pub use crate::{
smartcontracts::ValidQuery,
state::{StateView, World},
state::{StateReadOnly, StateView, World, WorldReadOnly},
tx::AcceptedTransaction,
};
}
Expand Down
54 changes: 27 additions & 27 deletions core/src/smartcontracts/isi/account.rs
Expand Up @@ -598,18 +598,18 @@ pub mod query {
};

use super::*;
use crate::state::StateSnapshot;
use crate::state::StateReadOnly;

impl ValidQuery for FindRolesByAccountId {
#[metrics(+"find_roles_by_account_id")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = RoleId> + 'state>, Error> {
let account_id = &self.id;
state_snapshot.world.account(account_id)?;
state_ro.world().account(account_id)?;
Ok(Box::new(
state_snapshot.world.account_roles(account_id).cloned(),
state_ro.world().account_roles_iter(account_id).cloned(),
))
}
}
Expand All @@ -618,13 +618,13 @@ pub mod query {
#[metrics(+"find_permission_tokens_by_account_id")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = PermissionToken> + 'state>, Error> {
let account_id = &self.id;
Ok(Box::new(
state_snapshot
.world
.account_permission_tokens(account_id)?
state_ro
.world()
.account_permission_tokens_iter(account_id)?
.cloned(),
))
}
Expand All @@ -634,12 +634,12 @@ pub mod query {
#[metrics(+"find_all_accounts")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = Account> + 'state>, Error> {
Ok(Box::new(
state_snapshot
.world
.domains()
state_ro
.world()
.domains_iter()
.flat_map(|domain| domain.accounts.values())
.cloned(),
))
Expand All @@ -648,11 +648,11 @@ pub mod query {

impl ValidQuery for FindAccountById {
#[metrics(+"find_account_by_id")]
fn execute(&self, state_snapshot: &StateSnapshot<'_>) -> Result<Account, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Account, Error> {
let id = &self.id;
iroha_logger::trace!(%id);
state_snapshot
.world
state_ro
.world()
.map_account(id, Clone::clone)
.map_err(Into::into)
}
Expand All @@ -662,14 +662,14 @@ pub mod query {
#[metrics(+"find_account_by_name")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = Account> + 'state>, Error> {
let name = self.name.clone();
iroha_logger::trace!(%name);
Ok(Box::new(
state_snapshot
.world
.domains()
state_ro
.world()
.domains_iter()
.flat_map(move |domain| {
let name = name.clone();

Expand All @@ -687,25 +687,25 @@ pub mod query {
#[metrics(+"find_accounts_by_domain_id")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = Account> + 'state>, Error> {
let id = &self.domain_id;

iroha_logger::trace!(%id);
Ok(Box::new(
state_snapshot.world.domain(id)?.accounts.values().cloned(),
state_ro.world().domain(id)?.accounts.values().cloned(),
))
}
}

impl ValidQuery for FindAccountKeyValueByIdAndKey {
#[metrics(+"find_account_key_value_by_id_and_key")]
fn execute(&self, state_snapshot: &StateSnapshot<'_>) -> Result<MetadataValueBox, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<MetadataValueBox, Error> {
let id = &self.id;
let key = &self.key;
iroha_logger::trace!(%id, %key);
state_snapshot
.world
state_ro
.world()
.map_account(id, |account| account.metadata.get(key).cloned())?
.ok_or_else(|| FindError::MetadataKey(key.clone()).into())
.map(Into::into)
Expand All @@ -716,14 +716,14 @@ pub mod query {
#[metrics(+"find_accounts_with_asset")]
fn execute<'state>(
&self,
state_snapshot: &'state StateSnapshot<'state>,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = Account> + 'state>, Error> {
let asset_definition_id = self.asset_definition_id.clone();
iroha_logger::trace!(%asset_definition_id);

Ok(Box::new(
state_snapshot
.world
state_ro
.world()
.map_domain(&asset_definition_id.domain_id.clone(), move |domain| {
domain.accounts.values().filter(move |account| {
let asset_id =
Expand Down

0 comments on commit e1e8a1a

Please sign in to comment.