Skip to content

Commit

Permalink
refactor: remove committed_topology from block
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Jul 23, 2024
1 parent 6f28b38 commit 5558ab0
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 229 deletions.
6 changes: 0 additions & 6 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ impl Iroha {
[genesis_domain(config.genesis.public_key.clone())],
[genesis_account(config.genesis.public_key.clone())],
[],
config
.sumeragi
.trusted_peers
.value()
.clone()
.into_non_empty_vec(),
);

let (kura, block_count) = Kura::new(&config.kura).change_context(StartError::InitKura)?;
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
20 changes: 16 additions & 4 deletions core/benches/blocks/apply_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use common::*;
pub struct StateApplyBlocks {
state: State,
blocks: Vec<CommittedBlock>,
topology: Topology,
}

impl StateApplyBlocks {
Expand Down Expand Up @@ -56,14 +57,19 @@ impl StateApplyBlocks {
&topology,
&peer_private_key,
);
let _events = state_block.apply_without_execution(&block);
let _events =
state_block.apply_without_execution(&block, topology.as_ref().to_owned());
state_block.commit();
block
})
.collect::<Vec<_>>()
};

Self { state, blocks }
Self {
state,
blocks,
topology,
}
}

/// Run benchmark body.
Expand All @@ -74,10 +80,16 @@ impl StateApplyBlocks {
///
/// # Panics
/// If state height isn't updated after applying block
pub fn measure(Self { state, blocks }: &Self) -> Result<()> {
pub fn measure(
Self {
state,
blocks,
topology,
}: &Self,
) -> Result<()> {
for (block, i) in blocks.iter().zip(1..) {
let mut state_block = state.block();
let _events = state_block.apply(block)?;
let _events = state_block.apply(block, topology.as_ref().to_owned())?;
assert_eq!(state_block.height(), i);
state_block.commit();
}
Expand Down
3 changes: 0 additions & 3 deletions core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use iroha_executor_data_model::permission::{
account::CanUnregisterAccount, asset_definition::CanUnregisterAssetDefinition,
domain::CanUnregisterDomain,
};
use iroha_primitives::unique_vec::UniqueVec;

/// Create block
pub fn create_block(
Expand All @@ -41,7 +40,6 @@ pub fn create_block(

let block = BlockBuilder::new(
vec![AcceptedTransaction::accept(transaction, &chain_id, limits).unwrap()],
topology.clone(),
Vec::new(),
)
.chain(0, state)
Expand Down Expand Up @@ -189,7 +187,6 @@ pub fn build_state(rt: &tokio::runtime::Handle, account_id: &AccountId) -> State
[domain],
[Account::new(account_id.clone()).build(account_id)],
[],
UniqueVec::new(),
),
kura,
query_handle,
Expand Down
2 changes: 1 addition & 1 deletion core/benches/blocks/validate_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl StateValidateBlocks {
&topology,
&peer_private_key,
);
let _events = state_block.apply_without_execution(&block);
let _events = state_block.apply_without_execution(&block, topology.as_ref().to_owned());
assert_eq!(state_block.height(), i);
state_block.commit();
}
Expand Down
2 changes: 1 addition & 1 deletion core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) {
let topology = Topology::new(vec![peer_id]);
let mut block = {
let mut state_block = state.block();
BlockBuilder::new(vec![tx], topology.clone(), Vec::new())
BlockBuilder::new(vec![tx], Vec::new())
.chain(0, &mut state_block)
.sign(&peer_private_key)
.unpack(|_| {})
Expand Down
11 changes: 3 additions & 8 deletions core/benches/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ use iroha_core::{
query::store::LiveQueryStore,
smartcontracts::{isi::Registrable as _, Execute},
state::{State, World},
sumeragi::network_topology::Topology,
tx::TransactionExecutor,
};
use iroha_data_model::{
account::AccountId, isi::InstructionBox, parameter::TransactionParameters, prelude::*,
transaction::TransactionBuilder,
};
use iroha_primitives::unique_vec::UniqueVec;
use nonzero_ext::nonzero;
use once_cell::sync::Lazy;
use test_samples::gen_account_in;
Expand Down Expand Up @@ -50,7 +48,7 @@ fn build_test_and_transient_state() -> State {
let (account_id, _account_keypair) = gen_account_in(&*STARTER_DOMAIN);
let domain = Domain::new(STARTER_DOMAIN.clone()).build(&account_id);
let account = Account::new(account_id.clone()).build(&account_id);
World::with([domain], [account], [], UniqueVec::new())
World::with([domain], [account], [])
},
kura,
query_handle,
Expand Down Expand Up @@ -148,15 +146,12 @@ fn sign_blocks(criterion: &mut Criterion) {
let kura = iroha_core::kura::Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(World::new(), kura, query_handle);
let (peer_public_key, peer_private_key) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let (_, peer_private_key) = KeyPair::random().into_parts();

let mut count = 0;

let mut state_block = state.block();
let block =
BlockBuilder::new(vec![transaction], topology, Vec::new()).chain(0, &mut state_block);
let block = BlockBuilder::new(vec![transaction], Vec::new()).chain(0, &mut state_block);

let _ = criterion.bench_function("sign_block", |b| {
b.iter_batched(
Expand Down
61 changes: 13 additions & 48 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ mod pending {
/// the previous round, which might then be processed by the trigger system.
#[derive(Debug, Clone)]
pub struct Pending {
/// The topology at the time of block commit.
commit_topology: Topology,
/// Collection of transactions which have been accepted.
/// Transaction will be validated when block is chained.
transactions: Vec<AcceptedTransaction>,
Expand All @@ -146,11 +144,9 @@ mod pending {
#[inline]
pub fn new(
transactions: Vec<AcceptedTransaction>,
commit_topology: Topology,
event_recommendations: Vec<EventBox>,
) -> Self {
Self(Pending {
commit_topology,
transactions,
event_recommendations,
})
Expand Down Expand Up @@ -242,7 +238,6 @@ mod pending {
state.world.parameters().sumeragi.consensus_estimation(),
),
transactions,
commit_topology: self.0.commit_topology.into_iter().collect(),
event_recommendations: self.0.event_recommendations,
}))
}
Expand Down Expand Up @@ -529,25 +524,11 @@ mod valid {
if let Err(e) = check_genesis_block(block, genesis_account) {
return Err(e.into());
}
} else {
if let Err(err) = Self::verify_leader_signature(block, topology)
.and_then(|()| Self::verify_validator_signatures(block, topology))
.and_then(|()| Self::verify_no_undefined_signatures(block, topology))
{
return Err(err.into());
}

let actual_commit_topology = block.commit_topology().cloned().collect();
let expected_commit_topology = topology.as_ref();

// NOTE: checked AFTER height and hash because
// both of them can lead to a topology mismatch
if actual_commit_topology != expected_commit_topology {
return Err(BlockValidationError::TopologyMismatch {
expected: expected_commit_topology.to_owned(),
actual: actual_commit_topology,
});
}
} else if let Err(err) = Self::verify_leader_signature(block, topology)
.and_then(|()| Self::verify_validator_signatures(block, topology))
.and_then(|()| Self::verify_no_undefined_signatures(block, topology))
{
return Err(err.into());
}

if block.transactions().any(|tx| {
Expand Down Expand Up @@ -772,7 +753,6 @@ mod valid {
consensus_estimation_ms: 4_000,
},
transactions: Vec::new(),
commit_topology: Vec::new(),
event_recommendations: Vec::new(),
};
f(&mut payload);
Expand Down Expand Up @@ -1085,7 +1065,6 @@ mod tests {

use iroha_data_model::prelude::*;
use iroha_genesis::GENESIS_DOMAIN_ID;
use iroha_primitives::unique_vec::UniqueVec;
use test_samples::gen_account_in;

use super::*;
Expand Down Expand Up @@ -1121,7 +1100,7 @@ mod tests {
let account = Account::new(alice_id.clone()).build(&alice_id);
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let domain = Domain::new(domain_id).build(&alice_id);
let world = World::with([domain], [account], [], UniqueVec::new());
let world = World::with([domain], [account], []);
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand All @@ -1141,10 +1120,7 @@ mod tests {

// Creating a block of two identical transactions and validating it
let transactions = vec![tx.clone(), tx];
let (peer_public_key, _) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let valid_block = BlockBuilder::new(transactions, topology, Vec::new())
let valid_block = BlockBuilder::new(transactions, Vec::new())
.chain(0, &mut state_block)
.sign(alice_keypair.private_key())
.unpack(|_| {});
Expand Down Expand Up @@ -1177,7 +1153,7 @@ mod tests {
let account = Account::new(alice_id.clone()).build(&alice_id);
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let domain = Domain::new(domain_id).build(&alice_id);
let world = World::with([domain], [account], [], UniqueVec::new());
let world = World::with([domain], [account], []);
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 @@ -1215,10 +1191,7 @@ mod tests {

// Creating a block of two identical transactions and validating it
let transactions = vec![tx0, tx, tx2];
let (peer_public_key, _) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let valid_block = BlockBuilder::new(transactions, topology, Vec::new())
let valid_block = BlockBuilder::new(transactions, Vec::new())
.chain(0, &mut state_block)
.sign(alice_keypair.private_key())
.unpack(|_| {});
Expand Down Expand Up @@ -1251,7 +1224,7 @@ mod tests {
let account = Account::new(alice_id.clone()).build(&alice_id);
let domain_id = DomainId::from_str("wonderland").expect("Valid");
let domain = Domain::new(domain_id).build(&alice_id);
let world = World::with([domain], [account], [], UniqueVec::new());
let world = World::with([domain], [account], []);
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand All @@ -1277,10 +1250,7 @@ mod tests {

// Creating a block of where first transaction must fail and second one fully executed
let transactions = vec![tx_fail, tx_accept];
let (peer_public_key, _) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let valid_block = BlockBuilder::new(transactions, topology, Vec::new())
let valid_block = BlockBuilder::new(transactions, Vec::new())
.chain(0, &mut state_block)
.sign(alice_keypair.private_key())
.unpack(|_| {});
Expand Down Expand Up @@ -1329,12 +1299,7 @@ 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);
let world = World::with(
[genesis_domain],
[genesis_wrong_account],
[],
UniqueVec::new(),
);
let world = World::with([genesis_domain], [genesis_wrong_account], []);
let kura = Kura::blank_kura_for_testing();
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand All @@ -1359,7 +1324,7 @@ mod tests {
let (peer_public_key, _) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let valid_block = BlockBuilder::new(transactions, topology.clone(), Vec::new())
let valid_block = BlockBuilder::new(transactions, Vec::new())
.chain(0, &mut state_block)
.sign(genesis_correct_key.private_key())
.unpack(|_| {});
Expand Down
5 changes: 2 additions & 3 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ pub mod tests {
query::store::LiveQueryStore,
smartcontracts::isi::Registrable as _,
state::{State, World},
PeersIds,
};

impl Queue {
Expand Down Expand Up @@ -439,7 +438,7 @@ pub mod tests {
let (account_id, _account_keypair) = gen_account_in("wonderland");
let domain = Domain::new(domain_id).build(&account_id);
let account = Account::new(account_id.clone()).build(&account_id);
World::with([domain], [account], [], PeersIds::new())
World::with([domain], [account], [])
}

fn config_factory() -> Config {
Expand Down Expand Up @@ -840,7 +839,7 @@ pub mod tests {
let 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);
World::with([domain], [alice_account, bob_account], [], PeersIds::new())
World::with([domain], [alice_account, bob_account], [])
};
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura, query_handle);
Expand Down
3 changes: 1 addition & 2 deletions core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,10 @@ mod tests {
query::store::LiveQueryStore,
state::{State, World},
tx::AcceptTransactionFail,
PeersIds,
};

fn state_with_test_domains(kura: &Arc<Kura>) -> Result<State> {
let world = World::with([], [], [], PeersIds::new());
let world = World::with([], [], []);
let query_handle = LiveQueryStore::test().start();
let state = State::new(world, kura.clone(), query_handle);
let asset_definition_id = AssetDefinitionId::from_str("rose#wonderland")?;
Expand Down
Loading

0 comments on commit 5558ab0

Please sign in to comment.