Skip to content

Commit

Permalink
feat!: authenticate personal accounts by ID
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

- change `AccountId` from "name@domain" to "multihash@domain"
- make account signatory single
- make transaction signature single
- remove query `FindAccountsByName`

closes issue #2085

Signed-off-by: Shunkichi Sato <[email protected]>
  • Loading branch information
s8sato authored and mversic committed May 14, 2024
1 parent a362b86 commit 7493bc2
Show file tree
Hide file tree
Showing 147 changed files with 1,524 additions and 2,987 deletions.
10 changes: 5 additions & 5 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
newline_style="Unix"
use_field_init_shorthand=true
format_code_in_doc_comments = true # unstable (https://github.com/rust-lang/rustfmt/issues/3348)
group_imports="StdExternalCrate" # unstable (https://github.com/rust-lang/rustfmt/issues/5083)
imports_granularity="Crate" # unstable (https://github.com/rust-lang/rustfmt/issues/4991)
newline_style = "Unix"
use_field_init_shorthand = true
format_code_in_doc_comments = true # unstable (https://github.com/rust-lang/rustfmt/issues/3348)
group_imports = "StdExternalCrate" # unstable (https://github.com/rust-lang/rustfmt/issues/5083)
imports_granularity = "Crate" # unstable (https://github.com/rust-lang/rustfmt/issues/4991)
17 changes: 17 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ iroha_executor_derive = { version = "=2.0.0-pre-rc.21", path = "smart_contract/e
iroha_trigger_derive = { version = "=2.0.0-pre-rc.21", path = "smart_contract/trigger/derive" }

test_network = { version = "=2.0.0-pre-rc.21", path = "core/test_network" }
test_samples = { version = "=2.0.0-pre-rc.21", path = "test_samples" }

proc-macro2 = "1.0.81"
syn = { version = "2.0.60", default-features = false }
quote = "1.0.36"
Expand Down Expand Up @@ -228,6 +230,7 @@ members = [
"smart_contract/executor",
"smart_contract/executor/derive",
"telemetry",
"test_samples",
"tools/kagami",
"tools/kura_inspector",
"tools/parity_scale_cli",
Expand Down
16 changes: 8 additions & 8 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,18 @@ impl Iroha {
}

fn genesis_account(public_key: PublicKey) -> Account {
Account::new(iroha_genesis::GENESIS_ACCOUNT_ID.clone(), public_key)
.build(&iroha_genesis::GENESIS_ACCOUNT_ID)
let genesis_account_id = AccountId::new(iroha_genesis::GENESIS_DOMAIN_ID.clone(), public_key);
Account::new(genesis_account_id.clone()).build(&genesis_account_id)
}

fn genesis_domain(public_key: PublicKey) -> Domain {
let mut domain = Domain::new(iroha_genesis::GENESIS_DOMAIN_ID.clone())
.build(&iroha_genesis::GENESIS_ACCOUNT_ID);
let genesis_account = genesis_account(public_key);
let mut domain =
Domain::new(iroha_genesis::GENESIS_DOMAIN_ID.clone()).build(&genesis_account.id);

domain.accounts.insert(
iroha_genesis::GENESIS_ACCOUNT_ID.clone(),
genesis_account(public_key),
);
domain
.accounts
.insert(genesis_account.id.clone(), genesis_account);

domain
}
Expand Down
25 changes: 16 additions & 9 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,24 @@ pub fn get_trusted_peers(public_key: Option<&PublicKey>) -> HashSet<PeerId> {
pub fn get_user_config(
peers: &UniqueVec<PeerId>,
chain_id: Option<ChainId>,
key_pair: Option<KeyPair>,
peer_key_pair: Option<KeyPair>,
genesis_key_pair: Option<KeyPair>,
) -> UserConfig {
let chain_id = chain_id.unwrap_or_else(|| ChainId::from("0"));

let (public_key, private_key) = key_pair.unwrap_or_else(KeyPair::random).into_parts();
iroha_logger::info!(%public_key);
let (peer_public_key, peer_private_key) =
peer_key_pair.unwrap_or_else(KeyPair::random).into_parts();
iroha_logger::info!(%peer_public_key);
let (genesis_public_key, genesis_private_key) = genesis_key_pair
.unwrap_or_else(KeyPair::random)
.into_parts();
iroha_logger::info!(%genesis_public_key);

let mut config = UserConfig::new();

config.chain_id.set(chain_id);
config.public_key.set(public_key.clone());
config.private_key.set(private_key.clone());
config.public_key.set(peer_public_key);
config.private_key.set(peer_private_key);
config.network.address.set(DEFAULT_P2P_ADDR);
config
.chain_wide
Expand All @@ -89,8 +95,8 @@ pub fn get_user_config(
.network
.block_gossip_period
.set(HumanDuration(Duration::from_millis(500)));
config.genesis.private_key.set(private_key);
config.genesis.public_key.set(public_key);
config.genesis.private_key.set(genesis_private_key);
config.genesis.public_key.set(genesis_public_key);
config.genesis.file.set("./genesis.json".into());
// There is no need in persistency in tests
// If required to should be set explicitly not to overlap with other existing tests
Expand All @@ -109,9 +115,10 @@ pub fn get_user_config(
pub fn get_config(
trusted_peers: &UniqueVec<PeerId>,
chain_id: Option<ChainId>,
key_pair: Option<KeyPair>,
peer_key_pair: Option<KeyPair>,
genesis_key_pair: Option<KeyPair>,
) -> Config {
get_user_config(trusted_peers, chain_id, key_pair)
get_user_config(trusted_peers, chain_id, peer_key_pair, genesis_key_pair)
.unwrap_partial()
.expect("config should build as all required fields were provided")
.parse(CliContext {
Expand Down
1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ iroha_logger = { workspace = true }
iroha_telemetry = { workspace = true }
iroha_torii_const = { workspace = true }
iroha_version = { workspace = true, features = ["http"] }
test_samples = { workspace = true }

attohttpc = { version = "0.28.0", default-features = false }
eyre = { workspace = true }
Expand Down
40 changes: 17 additions & 23 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use iroha::samples::{construct_executor, get_config};
use iroha_client::{
client::{asset, Client},
crypto::KeyPair,
data_model::prelude::*,
};
use iroha_genesis::{GenesisNetwork, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use iroha_version::Encode;
use test_network::{get_chain_id, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime};
use test_samples::gen_account_in;
use tokio::runtime::Runtime;

const MINIMUM_SUCCESS_REQUEST_RATIO: f32 = 0.9;
Expand All @@ -24,17 +24,15 @@ fn query_requests(criterion: &mut Criterion) {
let configuration = get_config(
&unique_vec![peer.id.clone()],
Some(chain_id.clone()),
Some(get_key_pair()),
Some(get_key_pair(test_network::Signatory::Peer)),
Some(get_key_pair(test_network::Signatory::Genesis)),
);

let rt = Runtime::test();
let genesis = GenesisNetwork::new(
RawGenesisBlockBuilder::default()
.domain("wonderland".parse().expect("Valid"))
.account(
"alice".parse().expect("Valid"),
get_key_pair().public_key().clone(),
)
.account(get_key_pair(test_network::Signatory::Alice).into_parts().0)
.finish_domain()
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
Expand All @@ -60,11 +58,10 @@ fn query_requests(criterion: &mut Criterion) {
});
let mut group = criterion.benchmark_group("query-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain = Register::domain(Domain::new(domain_id.clone()));
let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid"));
let (public_key, _) = KeyPair::random().into_parts();
let create_account = Register::account(Account::new(account_id.clone(), public_key));
let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid"));
let create_domain = Register::domain(Domain::new(domain_id));
let (account_id, _account_keypair) = gen_account_in("domain");
let create_account = Register::account(Account::new(account_id.clone()));
let asset_definition_id: AssetDefinitionId = "xor#domain".parse().expect("Valid");
let create_asset =
Register::asset_definition(AssetDefinition::numeric(asset_definition_id.clone()));
let mint_asset = Mint::asset_numeric(
Expand All @@ -73,7 +70,7 @@ fn query_requests(criterion: &mut Criterion) {
);
let client_config = iroha_client::samples::get_client_config(
get_chain_id(),
get_key_pair(),
get_key_pair(test_network::Signatory::Alice),
format!("http://{}", peer.api_address).parse().unwrap(),
);

Expand Down Expand Up @@ -132,15 +129,13 @@ fn instruction_submits(criterion: &mut Criterion) {
let configuration = get_config(
&unique_vec![peer.id.clone()],
Some(chain_id.clone()),
Some(get_key_pair()),
Some(get_key_pair(test_network::Signatory::Peer)),
Some(get_key_pair(test_network::Signatory::Genesis)),
);
let genesis = GenesisNetwork::new(
RawGenesisBlockBuilder::default()
.domain("wonderland".parse().expect("Valid"))
.account(
"alice".parse().expect("Valid"),
configuration.common.key_pair.public_key().clone(),
)
.account(configuration.common.key_pair.public_key().clone())
.finish_domain()
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
Expand All @@ -158,14 +153,13 @@ fn instruction_submits(criterion: &mut Criterion) {
rt.block_on(builder.start_with_peer(&mut peer));
let mut group = criterion.benchmark_group("instruction-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id.clone())).into();
let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid"));
let (public_key, _) = KeyPair::random().into_parts();
let create_account = Register::account(Account::new(account_id.clone(), public_key)).into();
let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid"));
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id)).into();
let (account_id, _account_keypair) = gen_account_in("domain");
let create_account = Register::account(Account::new(account_id.clone())).into();
let asset_definition_id: AssetDefinitionId = "xor#domain".parse().expect("Valid");
let client_config = iroha_client::samples::get_client_config(
get_chain_id(),
get_key_pair(),
get_key_pair(test_network::Signatory::Alice),
format!("http://{}", peer.api_address).parse().unwrap(),
);
let iroha_client = Client::new(client_config);
Expand Down
34 changes: 15 additions & 19 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{fmt, fs::File, io::BufReader, path::Path, str::FromStr as _, sync::mpsc, thread, time};
use std::{fmt, fs::File, io::BufReader, path::Path, sync::mpsc, thread, time};

use eyre::{Result, WrapErr};
use iroha_client::{
client::Client,
crypto::KeyPair,
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
Expand All @@ -12,6 +13,7 @@ use iroha_data_model::events::pipeline::{BlockEventFilter, BlockStatus};
use nonzero_ext::nonzero;
use serde::Deserialize;
use test_network::*;
use test_samples::ALICE_ID;

pub type Tps = f64;

Expand Down Expand Up @@ -68,6 +70,7 @@ impl Config {
config: self,
client,
name,
signatory: KeyPair::random().into_parts().0,
};
unit.ready()
})
Expand Down Expand Up @@ -136,6 +139,7 @@ struct MeasurerUnit {
pub config: Config,
pub client: Client,
pub name: UnitName,
pub signatory: PublicKey,
}

type UnitName = u32;
Expand All @@ -146,15 +150,10 @@ impl MeasurerUnit {

/// Submit initial transactions for measurement
fn ready(self) -> Result<Self> {
let keypair = iroha_client::crypto::KeyPair::random();

let account_id = account_id(self.name);
let asset_id = asset_id(self.name);

let register_me = Register::account(Account::new(account_id, keypair.public_key().clone()));
let register_me = Register::account(Account::new(self.account_id()));
self.client.submit_blocking(register_me)?;

let mint_a_rose = Mint::asset_numeric(1_u32, asset_id);
let mint_a_rose = Mint::asset_numeric(1_u32, self.asset_id());
self.client.submit_blocking(mint_a_rose)?;

Ok(self)
Expand Down Expand Up @@ -193,7 +192,7 @@ impl MeasurerUnit {
let submitter = self.client.clone();
let interval_us_per_tx = self.config.interval_us_per_tx;
let instructions = self.instructions();
let alice_id = AccountId::from_str("alice@wonderland").expect("Failed to parse account id");
let alice_id = ALICE_ID.clone();

let mut nonce = nonzero!(1_u32);

Expand Down Expand Up @@ -231,17 +230,14 @@ impl MeasurerUnit {
}

fn mint(&self) -> InstructionBox {
Mint::asset_numeric(1_u32, asset_id(self.name)).into()
Mint::asset_numeric(1_u32, self.asset_id()).into()
}
}

fn asset_id(account_name: UnitName) -> AssetId {
AssetId::new(
"rose#wonderland".parse().expect("Valid"),
account_id(account_name),
)
}
fn account_id(&self) -> AccountId {
AccountId::new("wonderland".parse().expect("Valid"), self.signatory.clone())
}

fn account_id(name: UnitName) -> AccountId {
format!("{name}@wonderland").parse().expect("Valid")
fn asset_id(&self) -> AssetId {
AssetId::new("rose#wonderland".parse().expect("Valid"), self.account_id())
}
}
Loading

0 comments on commit 7493bc2

Please sign in to comment.