Skip to content

Commit

Permalink
Remove roles feature
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix authored and SamHSmith committed Apr 22, 2022
1 parent 81f46bb commit 9ac0528
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 95 deletions.
2 changes: 0 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ default = ["bridge", "telemetry", "schema-endpoint"]

bridge = ["iroha_core/bridge"]
dex = ["iroha_core/dex"]
# Include support for account roles
roles = ["iroha_core/roles", "iroha_permissions_validators/roles"]
telemetry = ["iroha_telemetry", "iroha_core/telemetry"]
dev-telemetry = ["iroha_core/dev-telemetry", "iroha_telemetry"]
schema-endpoint = ["iroha_schema_bin"]
Expand Down
4 changes: 2 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ the results of the compilation can be found in `<IROHA REPO ROOT>/target/release

### Adding features

To add optional features, e.g. support for _roles_, compile with
To add optional features, e.g. support for _bridge_, compile with

```bash
cargo build --release --features roles
cargo build --release --features bridge
```

A full list of features can be found in the [cargo manifest file](Cargo.toml) of this repository.
Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ maintenance = { status = "actively-developed" }
[dependencies]
iroha_config = { version = "=2.0.0-pre-rc.3", path = "../config" }
iroha_crypto = { version = "=2.0.0-pre-rc.3", path = "../crypto"}
iroha_data_model = { version = "=2.0.0-pre-rc.3", path = "../data_model", features = ["warp", "roles"] }
iroha_data_model = { version = "=2.0.0-pre-rc.3", path = "../data_model", features = ["warp"] }
iroha_logger = { version = "=2.0.0-pre-rc.3", path = "../logger"}
iroha_telemetry = { version ="=2.0.0-pre-rc.3", path = "../telemetry" }
iroha_version = { version = "=2.0.0-pre-rc.3", path = "../version" }
Expand Down
4 changes: 1 addition & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ keywords = ["crypto", "blockchain", "ledger"]
categories = ["cryptography::cryptocurrencies"]

[features]
default = ["bridge", "cli", "telemetry", "roles"]
default = ["bridge", "cli", "telemetry"]

bridge = []
# Include support for account roles
roles = ["iroha_data_model/roles"]
telemetry = []
cli = []
dex = []
Expand Down
4 changes: 1 addition & 3 deletions core/docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ edition = "2021"

# Explanation: You want the option to remove configuration docs if you distribute e.g. a `deb`, but want the person who just cloned the repo to be able to see at a glance what kinds of features are accessible to them, what they do and how to use them. #1975 should be fixed soon.
[features]
default = ["roles", "dex", "telemetry", "dev-telemetry"]
# Include support for account roles
roles = ["iroha_core/roles"]
default = ["dex", "telemetry", "dev-telemetry"]
dex = ["iroha_core/dex"]
telemetry = ["iroha_core/telemetry"]
dev-telemetry = ["iroha_core/dev-telemetry"]
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub type PeersIds = dashmap::DashSet<PeerId>;
pub type DomainsMap = dashmap::DashMap<DomainId, Domain>;

/// `RolesMap` provides an API to work with collection of key(`PeerId`) - value(`Role`) pairs.
#[cfg(feature = "roles")]
pub type RolesMap = dashmap::DashMap<RoleId, Role>;

/// Type of `Sender<Event>` which should be used for channels of `Event` messages.
Expand Down
3 changes: 0 additions & 3 deletions core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ pub mod isi {
}
}

#[cfg(feature = "roles")]
impl<W: WorldTrait> Execute<W> for Grant<Account, RoleId> {
type Error = Error;

Expand Down Expand Up @@ -209,7 +208,6 @@ pub mod isi {
}
}

#[cfg(feature = "roles")]
impl<W: WorldTrait> Execute<W> for Revoke<Account, RoleId> {
type Error = Error;

Expand Down Expand Up @@ -247,7 +245,6 @@ pub mod query {
use super::{super::Evaluate, *};
use crate::smartcontracts::{isi::prelude::WorldTrait, query::Error, FindError};

#[cfg(feature = "roles")]
impl<W: WorldTrait> ValidQuery<W> for FindRolesByAccountId {
#[log]
#[metrics(+"find_roles_by_account_id")]
Expand Down
4 changes: 0 additions & 4 deletions core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ pub mod error {
#[error("Trigger not found.")]
Trigger(TriggerId),
/// Failed to find Role by id.
#[cfg(feature = "roles")]
#[error("Failed to find role by id: `{0}`")]
Role(RoleId),
}
Expand Down Expand Up @@ -318,7 +317,6 @@ impl<W: WorldTrait> Execute<W> for RegisterBox {
RegistrableBox::Trigger(trigger) => {
Register::<Trigger>::new(*trigger).execute(authority, wsv)
}
#[cfg(feature = "roles")]
RegistrableBox::Role(role) => Register::<Role>::new(*role).execute(authority, wsv),
_ => Err(Error::Unsupported(InstructionType::Register)),
}
Expand Down Expand Up @@ -581,7 +579,6 @@ impl<W: WorldTrait> Execute<W> for GrantBox {
Grant::<Account, PermissionToken>::new(permission_token, account_id)
.execute(authority, wsv)
}
#[cfg(feature = "roles")]
(IdBox::AccountId(account_id), Value::Id(IdBox::RoleId(role_id))) => {
Grant::<Account, RoleId>::new(role_id, account_id).execute(authority, wsv)
}
Expand All @@ -608,7 +605,6 @@ impl<W: WorldTrait> Execute<W> for RevokeBox {
Revoke::<Account, PermissionToken>::new(permission_token, account_id)
.execute(authority, wsv)
}
#[cfg(feature = "roles")]
(IdBox::AccountId(account_id), Value::Id(IdBox::RoleId(role_id))) => {
Revoke::<Account, RoleId>::new(role_id, account_id).execute(authority, wsv)
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/smartcontracts/isi/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{iter, sync::Arc};
use eyre::Result;
use iroha_data_model::{isi::RevokeBox, prelude::*};

#[cfg(feature = "roles")]
use super::Evaluate;
use crate::wsv::{WorldStateView, WorldTrait};

Expand Down Expand Up @@ -693,7 +692,6 @@ impl<W: WorldTrait> From<IsRevokeAllowedBoxed<W>> for IsInstructionAllowedBoxed<
///
/// # Errors
/// Evaluation failure of instruction fields.
#[cfg(feature = "roles")]
fn unpack_if_role_grant<W: WorldTrait>(
instruction: Instruction,
wsv: &WorldStateView<W>,
Expand Down Expand Up @@ -734,7 +732,6 @@ fn unpack_if_role_grant<W: WorldTrait>(
///
/// # Errors
/// Evaluation failure of each of the instruction fields.
#[cfg(feature = "roles")]
pub fn unpack_if_role_revoke<W: WorldTrait>(
instruction: Instruction,
wsv: &WorldStateView<W>,
Expand Down Expand Up @@ -775,11 +772,8 @@ pub fn check_instruction_permissions<W: WorldTrait>(
is_query_allowed: &IsQueryAllowedBoxed<W>,
wsv: &WorldStateView<W>,
) -> Result<(), TransactionRejectionReason> {
#[cfg(feature = "roles")]
let granted_instructions = &unpack_if_role_grant(instruction.clone(), wsv)
.expect("Infallible. Evaluations have been checked by instruction execution.");
#[cfg(not(feature = "roles"))]
let granted_instructions = std::iter::once(instruction);

for isi in granted_instructions {
is_instruction_allowed
Expand Down
2 changes: 0 additions & 2 deletions core/src/smartcontracts/isi/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ impl<W: WorldTrait> ValidQuery<W> for QueryBox {
FindTransactionByHash(query) => query.execute_into_value(wsv),
FindPermissionTokensByAccountId(query) => query.execute_into_value(wsv),
FindAssetDefinitionKeyValueByIdAndKey(query) => query.execute_into_value(wsv),
#[cfg(feature = "roles")]
FindAllRoles(query) => query.execute_into_value(wsv),
#[cfg(feature = "roles")]
FindRolesByAccountId(query) => query.execute_into_value(wsv),
}
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/smartcontracts/isi/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pub mod isi {
}
}

#[cfg(feature = "roles")]
impl<W: WorldTrait> Execute<W> for Register<Role> {
type Error = Error;

Expand Down Expand Up @@ -141,7 +140,6 @@ pub mod isi {
}
}

#[cfg(feature = "roles")]
impl<W: WorldTrait> Execute<W> for Unregister<Role> {
type Error = Error;

Expand Down Expand Up @@ -202,7 +200,6 @@ pub mod query {
use super::*;
use crate::smartcontracts::query::Error;

#[cfg(feature = "roles")]
impl<W: WorldTrait> ValidQuery<W> for FindAllRoles {
#[log]
fn execute(&self, wsv: &WorldStateView<W>) -> Result<Self::Output, Error> {
Expand Down
3 changes: 0 additions & 3 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub struct World {
/// Registered domains.
pub domains: DomainsMap,
/// Roles. [`Role`] pairs.
#[cfg(feature = "roles")]
pub roles: crate::RolesMap,
/// Triggers
pub triggers: TriggerSet,
Expand Down Expand Up @@ -183,7 +182,6 @@ impl<W: WorldTrait> WorldStateView<W> {
#[allow(unused_mut)]
let mut tokens: Vec<PermissionToken> = account.permissions().cloned().collect();

#[cfg(feature = "roles")]
for role_id in account.roles() {
if let Some(role) = self.world.roles.get(role_id) {
tokens.append(&mut role.permissions().cloned().collect());
Expand Down Expand Up @@ -467,7 +465,6 @@ impl<W: WorldTrait> WorldStateView<W> {
cur_events.push(DataEvent::Domain(domain_event).into());
}
WorldEvent::Peer(peer_event) => cur_events.push(DataEvent::Peer(peer_event).into()),
#[cfg(feature = "roles")]
WorldEvent::Role(role_event) => cur_events.push(DataEvent::Role(role_event).into()),
WorldEvent::Trigger(trigger_event) => {
cur_events.push(DataEvent::Trigger(trigger_event).into())
Expand Down
6 changes: 2 additions & 4 deletions data_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/ir
maintenance = { status = "actively-developed" }

[features]
default = ["std", "roles"]
default = ["std"]
# Enable static linkage of the rust standard library.
# Disabled for WASM interoperability, to reduce the binary size.
# Please refer to https://docs.rust-embedded.org/book/intro/no-std.html
std = ["iroha_macro/std", "iroha_version/std", "iroha_version/warp", "iroha_crypto/std", "iroha_data_primitives/std", "thiserror"]
# Include support for account roles (FIXME: https://github.com/hyperledger/iroha/issues/2111)
roles = []

# Internal use only
mutable_api = []
Expand All @@ -44,7 +42,7 @@ thiserror = { version = "1.0.28", optional = true }
getset = "0.1.2"

[dev-dependencies]
iroha_core = { path = "../core", version = "=2.0.0-pre-rc.3", features = ["roles"] }
iroha_core = { path = "../core", version = "=2.0.0-pre-rc.3" }
iroha_client = { path = "../client", version = "=2.0.0-pre-rc.3" }
iroha = { path = "../cli" }

Expand Down
9 changes: 1 addition & 8 deletions data_model/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ use iroha_schema::IntoSchema;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

#[cfg(feature = "roles")]
use crate::role::{prelude::RoleId, RoleIds};
use crate::{
asset::{prelude::AssetId, AssetsMap},
domain::prelude::*,
expression::{ContainsAny, ContextValue, EvaluatesTo},
metadata::Metadata,
permissions::{PermissionToken, Permissions},
prelude::Asset,
role::{prelude::RoleId, RoleIds},
Identifiable, Name, ParseError, PublicKey,
};

Expand Down Expand Up @@ -159,7 +158,6 @@ impl NewAccount {
permission_tokens: Permissions::default(),
signature_check_condition: SignatureCheckCondition::default(),
metadata: self.metadata,
#[cfg(feature = "roles")]
roles: RoleIds::default(),
}
}
Expand Down Expand Up @@ -202,7 +200,6 @@ pub struct Account {
metadata: Metadata,
/// Roles of this account, they are tags for sets of permissions stored in `World`.
#[getset(skip)]
#[cfg(feature = "roles")]
roles: RoleIds,
}

Expand Down Expand Up @@ -273,14 +270,12 @@ impl Account {

/// Return `true` if `Account` contains role
#[inline]
#[cfg(feature = "roles")]
pub fn contains_role(&self, role_id: &RoleId) -> bool {
self.roles.contains(role_id)
}

/// Get an iterator over [`role ids`](RoleId) of the `Account`
#[inline]
#[cfg(feature = "roles")]
pub fn roles(&self) -> impl ExactSizeIterator<Item = &RoleId> {
self.roles.iter()
}
Expand Down Expand Up @@ -341,14 +336,12 @@ impl Account {
/// If `Account` did not have this role present, `true` is returned.
/// If `Account` did have this role present, `false` is returned.
#[inline]
#[cfg(feature = "roles")]
pub fn add_role(&mut self, role_id: RoleId) -> bool {
self.roles.insert(role_id)
}

/// Remove a role from the `Account` and return whether the role was present in the `Account`
#[inline]
#[cfg(feature = "roles")]
pub fn remove_role(&mut self, role_id: &RoleId) -> bool {
self.roles.remove(role_id)
}
Expand Down
6 changes: 1 addition & 5 deletions data_model/src/events/data/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ mod peer {
}
}

#[cfg(feature = "roles")]
mod role {
//! This module contains `RoleEvent` and its impls
Expand Down Expand Up @@ -233,7 +232,6 @@ mod trigger {
pub enum WorldEvent {
Peer(peer::PeerEvent),
Domain(domain::DomainEvent),
#[cfg(feature = "roles")]
Role(role::RoleEvent),
Trigger(trigger::TriggerEvent),
}
Expand All @@ -256,18 +254,16 @@ pub enum Event {
/// Trigger event
Trigger(trigger::TriggerEvent),
/// Role event
#[cfg(feature = "roles")]
Role(role::RoleEvent),
}

pub mod prelude {
#[cfg(feature = "roles")]
pub use super::role::RoleEvent;
pub use super::{
account::AccountEvent,
asset::{AssetDefinitionEvent, AssetEvent},
domain::DomainEvent,
peer::PeerEvent,
role::RoleEvent,
trigger::TriggerEvent,
Event as DataEvent, WorldEvent,
};
Expand Down
6 changes: 1 addition & 5 deletions data_model/src/events/data/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ macro_rules! entity_filter {
};
}

#[cfg(feature = "roles")]
mod role {
//! This module contains filters related to `RoleEvent`
Expand Down Expand Up @@ -622,7 +621,6 @@ pub enum EntityFilter {
/// Filter by Trigger entity. `AcceptAll` value will accept all `Trigger` events
ByTrigger(FilterOpt<TriggerFilter>),
/// Filter by Role entity. `AcceptAll` value will accept all `Role` events
#[cfg(feature = "roles")]
ByRole(FilterOpt<RoleFilter>),
}

Expand All @@ -638,7 +636,6 @@ impl Filter for EntityFilter {
filter_opt.matches(asset_definition)
}
(Self::ByAsset(filter_opt), Event::Asset(asset)) => filter_opt.matches(asset),
#[cfg(feature = "roles")]
(Self::ByRole(filter_opt), Event::Role(role)) => filter_opt.matches(role),
_ => false,
}
Expand Down Expand Up @@ -680,13 +677,12 @@ impl<Id: Eq> Filter for IdFilter<Id> {
}

pub mod prelude {
#[cfg(feature = "roles")]
pub use super::role::{RoleEventFilter, RoleFilter};
pub use super::{
account::{AccountEventFilter, AccountFilter},
asset::{AssetDefinitionEventFilter, AssetDefinitionFilter, AssetEventFilter, AssetFilter},
domain::{DomainEventFilter, DomainFilter},
peer::{PeerEventFilter, PeerFilter},
role::{RoleEventFilter, RoleFilter},
trigger::{TriggerEventFilter, TriggerFilter},
EntityFilter as DataEntityFilter, EventFilter as DataEventFilter,
FilterOpt::{self, *},
Expand Down
Loading

0 comments on commit 9ac0528

Please sign in to comment.