Skip to content

Commit

Permalink
Merge branch 'iroha2-dev' into dev_error_message_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
6r1d committed Jul 18, 2022
2 parents 4f81009 + 5ff6b67 commit a16d9c3
Show file tree
Hide file tree
Showing 61 changed files with 3,862 additions and 3,866 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ tokio = { version = "1.6.0", features = ["sync", "time", "rt", "io-util", "rt-mu
warp = "0.3"

[dev-dependencies]
serial_test = "0.8.0"
test_network = { version = "=2.0.0-pre-rc.5", path = "../core/test_network" }
3 changes: 3 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Configuration {
pub private_key: PrivateKey,
/// Disable coloring of the backtrace and error report on panic.
pub disable_panic_terminal_colors: bool,
/// Iroha will shutdown on any panic if this option is set to `true`.
pub shutdown_on_panic: bool,
/// `Kura` related configuration.
#[config(inner)]
pub kura: KuraConfiguration,
Expand Down Expand Up @@ -71,6 +73,7 @@ impl Default for Configuration {
public_key,
private_key,
disable_panic_terminal_colors: bool::default(),
shutdown_on_panic: false,
kura: KuraConfiguration::default(),
sumeragi: sumeragi_configuration,
torii: ToriiConfiguration::default(),
Expand Down
31 changes: 18 additions & 13 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use iroha_core::{
kura::Kura,
prelude::{World, WorldStateView},
queue::Queue,
smartcontracts::permissions::{IsInstructionAllowedBoxed, IsQueryAllowedBoxed},
smartcontracts::permissions::judge::{InstructionJudgeBoxed, QueryJudgeBoxed},
sumeragi::{Sumeragi, SumeragiTrait},
tx::{PeerId, TransactionValidator},
IrohaNetwork,
Expand Down Expand Up @@ -101,8 +101,8 @@ where
#[allow(clippy::non_ascii_literal)]
pub async fn new(
args: &Arguments,
instruction_validator: IsInstructionAllowedBoxed,
query_validator: IsQueryAllowedBoxed,
instruction_judge: InstructionJudgeBoxed,
query_judge: QueryJudgeBoxed,
) -> Result<Self> {
let broker = Broker::new();
let mut config = match Configuration::from_path(&args.config_path) {
Expand Down Expand Up @@ -130,8 +130,8 @@ where
Self::with_genesis(
genesis,
config,
instruction_validator,
query_validator,
instruction_judge,
query_judge,
broker,
telemetry,
)
Expand All @@ -155,8 +155,8 @@ where
pub async fn with_genesis(
genesis: Option<G>,
config: Configuration,
instruction_validator: IsInstructionAllowedBoxed,
query_validator: IsQueryAllowedBoxed,
instruction_judge: InstructionJudgeBoxed,
query_judge: QueryJudgeBoxed,
broker: Broker,
telemetry: Option<iroha_logger::Telemetries>,
) -> Result<Self> {
Expand Down Expand Up @@ -189,12 +189,12 @@ where
events_sender.clone(),
));

let query_validator = Arc::new(query_validator);
let query_judge = Arc::from(query_judge);

let transaction_validator = TransactionValidator::new(
config.sumeragi.transaction_limits,
Arc::new(instruction_validator),
Arc::clone(&query_validator),
Arc::from(instruction_judge),
Arc::clone(&query_judge),
Arc::clone(&wsv),
);

Expand Down Expand Up @@ -244,15 +244,17 @@ where
config.clone(),
Arc::clone(&wsv),
Arc::clone(&queue),
query_validator,
query_judge,
events_sender,
network_addr.clone(),
Arc::clone(&notify_shutdown),
);

Self::start_listening_signal(Arc::clone(&notify_shutdown))?;

Self::prepare_panic_hook(notify_shutdown);
if config.shutdown_on_panic {
Self::prepare_panic_hook(notify_shutdown);
}

let torii = Some(torii);
Ok(Self {
Expand Down Expand Up @@ -367,10 +369,13 @@ fn domains(configuration: &config::Configuration) -> [Domain; 1] {
mod tests {
use std::{panic, thread};

use serial_test::serial;

use super::*;

#[tokio::test]
#[allow(clippy::panic)]
#[tokio::test]
#[serial]
async fn iroha_should_notify_on_panic() {
let notify = Arc::new(Notify::new());
let hook = panic::take_hook();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<(), color_eyre::Report> {
}
}

<iroha::Iroha>::new(&args, default_permissions(), AllowAll.into())
<iroha::Iroha>::new(&args, default_permissions(), Box::new(AllowAll::new()))
.await?
.start()
.await?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::{stream::FuturesUnordered, StreamExt};
use iroha_core::{
prelude::*,
queue::{self, Queue},
smartcontracts::{isi::query, permissions::IsQueryAllowedBoxed},
smartcontracts::isi::query,
EventsSender, IrohaNetwork,
};
use thiserror::Error;
Expand All @@ -33,7 +33,7 @@ pub struct Torii {
wsv: Arc<WorldStateView>,
queue: Arc<Queue>,
events: EventsSender,
query_validator: Arc<IsQueryAllowedBoxed>,
query_judge: QueryJudgeArc,
network: iroha_actor::Addr<IrohaNetwork>,
notify_shutdown: Arc<Notify>,
}
Expand Down
23 changes: 10 additions & 13 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ use iroha_core::{
VersionedBlockSubscriberMessage,
},
smartcontracts::{
isi::{
permissions::IsQueryAllowedBoxed,
query::{Error as QueryError, ValidQueryRequest},
},
permissions::IsAllowed as _,
isi::query::{Error as QueryError, ValidQueryRequest},
permissions::prelude::*,
},
};
use iroha_crypto::SignatureOf;
Expand Down Expand Up @@ -57,7 +54,7 @@ impl VerifiedQueryRequest {
pub fn validate(
self,
wsv: &WorldStateView,
query_validator: &IsQueryAllowedBoxed,
query_judge: &dyn Judge<Operation = QueryBox>,
) -> 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 All @@ -67,8 +64,8 @@ impl VerifiedQueryRequest {
"Signature public key doesn't correspond to the account.",
)));
}
query_validator
.check(&self.payload.account_id, &self.payload.query, wsv)
query_judge
.judge(&self.payload.account_id, &self.payload.query, wsv)
.map_err(QueryError::Permission)?;
Ok((
ValidQueryRequest::new(self.payload.query),
Expand Down Expand Up @@ -118,11 +115,11 @@ pub(crate) async fn handle_instructions(
#[iroha_futures::telemetry_future]
pub(crate) async fn handle_queries(
wsv: Arc<WorldStateView>,
query_validator: Arc<IsQueryAllowedBoxed>,
query_judge: QueryJudgeArc,
pagination: Pagination,
request: VerifiedQueryRequest,
) -> Result<Scale<VersionedPaginatedQueryResult>> {
let (valid_request, filter) = request.validate(&wsv, &query_validator)?;
let (valid_request, filter) = request.validate(&wsv, query_judge.as_ref())?;
let original_result = valid_request.execute(&wsv)?;
let result = filter.filter(original_result);
let (total, result) = if let Value::Vec(value) = result {
Expand Down Expand Up @@ -409,7 +406,7 @@ impl Torii {
iroha_cfg: Configuration,
wsv: Arc<WorldStateView>,
queue: Arc<Queue>,
query_validator: Arc<IsQueryAllowedBoxed>,
query_judge: QueryJudgeArc,
events: EventsSender,
network: Addr<IrohaNetwork>,
notify_shutdown: Arc<Notify>,
Expand All @@ -418,7 +415,7 @@ impl Torii {
iroha_cfg,
wsv,
events,
query_validator,
query_judge,
queue,
network,
notify_shutdown,
Expand Down Expand Up @@ -484,7 +481,7 @@ impl Torii {
.or(endpoint4(
handle_queries,
warp::path(uri::QUERY)
.and(add_state!(self.wsv, self.query_validator))
.and(add_state!(self.wsv, self.query_judge))
.and(paginate())
.and(body::query()),
))
Expand Down
21 changes: 13 additions & 8 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::combinators::DenyAll},
smartcontracts::isi::error::FindError,
sumeragi::view_change::ProofChain,
tx::TransactionValidator,
wsv::World,
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn create_torii() -> (Torii, KeyPair) {
config,
wsv,
queue,
AllowAll::new(),
Arc::new(AllowAll::new()),
events,
network,
Arc::new(Notify::new()),
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn torii_pagination() {
let pagination = Pagination { start, limit };
handle_queries(
Arc::clone(&torii.wsv),
Arc::clone(&torii.query_validator),
Arc::clone(&torii.query_judge),
pagination,
query,
)
Expand Down Expand Up @@ -176,7 +176,7 @@ impl QuerySet {

let (mut torii, keys) = create_torii().await;
if self.deny_all {
torii.query_validator = Arc::new(DenyAll.into());
torii.query_judge = Arc::new(DenyAll::new());
}

let authority = AccountId::from_str("alice@wonderland").expect("Valid");
Expand Down Expand Up @@ -789,10 +789,15 @@ fn hash_should_be_the_same() {
domains(&config).unwrap(),
BTreeSet::new(),
)));
let valid_tx_hash = TransactionValidator::new(tx_limits, AllowAll::new(), AllowAll::new(), wsv)
.validate(accepted_tx, true)
.expect("Failed to validate.")
.hash();
let valid_tx_hash = TransactionValidator::new(
tx_limits,
Arc::new(AllowAll::new()),
Arc::new(AllowAll::new()),
wsv,
)
.validate(accepted_tx, true)
.expect("Failed to validate.")
.hash();
assert_eq!(tx_hash, signed_tx_hash);
assert_eq!(tx_hash, accepted_tx_hash);
assert_eq!(tx_hash, valid_tx_hash.transmute());
Expand Down
9 changes: 7 additions & 2 deletions client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ fn main() {
// invoked with the nightly toolchain. We should not force our
// users to have the `nightly` if we don't use any `nightly`
// features in the actual binary.
if env::var("RUSTUP_TOOLCHAIN")
.expect("Should be defined")
let rustc_version_output = Command::new("rustc")
.arg("--version")
.output()
.expect("Failed to run `rustc --version`");

if std::str::from_utf8(&rustc_version_output.stdout)
.expect("Garbage in `rustc --version` output")
.contains("nightly")
{
let manifest_dir = env::var("CARGO_MANIFEST_DIR")
Expand Down
3 changes: 1 addition & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,6 @@ mod tests {
#[cfg(test)]
mod query_errors_handling {
use http::Response;
use iroha_core::smartcontracts::permissions::error::DenialReason;

use super::*;

Expand All @@ -1260,7 +1259,7 @@ mod tests {
),
(
StatusCode::FORBIDDEN,
QueryError::Permission(DenialReason::Custom("whatever".to_owned())),
QueryError::Permission("whatever".to_owned()),
),
(
StatusCode::NOT_FOUND,
Expand Down
Loading

0 comments on commit a16d9c3

Please sign in to comment.