Skip to content

Commit

Permalink
[refactor] hyperledger-iroha#2292: Remove WorldTrait, remove generi…
Browse files Browse the repository at this point in the history
…cs from `IsAllowedBoxed` (hyperledger-iroha#2284)

Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix authored Jun 14, 2022
1 parent eafdb7e commit 916a2cc
Show file tree
Hide file tree
Showing 73 changed files with 2,696 additions and 2,687 deletions.
3 changes: 1 addition & 2 deletions 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 cli/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use syn::{
/// 3) When the colon-separated form has spaces in the provided name.
///
/// # Examples:
/// ```rust
/// ```no_run
/// use warp::{Rejection, Filter};
/// use std::convert::Infallible;
/// use iroha_cli::torii::utils::WarpResult;
Expand Down
47 changes: 20 additions & 27 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use iroha_core::{
smartcontracts::permissions::{IsInstructionAllowedBoxed, IsQueryAllowedBoxed},
sumeragi::{Sumeragi, SumeragiTrait},
tx::{PeerId, TransactionValidator},
wsv::WorldTrait,
IrohaNetwork,
};
use iroha_data_model::prelude::*;
Expand Down Expand Up @@ -62,40 +61,33 @@ impl Default for Arguments {

/// Iroha is an [Orchestrator](https://en.wikipedia.org/wiki/Orchestration_%28computing%29) of the
/// system. It configures, coordinates and manages transactions and queries processing, work of consensus and storage.
pub struct Iroha<
W = World,
G = GenesisNetwork,
K = Kura<W>,
S = Sumeragi<G, K, W>,
B = BlockSynchronizer<S, W>,
> where
W: WorldTrait,
pub struct Iroha<G = GenesisNetwork, K = Kura, S = Sumeragi<G, K>, B = BlockSynchronizer<S>>
where
G: GenesisNetworkTrait,
K: KuraTrait<World = W>,
S: SumeragiTrait<GenesisNetwork = G, Kura = K, World = W>,
B: BlockSynchronizerTrait<Sumeragi = S, World = W>,
K: KuraTrait,
S: SumeragiTrait<GenesisNetwork = G, Kura = K>,
B: BlockSynchronizerTrait<Sumeragi = S>,
{
/// World state view
pub wsv: Arc<WorldStateView<W>>,
pub wsv: Arc<WorldStateView>,
/// Queue of transactions
pub queue: Arc<Queue<W>>,
pub queue: Arc<Queue>,
/// Sumeragi consensus
pub sumeragi: AlwaysAddr<S>,
/// Kura - block storage
pub kura: AlwaysAddr<K>,
/// Block synchronization actor
pub block_sync: AlwaysAddr<B>,
/// Torii web server
pub torii: Option<Torii<W>>,
pub torii: Option<Torii>,
}

impl<W, G, S, K, B> Iroha<W, G, K, S, B>
impl<G, S, K, B> Iroha<G, K, S, B>
where
W: WorldTrait,
G: GenesisNetworkTrait,
K: KuraTrait<World = W>,
S: SumeragiTrait<GenesisNetwork = G, Kura = K, World = W>,
B: BlockSynchronizerTrait<Sumeragi = S, World = W>,
K: KuraTrait,
S: SumeragiTrait<GenesisNetwork = G, Kura = K>,
B: BlockSynchronizerTrait<Sumeragi = S>,
{
/// To make `Iroha` peer work all actors should be started first.
/// After that moment it you can start it with listening to torii events.
Expand All @@ -111,8 +103,8 @@ where
#[allow(clippy::non_ascii_literal)]
pub async fn new(
args: &Arguments,
instruction_validator: IsInstructionAllowedBoxed<K::World>,
query_validator: IsQueryAllowedBoxed<K::World>,
instruction_validator: IsInstructionAllowedBoxed,
query_validator: IsQueryAllowedBoxed,
) -> Result<Self> {
let broker = Broker::new();
let mut config = match Configuration::from_path(&args.config_path) {
Expand Down Expand Up @@ -153,8 +145,8 @@ where
pub async fn with_genesis(
genesis: Option<G>,
config: Configuration,
instruction_validator: IsInstructionAllowedBoxed<K::World>,
query_validator: IsQueryAllowedBoxed<K::World>,
instruction_validator: IsInstructionAllowedBoxed,
query_validator: IsQueryAllowedBoxed,
broker: Broker,
telemetry: Option<iroha_logger::Telemetries>,
) -> Result<Self> {
Expand All @@ -177,7 +169,7 @@ where
let network_addr = network.start().await;

let (events_sender, _) = broadcast::channel(100);
let world = W::with(
let world = World::with(
domains(&config),
config.sumeragi.trusted_peers.peers.clone(),
);
Expand All @@ -187,6 +179,7 @@ where
);

let query_validator = Arc::new(query_validator);

let transaction_validator = TransactionValidator::new(
config.sumeragi.transaction_limits,
Arc::new(instruction_validator),
Expand Down Expand Up @@ -347,7 +340,7 @@ where
///
/// # Errors
/// - Genesis account public key not specified.
fn domains(configuration: &config::Configuration) -> impl Iterator<Item = Domain> {
fn domains(configuration: &config::Configuration) -> [Domain; 1] {
let key = configuration.genesis.account_public_key.clone();
[Domain::from(GenesisDomain::new(key))].into_iter()
[Domain::from(GenesisDomain::new(key))]
}
9 changes: 4 additions & 5 deletions cli/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use iroha_core::{
prelude::*,
queue::{self, Queue},
smartcontracts::{isi::query, permissions::IsQueryAllowedBoxed},
wsv::WorldTrait,
EventsSender, IrohaNetwork,
};
use thiserror::Error;
Expand All @@ -29,12 +28,12 @@ pub mod config;
pub mod routing;

/// Main network handler and the only entrypoint of the Iroha.
pub struct Torii<W: WorldTrait> {
pub struct Torii {
iroha_cfg: super::Configuration,
wsv: Arc<WorldStateView<W>>,
queue: Arc<Queue<W>>,
wsv: Arc<WorldStateView>,
queue: Arc<Queue>,
events: EventsSender,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
query_validator: Arc<IsQueryAllowedBoxed>,
network: iroha_actor::Addr<IrohaNetwork>,
notify_shutdown: Arc<Notify>,
}
Expand Down
64 changes: 27 additions & 37 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use iroha_core::{
BlockPublisherMessage, BlockSubscriberMessage, VersionedBlockPublisherMessage,
VersionedBlockSubscriberMessage,
},
smartcontracts::isi::{
permissions::IsQueryAllowedBoxed,
query::{Error as QueryError, ValidQueryRequest},
smartcontracts::{
isi::{
permissions::IsQueryAllowedBoxed,
query::{Error as QueryError, ValidQueryRequest},
},
permissions::IsAllowed as _,
},
wsv::WorldTrait,
};
use iroha_crypto::SignatureOf;
use iroha_data_model::{
Expand Down Expand Up @@ -52,10 +54,10 @@ impl VerifiedQueryRequest {
/// - Account doesn't exist.
/// - Account doesn't have the correct public key.
/// - Account has incorrect permissions.
pub fn validate<W: WorldTrait>(
pub fn validate(
self,
wsv: &WorldStateView<W>,
query_validator: &IsQueryAllowedBoxed<W>,
wsv: &WorldStateView,
query_validator: &IsQueryAllowedBoxed,
) -> Result<(ValidQueryRequest, PredicateBox), QueryError> {
let account_has_public_key = wsv.map_account(&self.payload.account_id, |account| {
account.contains_signatory(self.signature.public_key())
Expand Down Expand Up @@ -91,9 +93,9 @@ impl TryFrom<SignedQueryRequest> for VerifiedQueryRequest {
}

#[iroha_futures::telemetry_future]
pub(crate) async fn handle_instructions<W: WorldTrait>(
pub(crate) async fn handle_instructions(
iroha_cfg: Configuration,
queue: Arc<Queue<W>>,
queue: Arc<Queue>,
transaction: VersionedTransaction,
) -> Result<Empty> {
let transaction: Transaction = transaction.into_v1();
Expand All @@ -114,9 +116,9 @@ pub(crate) async fn handle_instructions<W: WorldTrait>(
}

#[iroha_futures::telemetry_future]
pub(crate) async fn handle_queries<W: WorldTrait>(
wsv: Arc<WorldStateView<W>>,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
pub(crate) async fn handle_queries(
wsv: Arc<WorldStateView>,
query_validator: Arc<IsQueryAllowedBoxed>,
pagination: Pagination,
request: VerifiedQueryRequest,
) -> Result<Scale<VersionedPaginatedQueryResult>> {
Expand Down Expand Up @@ -162,8 +164,8 @@ async fn handle_schema() -> Json {
}

#[iroha_futures::telemetry_future]
async fn handle_pending_transactions<W: WorldTrait>(
queue: Arc<Queue<W>>,
async fn handle_pending_transactions(
queue: Arc<Queue>,
pagination: Pagination,
) -> Result<Scale<VersionedPendingTransactions>> {
Ok(Scale(
Expand Down Expand Up @@ -215,10 +217,7 @@ async fn handle_post_configuration(
}

#[iroha_futures::telemetry_future]
async fn handle_blocks_stream<W: WorldTrait>(
wsv: &WorldStateView<W>,
mut stream: WebSocket,
) -> eyre::Result<()> {
async fn handle_blocks_stream(wsv: &WorldStateView, mut stream: WebSocket) -> eyre::Result<()> {
let subscription_request: VersionedBlockSubscriberMessage = stream.recv().await?;
let mut from_height = subscription_request.into_v1().try_into()?;

Expand All @@ -237,9 +236,9 @@ async fn handle_blocks_stream<W: WorldTrait>(
}
}

async fn stream_blocks<W: WorldTrait>(
async fn stream_blocks(
from_height: &mut u64,
wsv: &WorldStateView<W>,
wsv: &WorldStateView,
stream: &mut WebSocket,
) -> eyre::Result<()> {
#[allow(clippy::expect_used)]
Expand Down Expand Up @@ -348,7 +347,7 @@ mod subscription {

#[iroha_futures::telemetry_future]
#[cfg(feature = "telemetry")]
async fn handle_version<W: WorldTrait>(wsv: Arc<WorldStateView<W>>) -> Json {
async fn handle_version(wsv: Arc<WorldStateView>) -> Json {
use iroha_version::Version;

#[allow(clippy::expect_used)]
Expand All @@ -363,29 +362,20 @@ async fn handle_version<W: WorldTrait>(wsv: Arc<WorldStateView<W>>) -> Json {
}

#[cfg(feature = "telemetry")]
async fn handle_metrics<W: WorldTrait>(
wsv: Arc<WorldStateView<W>>,
network: Addr<IrohaNetwork>,
) -> Result<String> {
async fn handle_metrics(wsv: Arc<WorldStateView>, network: Addr<IrohaNetwork>) -> Result<String> {
update_metrics(&wsv, network).await?;
wsv.metrics.try_to_string().map_err(Error::Prometheus)
}

#[cfg(feature = "telemetry")]
async fn handle_status<W: WorldTrait>(
wsv: Arc<WorldStateView<W>>,
network: Addr<IrohaNetwork>,
) -> Result<Json> {
async fn handle_status(wsv: Arc<WorldStateView>, network: Addr<IrohaNetwork>) -> Result<Json> {
update_metrics(&wsv, network).await?;
let status = Status::from(&wsv.metrics);
Ok(reply::json(&status))
}

#[cfg(feature = "telemetry")]
async fn update_metrics<W: WorldTrait>(
wsv: &WorldStateView<W>,
network: Addr<IrohaNetwork>,
) -> Result<()> {
async fn update_metrics(wsv: &WorldStateView, network: Addr<IrohaNetwork>) -> Result<()> {
let peers = network
.send(iroha_p2p::network::GetConnectedPeers)
.await
Expand Down Expand Up @@ -413,13 +403,13 @@ async fn update_metrics<W: WorldTrait>(
Ok(())
}

impl<W: WorldTrait> Torii<W> {
impl Torii {
/// Construct `Torii` from `ToriiConfiguration`.
pub fn from_configuration(
iroha_cfg: Configuration,
wsv: Arc<WorldStateView<W>>,
queue: Arc<Queue<W>>,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
wsv: Arc<WorldStateView>,
queue: Arc<Queue>,
query_validator: Arc<IsQueryAllowedBoxed>,
events: EventsSender,
network: Addr<IrohaNetwork>,
notify_shutdown: Arc<Notify>,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroha_core::{
BlockHeader, EmptyChainHash,
},
queue::Queue,
smartcontracts::{isi::error::FindError, permissions::DenyAll},
smartcontracts::{isi::error::FindError, permissions::combinators::DenyAll},
sumeragi::view_change::ProofChain,
tx::TransactionValidator,
wsv::World,
Expand All @@ -29,7 +29,7 @@ use crate::{
stream::{Sink, Stream},
};

async fn create_torii() -> (Torii<World>, KeyPair) {
async fn create_torii() -> (Torii, KeyPair) {
let mut config = crate::samples::get_config(crate::samples::get_trusted_peers(None), None);
config.torii.p2p_addr = format!("127.0.0.1:{}", unique_port::get_unique_free_port().unwrap());
config.torii.api_url = format!("127.0.0.1:{}", unique_port::get_unique_free_port().unwrap());
Expand All @@ -54,7 +54,7 @@ async fn create_torii() -> (Torii<World>, KeyPair) {
.build()
)
.is_none());
wsv.world.domains.insert(domain_id, domain);
wsv.domains().insert(domain_id, domain);
let queue = Arc::new(Queue::from_configuration(&config.queue, Arc::clone(&wsv)));
let network = IrohaNetwork::new(
Broker::new(),
Expand Down
3 changes: 2 additions & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ mod tests {
#[cfg(test)]
mod query_errors_handling {
use http::Response;
use iroha_core::smartcontracts::permissions::error::DenialReason;

use super::*;

Expand All @@ -1248,7 +1249,7 @@ mod tests {
),
(
StatusCode::FORBIDDEN,
QueryError::Permission("whatever".to_owned()),
QueryError::Permission(DenialReason::Custom("whatever".to_owned())),
),
(
StatusCode::NOT_FOUND,
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{str::FromStr as _, thread};

use iroha_client::client::{self, Client};
use iroha_core::smartcontracts::isi::permissions::DenyAll;
use iroha_core::smartcontracts::isi::permissions::combinators::DenyAll;
use iroha_data_model::prelude::*;
use iroha_permissions_validators::{private_blockchain, public_blockchain};
use test_network::{PeerBuilder, *};
Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{str::FromStr as _, time::Duration};

use eyre::{eyre, Result};
use iroha_client::client::{self, Client};
use iroha_core::{prelude::AllowAll, smartcontracts::permissions::ValidatorBuilder};
use iroha_core::prelude::*;
use iroha_data_model::prelude::*;
use iroha_permissions_validators::public_blockchain::{
key_value::{CanRemoveKeyValueInUserMetadata, CanSetKeyValueInUserMetadata},
Expand All @@ -21,9 +21,9 @@ fn add_role_to_limit_transfer_count() -> Result<()> {
// Peer has a special permission validator we need for this test
let (_rt, _peer, mut test_client) = <PeerBuilder>::new()
.with_instruction_validator(
ValidatorBuilder::new()
.with_recursive_validator(transfer::ExecutionCountFitsInLimit)
.all_should_succeed(),
ValidatorBuilder::with_recursive_validator(transfer::ExecutionCountFitsInLimit)
.all_should_succeed()
.build(),
)
.with_query_validator(AllowAll)
.start_with_runtime();
Expand Down
Loading

0 comments on commit 916a2cc

Please sign in to comment.