Skip to content

Commit

Permalink
[fix] hyperledger-iroha#2081: Fix role registration.
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
  • Loading branch information
appetrosyan committed Apr 20, 2022
1 parent f8040a8 commit 659d74e
Show file tree
Hide file tree
Showing 26 changed files with 523 additions and 327 deletions.
40 changes: 16 additions & 24 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ members = [
"core",
"core/test_network",
"crypto",
"tools/crypto_cli",
"tools/kura_inspector",
"tools/parity_scale_decoder",
"tools/generator",
"tools/kagami",
"data_model",
"data_model/primitives",
"futures",
Expand Down
27 changes: 25 additions & 2 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![allow(clippy::restriction)]

use std::{str::FromStr as _, time::Duration};
use std::{str::FromStr as _, time::Duration, collections::BTreeMap};

use eyre::{eyre, Result};
use iroha_client::client::{self, Client};
use iroha_core::{prelude::AllowAll, smartcontracts::permissions::ValidatorBuilder};
use iroha_data_model::{permissions::Permissions, prelude::*};
use iroha_permissions_validators::public_blockchain::transfer;
use iroha_permissions_validators::public_blockchain::{
key_value::{CAN_REMOVE_KEY_VALUE_IN_USER_METADATA, CAN_SET_KEY_VALUE_IN_USER_METADATA},
transfer,
};
use test_network::{Peer as TestPeer, *};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -122,3 +125,23 @@ fn register_role_with_empty_token_params() -> Result<()> {

// TODO: When we have more sane default permissions, see if we can
// test more about whether or not roles actually work.

#[test]
fn register_and_grant_metadata_role_to_account() -> Result<()> {
let (_rt, _peer, mut test_client) = <TestPeer>::start_test_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let bob_id = <Account as Identifiable>::Id::from_str("bob@wonderland")?;
let register_bob = RegisterBox::new(Account::new(bob_id.clone(), []));
test_client.submit_blocking(register_bob)?;

let role_id = iroha_data_model::role::Id::new("USER_METADATA_ACCESS".parse::<Name>()?);
let mut permissions = Permissions::new();
let mut params = BTreeMap::new();
params.insert(Name::from_str("account_id")?, bob_id.into());
permissions.insert(PermissionToken::new(CAN_SET_KEY_VALUE_IN_USER_METADATA.clone()).with_params(params.clone()));
permissions.insert(PermissionToken::new(CAN_REMOVE_KEY_VALUE_IN_USER_METADATA.clone()).with_params(params));
let register_role = RegisterBox::new(Role::new(role_id, permissions));
test_client.submit(register_role)?;
Ok(())
}
2 changes: 1 addition & 1 deletion config/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod attrs {
pub const INNER: &str = "inner";
}

fn get_type_argument<'a, 'b>(s: &'a str, ty: &'b Type) -> Option<&'b GenericArgument> {
fn get_type_argument<'st, 'ty>(s: &'st str, ty: &'ty Type) -> Option<&'ty GenericArgument> {
let path = if let Type::Path(r#type) = ty {
r#type
} else {
Expand Down
8 changes: 4 additions & 4 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets inner field of arbitrary inner depth and returns as json-value
/// # Errors
/// Fails if field was unknown
fn get_recursive<'a, T>(&self, inner_field: T) -> Result<Value, Self::Error>
fn get_recursive<'fld, T>(&self, inner_field: T) -> Result<Value, Self::Error>
where
T: AsRef<[&'a str]> + Send + 'a;
T: AsRef<[&'fld str]> + Send + 'fld;

/// Fails if fails to deserialize from environment
/// # Errors
Expand All @@ -184,8 +184,8 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets docs of inner field of arbitrary depth
/// # Errors
/// Fails if field was unknown
fn get_doc_recursive<'a>(
field: impl AsRef<[&'a str]>,
fn get_doc_recursive<'fld>(
field: impl AsRef<[&'fld str]>,
) -> Result<Option<&'static str>, Self::Error>;

/// Gets docs of field
Expand Down
3 changes: 2 additions & 1 deletion config/src/runtime_upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub enum ReloadError {
Other,
}

type PoisonErr<'a, T> = PoisonError<MutexGuard<'a, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;
type PoisonErr<'mutex, T> =
PoisonError<MutexGuard<'mutex, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;

impl<T> From<PoisonErr<'_, T>> for ReloadError {
fn from(_: PoisonErr<'_, T>) -> Self {
Expand Down
14 changes: 7 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ impl Chain {
}

/// Chain iterator
pub struct ChainIterator<'a> {
chain: &'a Chain,
pub struct ChainIterator<'ch> {
chain: &'ch Chain,
pos_front: u64,
pos_back: u64,
}

impl<'a> ChainIterator<'a> {
fn new(chain: &'a Chain) -> Self {
impl<'ch> ChainIterator<'ch> {
fn new(chain: &'ch Chain) -> Self {
ChainIterator {
chain,
pos_front: 1,
Expand All @@ -116,8 +116,8 @@ impl<'a> ChainIterator<'a> {
}
}

impl<'a> Iterator for ChainIterator<'a> {
type Item = MapRef<'a, u64, VersionedCommittedBlock>;
impl<'ch> Iterator for ChainIterator<'ch> {
type Item = MapRef<'ch, u64, VersionedCommittedBlock>;
fn next(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_front);
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<'a> Iterator for ChainIterator<'a> {
}
}

impl<'a> DoubleEndedIterator for ChainIterator<'a> {
impl<'de> DoubleEndedIterator for ChainIterator<'de> {
fn next_back(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_back);
Expand Down
10 changes: 5 additions & 5 deletions core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{collections::HashSet, fmt::Debug, fs::File, io::BufReader, ops::Deref,
use eyre::{eyre, Result, WrapErr};
use iroha_actor::Addr;
use iroha_crypto::{KeyPair, PublicKey};
use iroha_data_model::{asset::AssetDefinition, domain::NewDomain, prelude::*};
use iroha_data_model::{asset::AssetDefinition, prelude::*};
use iroha_schema::prelude::*;
use serde::{Deserialize, Serialize};
use small::SmallVec;
Expand Down Expand Up @@ -415,7 +415,7 @@ impl RawGenesisBlockBuilder {
/// be used to create assets and accounts.
pub fn domain(mut self, domain_name: Name) -> RawGenesisDomainBuilder {
let domain_id = DomainId::new(domain_name);
let new_domain = NewDomain::new(domain_id.clone());
let new_domain = Domain::new(domain_id.clone());
self.transaction
.isi
.push(Instruction::from(RegisterBox::new(new_domain)));
Expand Down Expand Up @@ -522,7 +522,7 @@ mod tests {
let domain_id: DomainId = "wonderland".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[0],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[1],
Expand All @@ -538,7 +538,7 @@ mod tests {
let domain_id: DomainId = "tulgey_wood".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[3],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[4],
Expand All @@ -549,7 +549,7 @@ mod tests {
let domain_id: DomainId = "meadow".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[5],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[6],
Expand Down
22 changes: 11 additions & 11 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl From<ParseError> for Error {
}
}

struct Validator<'a, W: WorldTrait> {
struct Validator<'va, W: WorldTrait> {
/// Number of instructions in the smartcontract
instruction_count: u64,
/// Max allowed number of instructions in the smartcontract
Expand All @@ -78,7 +78,7 @@ struct Validator<'a, W: WorldTrait> {
/// If this particular query is allowed
is_query_allowed: Arc<IsQueryAllowedBoxed<W>>,
/// Current [`WorldStateview`]
wsv: &'a WorldStateView<W>,
wsv: &'va WorldStateView<W>,
}

impl<W: WorldTrait> Validator<'_, W> {
Expand Down Expand Up @@ -125,16 +125,16 @@ impl<W: WorldTrait> Validator<'_, W> {
}
}

struct State<'a, W: WorldTrait> {
struct State<'wrld, W: WorldTrait> {
account_id: AccountId,
/// Ensures smartcontract adheres to limits
validator: Option<Validator<'a, W>>,
validator: Option<Validator<'wrld, W>>,
store_limits: StoreLimits,
wsv: &'a WorldStateView<W>,
wsv: &'wrld WorldStateView<W>,
}

impl<'a, W: WorldTrait> State<'a, W> {
fn new(wsv: &'a WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
impl<'wrld, W: WorldTrait> State<'wrld, W> {
fn new(wsv: &'wrld WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
Self {
wsv,
account_id,
Expand Down Expand Up @@ -171,13 +171,13 @@ impl<'a, W: WorldTrait> State<'a, W> {
}

/// `WebAssembly` virtual machine
pub struct Runtime<'a, W: WorldTrait> {
pub struct Runtime<'wrld, W: WorldTrait> {
engine: Engine,
linker: Linker<State<'a, W>>,
linker: Linker<State<'wrld, W>>,
config: Configuration,
}

impl<'a, W: WorldTrait> Runtime<'a, W> {
impl<'wrld, W: WorldTrait> Runtime<'wrld, W> {
/// `Runtime` constructor with default configuration.
///
/// # Errors
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a, W: WorldTrait> Runtime<'a, W> {
Ok(())
}

fn create_linker(engine: &Engine) -> Result<Linker<State<'a, W>>, Error> {
fn create_linker(engine: &Engine) -> Result<Linker<State<'wrld, W>>, Error> {
let mut linker = Linker::new(engine);

linker
Expand Down
4 changes: 2 additions & 2 deletions core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ impl VersionedMessage {
/// Send this message over the network to multiple `peers`.
/// # Errors
/// Fails if network sending fails
pub async fn send_to_multiple<'a, I>(self, broker: &Broker, peers: I)
pub async fn send_to_multiple<'itm, I>(self, broker: &Broker, peers: I)
where
I: IntoIterator<Item = &'a PeerId> + Send,
I: IntoIterator<Item = &'itm PeerId> + Send,
{
let futures = peers
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ impl Topology {
}

/// Returns signatures of the peers with the specified `roles` from all `signatures`.
pub fn filter_signatures_by_roles<'a>(
&'a self,
roles: &'a [Role],
signatures: impl IntoIterator<Item = &'a SignatureOf<VersionedValidBlock>> + 'a,
pub fn filter_signatures_by_roles<'slf>(
&'slf self,
roles: &'slf [Role],
signatures: impl IntoIterator<Item = &'slf SignatureOf<VersionedValidBlock>> + 'slf,
) -> Vec<SignatureOf<VersionedValidBlock>> {
let roles: HashSet<Role> = roles.iter().copied().collect();
let public_keys: HashSet<_> = roles
Expand Down Expand Up @@ -484,8 +484,8 @@ mod tests {
fn correct_number_of_peers_genesis() {
let peers = topology_test_peers();
// set_a.len() = 2, is wrong as it is not possible to get integer f in: 2f + 1 = 2
let set_a: HashSet<_> = topology_test_peers().iter().cloned().take(3).collect();
let set_b: HashSet<_> = topology_test_peers().iter().cloned().skip(3).collect();
let set_a: HashSet<_> = topology_test_peers().iter().take(3).cloned().collect();
let set_b: HashSet<_> = topology_test_peers().iter().skip(3).cloned().collect();
let _network_topology = GenesisBuilder::new()
.with_leader(peers.iter().next().unwrap().clone())
.with_set_a(set_a)
Expand Down
4 changes: 2 additions & 2 deletions core/src/triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl TriggerSet {
///
/// Users should not try to modify [`TriggerSet`] before dropping actions,
/// returned by the current function
pub fn find_matching<'e, E>(&self, events: E) -> Vec<Action>
pub fn find_matching<'evnt, E>(&self, events: E) -> Vec<Action>
where
E: IntoIterator<Item = &'e Event>,
E: IntoIterator<Item = &'evnt Event>,
{
let mut result = Vec::new();

Expand Down
13 changes: 9 additions & 4 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ use ursa::{
},
};


// Hiding constants is a bad idea. For one, you're forcing the user to
// create temporaries, but also you're not actually hiding any
// information that can be used in malicious ways. If you want to hide
// these, I'd prefer inlining them instead.
/// ed25519
const ED_25519: &str = "ed25519";
pub const ED_25519: &str = "ed25519";
/// secp256k1
const SECP_256_K1: &str = "secp256k1";
pub const SECP_256_K1: &str = "secp256k1";
/// bls normal
const BLS_NORMAL: &str = "bls_normal";
pub const BLS_NORMAL: &str = "bls_normal";
/// bls small
const BLS_SMALL: &str = "bls_small";
pub const BLS_SMALL: &str = "bls_small";

/// Error indicating algorithm could not be found
#[derive(Debug, Clone, Copy, Display, IntoSchema)]
Expand Down
Loading

0 comments on commit 659d74e

Please sign in to comment.