Skip to content

Commit

Permalink
[feature] #2085: Authenticate personal accounts by ID
Browse files Browse the repository at this point in the history
Signed-off-by: Shunkichi Sato <[email protected]>
  • Loading branch information
s8sato committed Apr 4, 2024
1 parent bc6be98 commit 5fcf972
Show file tree
Hide file tree
Showing 127 changed files with 1,372 additions and 2,506 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ iroha_data_model_derive = { version = "=2.0.0-pre-rc.20", path = "data_model/der
iroha_client = { version = "=2.0.0-pre-rc.20", path = "client" }
iroha_config = { version = "=2.0.0-pre-rc.20", path = "config" }
iroha_config_base = { version = "=2.0.0-pre-rc.20", path = "config/base" }
iroha_sample_params = { version = "=2.0.0-pre-rc.20", path = "configs/sample_params" }
iroha_schema_gen = { version = "=2.0.0-pre-rc.20", path = "schema/gen" }
iroha_schema = { version = "=2.0.0-pre-rc.20", path = "schema", default-features = false }
iroha_schema_derive = { version = "=2.0.0-pre-rc.20", path = "schema/derive" }
Expand Down Expand Up @@ -242,6 +243,7 @@ members = [
"wasm_codec",
"wasm_codec/derive",
"wasm_builder",
"configs/sample_params",
]

[profile.deploy]
Expand Down
18 changes: 7 additions & 11 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ impl Iroha {
.wrap_err("Unable to start P2P-network")?;

let (events_sender, _) = broadcast::channel(10000);
let world = World::with(
[genesis_domain(config.genesis.public_key().clone())],
config.sumeragi.trusted_peers.clone(),
);
let world = World::with([genesis_domain()], config.sumeragi.trusted_peers.clone());

let kura = Kura::new(&config.kura)?;
let live_query_store_handle = LiveQueryStore::from_config(config.live_query_store).start();
Expand Down Expand Up @@ -472,19 +469,18 @@ impl Iroha {
}
}

fn genesis_account(public_key: PublicKey) -> Account {
Account::new(iroha_genesis::GENESIS_ACCOUNT_ID.clone(), public_key)
fn genesis_account() -> Account {
Account::new(iroha_genesis::GENESIS_ACCOUNT_ID.clone())
.build(&iroha_genesis::GENESIS_ACCOUNT_ID)
}

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

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

domain
}
Expand Down
26 changes: 17 additions & 9 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,25 @@ 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);
// TODO remove "genesis account" #4409
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 +96,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 +116,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 @@ -53,6 +53,7 @@ iroha_crypto = { workspace = true }
iroha_data_model = { workspace = true, features = ["http"] }
iroha_primitives = { workspace = true }
iroha_logger = { workspace = true }
iroha_sample_params = { workspace = true }
iroha_telemetry = { workspace = true }
iroha_torii_const = { workspace = true }
iroha_version = { workspace = true, features = ["http"] }
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,11 +6,11 @@ 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_sample_params::alias::Alias;
use iroha_version::Encode;
use test_network::{get_chain_id, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime};
use tokio::runtime::Runtime;
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: AccountId = "account@domain".parse_alias();
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: AccountId = "account@domain".parse_alias();
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,4 +1,4 @@
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::{
Expand All @@ -8,7 +8,9 @@ use iroha_client::{
prelude::*,
},
};
use iroha_crypto::KeyPair;
use iroha_data_model::events::pipeline::{BlockEventFilter, BlockStatus};
use iroha_sample_params::alias::Alias;
use nonzero_ext::nonzero;
use serde::Deserialize;
use test_network::*;
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: AccountId = "alice@wonderland".parse_alias();

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 5fcf972

Please sign in to comment.