Skip to content

Commit

Permalink
refactor: Make domain structure shallow
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
  • Loading branch information
SamHSmith committed Jun 15, 2024
1 parent 5214a6a commit 343cfce
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 349 deletions.
5 changes: 2 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl Iroha {
let (events_sender, _) = broadcast::channel(10000);
let world = World::with(
[genesis_domain(config.genesis.public_key.clone())],
[genesis_account(config.genesis.public_key.clone())],
config
.sumeragi
.trusted_peers
Expand Down Expand Up @@ -557,9 +558,7 @@ fn genesis_domain(public_key: PublicKey) -> Domain {
let mut domain =
Domain::new(iroha_genesis::GENESIS_DOMAIN_ID.clone()).build(&genesis_account.id);

domain
.accounts
.insert(genesis_account.id.clone(), genesis_account);
domain.accounts.insert(genesis_account.id.clone());

domain
}
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
190 changes: 0 additions & 190 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
@@ -1,190 +0,0 @@
{
"instructions": [
{
"Register": {
"Domain": {
"id": "wonderland",
"logo": null,
"metadata": {
"key": {
"String": "value"
}
}
}
}
},
{
"Register": {
"Account": {
"id": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland",
"metadata": {
"key": {
"String": "value"
}
}
}
}
},
{
"Register": {
"Account": {
"id": "ed012004FF5B81046DDCCF19E2E451C45DFB6F53759D4EB30FA2EFA807284D1CC33016@wonderland",
"metadata": {
"key": {
"String": "value"
}
}
}
}
},
{
"Register": {
"AssetDefinition": {
"id": "rose#wonderland",
"value_type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
}
}
},
{
"Register": {
"Domain": {
"id": "garden_of_live_flowers",
"logo": null,
"metadata": {}
}
}
},
{
"Register": {
"Account": {
"id": "ed0120E9F632D3034BAB6BB26D92AC8FD93EF878D9C5E69E01B61B4C47101884EE2F99@garden_of_live_flowers",
"metadata": {}
}
}
},
{
"Register": {
"AssetDefinition": {
"id": "cabbage#garden_of_live_flowers",
"value_type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
}
}
},
{
"Mint": {
"Asset": {
"object": "13",
"destination": "rose##ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
},
{
"Mint": {
"Asset": {
"object": "44",
"destination": "cabbage#garden_of_live_flowers#ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
},
{
"Transfer": {
"AssetDefinition": {
"source": "ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4@genesis",
"object": "rose#wonderland",
"destination": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
},
{
"Transfer": {
"Domain": {
"source": "ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4@genesis",
"object": "wonderland",
"destination": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
},
{
"Grant": {
"Permission": {
"object": {
"id": "CanSetParameters",
"payload": null
},
"destination": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
},
{
"NewParameter": "?MaxTransactionsInBlock=512"
},
{
"NewParameter": "?BlockTime=2000"
},
{
"NewParameter": "?CommitTimeLimit=4000"
},
{
"NewParameter": "?TransactionLimits=4096,4194304_TL"
},
{
"NewParameter": "?WSVDomainMetadataLimits=1048576,4096_ML"
},
{
"NewParameter": "?WSVAssetDefinitionMetadataLimits=1048576,4096_ML"
},
{
"NewParameter": "?WSVAccountMetadataLimits=1048576,4096_ML"
},
{
"NewParameter": "?WSVAssetMetadataLimits=1048576,4096_ML"
},
{
"NewParameter": "?WSVTriggerMetadataLimits=1048576,4096_ML"
},
{
"NewParameter": "?WSVIdentLengthLimits=1,128_LL"
},
{
"NewParameter": "?ExecutorFuelLimit=55000000"
},
{
"NewParameter": "?ExecutorMaxMemory=524288000"
},
{
"NewParameter": "?WASMFuelLimit=55000000"
},
{
"NewParameter": "?WASMMaxMemory=524288000"
},
{
"Register": {
"Role": {
"id": "ALICE_METADATA_ACCESS",
"permissions": [
{
"id": "CanRemoveKeyValueInAccount",
"payload": {
"account_id": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
},
{
"id": "CanSetKeyValueInAccount",
"payload": {
"account_id": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
]
}
}
}
],
"executor": "./executor.wasm",
"chain": "00000000-0000-0000-0000-000000000000"
}
13 changes: 9 additions & 4 deletions core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,16 @@ pub fn build_state(rt: &tokio::runtime::Handle, account_id: &AccountId) -> State
LiveQueryStore::test().start()
};
let mut domain = Domain::new(account_id.domain().clone()).build(account_id);
domain.accounts.insert(
account_id.clone(),
Account::new(account_id.clone()).build(account_id),
domain.accounts.insert(account_id.clone());
let state = State::new(
World::with(
[domain],
[Account::new(account_id.clone()).build(account_id)],
UniqueVec::new(),
),
kura,
query_handle,
);
let state = State::new(World::with([domain], UniqueVec::new()), kura, query_handle);

{
let mut state_block = state.block();
Expand Down
16 changes: 8 additions & 8 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ mod tests {
let account = Account::new(alice_id.clone()).build(&alice_id);
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let mut domain = Domain::new(domain_id).build(&alice_id);
assert!(domain.add_account(account).is_none());
let world = World::with([domain], UniqueVec::new());
assert!(domain.add_account(account.id().clone()) == false);
let world = World::with([domain], [account], UniqueVec::new());
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down Expand Up @@ -1000,8 +1000,8 @@ mod tests {
let account = Account::new(alice_id.clone()).build(&alice_id);
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let mut domain = Domain::new(domain_id).build(&alice_id);
assert!(domain.add_account(account).is_none());
let world = World::with([domain], UniqueVec::new());
assert!(domain.add_account(account.id().clone()) == false);
let world = World::with([domain], [account], UniqueVec::new());
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down Expand Up @@ -1076,10 +1076,10 @@ mod tests {
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let mut domain = Domain::new(domain_id).build(&alice_id);
assert!(
domain.add_account(account).is_none(),
domain.add_account(account.id().clone()) == false,
"{alice_id} already exist in the blockchain"
);
let world = World::with([domain], UniqueVec::new());
let world = World::with([domain], [account], UniqueVec::new());
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down Expand Up @@ -1161,8 +1161,8 @@ mod tests {
Domain::new(GENESIS_DOMAIN_ID.clone()).build(&genesis_correct_account_id);
let genesis_wrong_account =
Account::new(genesis_wrong_account_id.clone()).build(&genesis_wrong_account_id);
assert!(genesis_domain.add_account(genesis_wrong_account).is_none(),);
let world = World::with([genesis_domain], UniqueVec::new());
assert!(genesis_domain.add_account(genesis_wrong_account.id().clone()) == false,);
let world = World::with([genesis_domain], [genesis_wrong_account], UniqueVec::new());
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down
10 changes: 5 additions & 5 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ pub mod tests {
let (account_id, _account_keypair) = gen_account_in("wonderland");
let mut domain = Domain::new(domain_id).build(&account_id);
let account = Account::new(account_id.clone()).build(&account_id);
assert!(domain.add_account(account).is_none());
World::with([domain], PeersIds::new())
assert!(domain.add_account(account_id.clone()) == false);
World::with([domain], [account], PeersIds::new())
}

fn config_factory() -> Config {
Expand Down Expand Up @@ -836,9 +836,9 @@ pub mod tests {
let mut domain = Domain::new(domain_id).build(&alice_id);
let alice_account = Account::new(alice_id.clone()).build(&alice_id);
let bob_account = Account::new(bob_id.clone()).build(&bob_id);
assert!(domain.add_account(alice_account).is_none());
assert!(domain.add_account(bob_account).is_none());
World::with([domain], PeersIds::new())
assert!(domain.add_account(alice_account.id().clone()) == false);
assert!(domain.add_account(bob_account.id().clone()) == false);
World::with([domain], [alice_account, bob_account], PeersIds::new())
};
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down
32 changes: 20 additions & 12 deletions core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,7 @@ pub mod query {
&self,
state_ro: &'state impl StateReadOnly,
) -> Result<Box<dyn Iterator<Item = Account> + 'state>, Error> {
Ok(Box::new(
state_ro
.world()
.domains_iter()
.flat_map(|domain| domain.accounts.values())
.cloned(),
))
Ok(Box::new(state_ro.world().accounts_iter().cloned()))
}
}

Expand All @@ -561,6 +555,10 @@ pub mod query {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Account, Error> {
let id = &self.id;
iroha_logger::trace!(%id);
state_ro
.world()
.domain(id.domain())
.map_err(|_| FindError::Domain(id.domain().clone()))?;
state_ro
.world()
.map_account(id, Clone::clone)
Expand All @@ -578,7 +576,13 @@ pub mod query {

iroha_logger::trace!(%id);
Ok(Box::new(
state_ro.world().domain(id)?.accounts.values().cloned(),
state_ro
.world()
.domain(id)?
.accounts
.iter()
.filter_map(|a_id| state_ro.world().account(a_id).ok())
.cloned(),
))
}
}
Expand Down Expand Up @@ -609,10 +613,14 @@ pub mod query {
Ok(Box::new(
state_ro
.world()
.map_domain(&asset_definition_id.domain.clone(), move |domain| {
domain.accounts.values().filter(move |account| {
account.assets.contains_key(&asset_definition_id)
})
.map_domain(&asset_definition_id.domain.clone(), |domain| {
domain
.accounts
.iter()
.filter_map(|account_id| state_ro.world().account(account_id).ok())
.filter(move |account| {
account.assets.contains_key(&asset_definition_id)
})
})?
.cloned(),
))
Expand Down
Loading

0 comments on commit 343cfce

Please sign in to comment.