diff --git a/client/src/client.rs b/client/src/client.rs index ece3888c30a..ce45562c393 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -28,7 +28,7 @@ use crate::{ config::Config, crypto::{HashOf, KeyPair}, data_model::{ - block::SignedBlock, + block::{BlockHeader, SignedBlock}, events::pipeline::{ BlockEventFilter, BlockStatus, PipelineEventBox, PipelineEventFilterBox, TransactionEventFilter, TransactionStatus, @@ -951,7 +951,7 @@ mod blocks_api { pub struct Events; impl FlowEvents for Events { - type Event = crate::data_model::block::SignedBlock; + type Event = SignedBlock; fn message(&self, message: Vec) -> Result { Ok(BlockMessage::decode_all(&mut message.as_slice()).map(Into::into)?) @@ -1012,7 +1012,7 @@ pub mod block { } /// Construct a query to find block header by hash - pub fn header_by_hash(hash: HashOf) -> FindBlockHeaderByHash { + pub fn header_by_hash(hash: HashOf) -> FindBlockHeaderByHash { FindBlockHeaderByHash::new(hash) } } diff --git a/client/tests/integration/pagination.rs b/client/tests/integration/pagination.rs index 9a38afd7796..dc2d38f5fee 100644 --- a/client/tests/integration/pagination.rs +++ b/client/tests/integration/pagination.rs @@ -26,11 +26,6 @@ fn limits_should_work() -> Result<()> { #[test] fn fetch_size_should_work() -> Result<()> { - let (_rt, _peer, client) = ::new().with_port(11_120).start_with_runtime(); - wait_for_genesis_committed(&vec![client.clone()], 0); - - register_assets(&client)?; - // use the lower-level API to inspect the batch size use iroha_data_model::query::{ builder::QueryExecutor as _, @@ -38,6 +33,11 @@ fn fetch_size_should_work() -> Result<()> { QueryWithFilter, QueryWithParams, }; + let (_rt, _peer, client) = ::new().with_port(11_120).start_with_runtime(); + wait_for_genesis_committed(&vec![client.clone()], 0); + + register_assets(&client)?; + let query = QueryWithParams::new( QueryWithFilter::new(asset::all_definitions(), CompoundPredicate::PASS).into(), QueryParams::new( diff --git a/core/src/block.rs b/core/src/block.rs index b007c36e740..7e144376858 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -43,9 +43,9 @@ pub enum BlockValidationError { /// Mismatch between the actual and expected hashes of the previous block. Expected: {expected:?}, actual: {actual:?} PrevBlockHashMismatch { /// Expected value - expected: Option>, + expected: Option>, /// Actual value - actual: Option>, + actual: Option>, }, /// Mismatch between the actual and expected height of the previous block. Expected: {expected}, actual: {actual} PrevBlockHeightMismatch { @@ -146,7 +146,7 @@ mod pending { fn make_header( prev_height: usize, - prev_block_hash: Option>, + prev_block_hash: Option>, view_change_index: usize, transactions: &[CommittedTransaction], consensus_estimation: Duration, @@ -1009,7 +1009,6 @@ mod event { let block_event = core::iter::once(BlockEvent { header: self.as_ref().header().clone(), - hash: self.as_ref().hash(), status: BlockStatus::Approved, }); @@ -1023,7 +1022,6 @@ mod event { fn produce_events(&self) -> impl Iterator { let block_event = core::iter::once(BlockEvent { header: self.as_ref().header().clone(), - hash: self.as_ref().hash(), status: BlockStatus::Committed, }); diff --git a/core/src/block_sync.rs b/core/src/block_sync.rs index a0ae5c35a32..c0c0d31e563 100644 --- a/core/src/block_sync.rs +++ b/core/src/block_sync.rs @@ -9,7 +9,10 @@ use std::{ use iroha_config::parameters::actual::BlockSync as Config; use iroha_crypto::HashOf; -use iroha_data_model::{block::SignedBlock, prelude::*}; +use iroha_data_model::{ + block::{BlockHeader, SignedBlock}, + prelude::*, +}; use iroha_logger::prelude::*; use iroha_macro::*; use iroha_p2p::Post; @@ -50,7 +53,7 @@ pub struct BlockSynchronizer { gossip_size: NonZeroU32, network: IrohaNetwork, state: Arc, - seen_blocks: BTreeSet<(NonZeroUsize, HashOf)>, + seen_blocks: BTreeSet<(NonZeroUsize, HashOf)>, latest_height: usize, } @@ -161,20 +164,20 @@ pub mod message { /// Peer id pub peer_id: PeerId, /// Hash of second to latest block - pub prev_hash: Option>, + pub prev_hash: Option>, /// Hash of latest available block - pub latest_hash: Option>, + pub latest_hash: Option>, /// The block hashes already seen - pub seen_blocks: BTreeSet>, + pub seen_blocks: BTreeSet>, } impl GetBlocksAfter { /// Construct [`GetBlocksAfter`]. pub const fn new( peer_id: PeerId, - prev_hash: Option>, - latest_hash: Option>, - seen_blocks: BTreeSet>, + prev_hash: Option>, + latest_hash: Option>, + seen_blocks: BTreeSet>, ) -> Self { Self { peer_id, @@ -304,9 +307,9 @@ pub mod message { #[derive(Decode)] struct GetBlocksAfterCandidate { peer: PeerId, - prev_hash: Option>, - latest_hash: Option>, - seen_blocks: BTreeSet>, + prev_hash: Option>, + latest_hash: Option>, + seen_blocks: BTreeSet>, } #[derive(Decode)] diff --git a/core/src/kura.rs b/core/src/kura.rs index d89ab30c4b4..3b75b5e970b 100644 --- a/core/src/kura.rs +++ b/core/src/kura.rs @@ -12,7 +12,7 @@ use std::{ use iroha_config::{kura::InitMode, parameters::actual::Kura as Config}; use iroha_crypto::{Hash, HashOf}; -use iroha_data_model::block::SignedBlock; +use iroha_data_model::block::{BlockHeader, SignedBlock}; use iroha_logger::prelude::*; use iroha_version::scale::{DecodeVersioned, EncodeVersioned}; use parity_scale_codec::DecodeAll; @@ -35,7 +35,7 @@ pub struct Kura { block_store: Mutex, /// The array of block hashes and a slot for an arc of the block. This is normally recovered from the index file. #[allow(clippy::type_complexity)] - block_data: Mutex, Option>)>>, + block_data: Mutex, Option>)>>, /// Path to file for plain text blocks. block_plain_text_path: Option, } @@ -134,7 +134,7 @@ impl Kura { fn init_fast_mode( block_store: &BlockStore, block_index_count: usize, - ) -> Result>, Error> { + ) -> Result>, Error> { let block_hashes_count = block_store .read_hashes_count()? .try_into() @@ -149,7 +149,7 @@ impl Kura { fn init_strict_mode( block_store: &mut BlockStore, block_index_count: usize, - ) -> Result>, Error> { + ) -> Result>, Error> { let mut block_hashes = Vec::with_capacity(block_index_count); let mut block_indices = vec![BlockIndex::default(); block_index_count]; @@ -271,7 +271,7 @@ impl Kura { } /// Get the hash of the block at the provided height. - pub fn get_block_hash(&self, block_height: NonZeroUsize) -> Option> { + pub fn get_block_hash(&self, block_height: NonZeroUsize) -> Option> { let hash_data_guard = self.block_data.lock(); let block_height = block_height.get(); @@ -284,7 +284,7 @@ impl Kura { } /// Search through blocks for the height of the block with the given hash. - pub fn get_block_height_by_hash(&self, hash: HashOf) -> Option { + pub fn get_block_height_by_hash(&self, hash: HashOf) -> Option { self.block_data .lock() .iter() @@ -463,7 +463,7 @@ impl BlockStore { &self, start_block_height: u64, block_count: usize, - ) -> Result>> { + ) -> Result>> { let path = self.path_to_blockchain.join(HASHES_FILE_NAME); let mut hashes_file = std::fs::OpenOptions::new() .read(true) @@ -497,7 +497,7 @@ impl BlockStore { /// Get the number of hashes in the hashes file, which is /// calculated as the size of the hashes file in bytes divided by - /// `size_of(HashOf)`. + /// `size_of(HashOf)`. /// /// # Errors /// IO Error. @@ -631,7 +631,7 @@ impl BlockStore { /// /// # Errors /// IO Error. - pub fn write_block_hash(&mut self, block_height: u64, hash: HashOf) -> Result<()> { + pub fn write_block_hash(&mut self, block_height: u64, hash: HashOf) -> Result<()> { let path = self.path_to_blockchain.join(HASHES_FILE_NAME); let mut hashes_file = std::fs::OpenOptions::new() .write(true) @@ -659,7 +659,7 @@ impl BlockStore { /// /// # Errors /// IO Error. - pub fn overwrite_block_hashes(&mut self, hashes: &[HashOf]) -> Result<()> { + pub fn overwrite_block_hashes(&mut self, hashes: &[HashOf]) -> Result<()> { let path = self.path_to_blockchain.join(HASHES_FILE_NAME); let hashes_file = std::fs::OpenOptions::new() .write(true) diff --git a/core/src/smartcontracts/isi/account.rs b/core/src/smartcontracts/isi/account.rs index 1955f7ddd2f..70f5e56a760 100644 --- a/core/src/smartcontracts/isi/account.rs +++ b/core/src/smartcontracts/isi/account.rs @@ -498,11 +498,11 @@ pub mod query { impl ValidQuery for FindRolesByAccountId { #[metrics(+"find_roles_by_account_id")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { let account_id = &self.id; state_ro.world().account(account_id)?; Ok(state_ro @@ -515,11 +515,11 @@ pub mod query { impl ValidQuery for FindPermissionsByAccountId { #[metrics(+"find_permissions_by_account_id")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { let account_id = &self.id; Ok(state_ro .world() @@ -531,11 +531,11 @@ pub mod query { impl ValidQuery for FindAccounts { #[metrics(+"find_accounts")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .accounts_iter() @@ -560,11 +560,11 @@ pub mod query { impl ValidQuery for FindAccountsWithAsset { #[metrics(+"find_accounts_with_asset")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> std::result::Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> std::result::Result, Error> { let asset_definition_id = self.asset_definition.clone(); iroha_logger::trace!(%asset_definition_id); diff --git a/core/src/smartcontracts/isi/asset.rs b/core/src/smartcontracts/isi/asset.rs index ef75519dd88..1150f6b48b6 100644 --- a/core/src/smartcontracts/isi/asset.rs +++ b/core/src/smartcontracts/isi/asset.rs @@ -439,11 +439,11 @@ pub mod query { impl ValidQuery for FindAssets { #[metrics(+"find_assets")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .assets_iter() @@ -453,11 +453,11 @@ pub mod query { } impl ValidQuery for FindAssetsDefinitions { #[metrics(+"find_asset_definitions")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .asset_definitions_iter() diff --git a/core/src/smartcontracts/isi/block.rs b/core/src/smartcontracts/isi/block.rs index a8b67df2e7d..05674f8fd47 100644 --- a/core/src/smartcontracts/isi/block.rs +++ b/core/src/smartcontracts/isi/block.rs @@ -19,11 +19,11 @@ use crate::{smartcontracts::ValidQuery, state::StateReadOnly}; impl ValidQuery for FindBlocks { #[metrics(+"find_blocks")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, QueryExecutionFail> { + state_ro: &impl StateReadOnly, + ) -> Result, QueryExecutionFail> { Ok(state_ro .all_blocks(nonzero!(1_usize)) .rev() @@ -34,11 +34,11 @@ impl ValidQuery for FindBlocks { impl ValidQuery for FindBlockHeaders { #[metrics(+"find_block_headers")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, QueryExecutionFail> { + state_ro: &impl StateReadOnly, + ) -> Result, QueryExecutionFail> { Ok(state_ro .all_blocks(nonzero!(1_usize)) .rev() diff --git a/core/src/smartcontracts/isi/domain.rs b/core/src/smartcontracts/isi/domain.rs index f31faad7997..fc1a223f0a5 100644 --- a/core/src/smartcontracts/isi/domain.rs +++ b/core/src/smartcontracts/isi/domain.rs @@ -405,11 +405,11 @@ pub mod query { impl ValidQuery for FindDomains { #[metrics(+"find_domains")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> std::result::Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> std::result::Result, Error> { Ok(state_ro .world() .domains_iter() diff --git a/core/src/smartcontracts/isi/triggers/mod.rs b/core/src/smartcontracts/isi/triggers/mod.rs index d076cbd7a9b..7aeef5148e7 100644 --- a/core/src/smartcontracts/isi/triggers/mod.rs +++ b/core/src/smartcontracts/isi/triggers/mod.rs @@ -339,11 +339,11 @@ pub mod query { impl ValidQuery for FindActiveTriggerIds { #[metrics(+"find_active_triggers")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .triggers() diff --git a/core/src/smartcontracts/isi/tx.rs b/core/src/smartcontracts/isi/tx.rs index 4872c61ba00..fd6c5023d0c 100644 --- a/core/src/smartcontracts/isi/tx.rs +++ b/core/src/smartcontracts/isi/tx.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use eyre::Result; use iroha_crypto::HashOf; use iroha_data_model::{ - block::SignedBlock, + block::{BlockHeader, SignedBlock}, prelude::*, query::{ error::{FindError, QueryExecutionFail}, @@ -47,7 +47,7 @@ impl Iterator for BlockTransactionIter { } impl BlockTransactionRef { - fn block_hash(&self) -> HashOf { + fn block_hash(&self) -> HashOf { self.0.hash() } @@ -70,11 +70,11 @@ impl BlockTransactionRef { impl ValidQuery for FindTransactions { #[metrics(+"find_transactions")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, QueryExecutionFail> { + state_ro: &impl StateReadOnly, + ) -> Result, QueryExecutionFail> { Ok(state_ro .all_blocks(nonzero!(1_usize)) .flat_map(BlockTransactionIter::new) @@ -88,11 +88,11 @@ impl ValidQuery for FindTransactions { impl ValidQuery for FindTransactionsByAccountId { #[metrics(+"find_transactions_by_account_id")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, QueryExecutionFail> { + state_ro: &impl StateReadOnly, + ) -> Result, QueryExecutionFail> { let account_id = self.account.clone(); Ok(state_ro diff --git a/core/src/smartcontracts/isi/world.rs b/core/src/smartcontracts/isi/world.rs index a310ce096c5..97ae16b967c 100644 --- a/core/src/smartcontracts/isi/world.rs +++ b/core/src/smartcontracts/isi/world.rs @@ -474,11 +474,11 @@ pub mod query { impl ValidQuery for FindRoles { #[metrics(+"find_roles")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .roles() @@ -491,11 +491,11 @@ pub mod query { impl ValidQuery for FindRoleIds { #[metrics(+"find_role_ids")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .roles() @@ -509,11 +509,11 @@ pub mod query { impl ValidQuery for FindPeers { #[metrics(+"find_peers")] - fn execute<'state>( + fn execute( self, filter: CompoundPredicate, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, Error> { + state_ro: &impl StateReadOnly, + ) -> Result, Error> { Ok(state_ro .world() .peers() diff --git a/core/src/smartcontracts/mod.rs b/core/src/smartcontracts/mod.rs index 04a80b8e4fa..cc34849a62c 100644 --- a/core/src/smartcontracts/mod.rs +++ b/core/src/smartcontracts/mod.rs @@ -44,11 +44,11 @@ where /// /// # Errors /// Concrete to each implementer - fn execute<'state>( + fn execute( self, filter: CompoundPredicate<::PredicateBoxType>, - state_ro: &'state impl StateReadOnly, - ) -> Result + 'state, QueryExecutionFail>; + state_ro: &impl StateReadOnly, + ) -> Result, QueryExecutionFail>; } /// This trait defines how an Iroha Singular query is executed. diff --git a/core/src/snapshot.rs b/core/src/snapshot.rs index b2fc9661bab..e744f39f393 100644 --- a/core/src/snapshot.rs +++ b/core/src/snapshot.rs @@ -9,7 +9,7 @@ use std::{ use iroha_config::{parameters::actual::Snapshot as Config, snapshot::Mode}; use iroha_crypto::HashOf; -use iroha_data_model::block::SignedBlock; +use iroha_data_model::block::BlockHeader; use iroha_logger::prelude::*; use serde::{de::DeserializeSeed, Serialize}; use tokio::sync::mpsc; @@ -43,7 +43,7 @@ pub struct SnapshotMaker { /// Path to the directory where snapshots are stored store_dir: PathBuf, /// Hash of the latest block stored in the state - latest_block_hash: Option>, + latest_block_hash: Option>, } impl SnapshotMaker { @@ -238,9 +238,9 @@ pub enum TryReadError { /// Height at which block hashes differs between snapshot and [`Kura`] height: usize, /// Hash of the block stored in snapshot - snapshot_block_hash: HashOf, + snapshot_block_hash: HashOf, /// Hash of the block stored in kura - kura_block_hash: HashOf, + kura_block_hash: HashOf, }, } diff --git a/core/src/state.rs b/core/src/state.rs index b2c7008de9c..6e23260c8b8 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -7,7 +7,7 @@ use eyre::Result; use iroha_crypto::HashOf; use iroha_data_model::{ account::AccountId, - block::SignedBlock, + block::{BlockHeader, SignedBlock}, events::{ pipeline::BlockEvent, time::TimeEvent, @@ -209,7 +209,7 @@ pub struct State { pub world: World, /// Blockchain. // TODO: Cell is redundant here since block_hashes is very easy to rollback by just popping the last element - pub block_hashes: Cell>>, + pub block_hashes: Cell>>, /// Hashes of transactions mapped onto block height where they stored pub transactions: Storage, NonZeroUsize>, /// Topology used to commit latest block @@ -240,7 +240,7 @@ pub struct StateBlock<'state> { /// The world. Contains `domains`, `triggers`, `roles` and other data representing the current state of the blockchain. pub world: WorldBlock<'state>, /// Blockchain. - pub block_hashes: CellBlock<'state, Vec>>, + pub block_hashes: CellBlock<'state, Vec>>, /// Hashes of transactions mapped onto block height where they stored pub transactions: StorageBlock<'state, HashOf, NonZeroUsize>, /// Topology used to commit latest block @@ -266,7 +266,7 @@ pub struct StateTransaction<'block, 'state> { /// The world. Contains `domains`, `triggers`, `roles` and other data representing the current state of the blockchain. pub world: WorldTransaction<'block, 'state>, /// Blockchain. - pub block_hashes: CellTransaction<'block, 'state, Vec>>, + pub block_hashes: CellTransaction<'block, 'state, Vec>>, /// Hashes of transactions mapped onto block height where they stored pub transactions: StorageTransaction<'block, 'state, HashOf, NonZeroUsize>, /// Topology used to commit latest block @@ -290,7 +290,7 @@ pub struct StateView<'state> { /// The world. Contains `domains`, `triggers`, `roles` and other data representing the current state of the blockchain. pub world: WorldView<'state>, /// Blockchain. - pub block_hashes: CellView<'state, Vec>>, + pub block_hashes: CellView<'state, Vec>>, /// Hashes of transactions mapped onto block height where they stored pub transactions: StorageView<'state, HashOf, NonZeroUsize>, /// Topology used to commit latest block @@ -1191,7 +1191,7 @@ impl State { #[allow(missing_docs)] pub trait StateReadOnly { fn world(&self) -> &impl WorldReadOnly; - fn block_hashes(&self) -> &[HashOf]; + fn block_hashes(&self) -> &[HashOf]; fn transactions(&self) -> &impl StorageReadOnly, NonZeroUsize>; fn commit_topology(&self) -> &[PeerId]; fn prev_commit_topology(&self) -> &[PeerId]; @@ -1209,12 +1209,12 @@ pub trait StateReadOnly { } /// Return the hash of the latest block - fn latest_block_hash(&self) -> Option> { + fn latest_block_hash(&self) -> Option> { self.block_hashes().iter().nth_back(0).copied() } /// Return the hash of the block one before the latest block - fn prev_block_hash(&self) -> Option> { + fn prev_block_hash(&self) -> Option> { self.block_hashes().iter().nth_back(1).copied() } @@ -1233,8 +1233,8 @@ pub trait StateReadOnly { /// Return a vector of blockchain blocks after the block with the given `hash` fn block_hashes_after_hash( &self, - hash: Option>, - ) -> Vec> { + hash: Option>, + ) -> Vec> { hash.map_or_else( || self.block_hashes().to_vec(), |block_hash| { @@ -1249,7 +1249,7 @@ pub trait StateReadOnly { } /// Return an iterator over blockchain block hashes starting with the block of the given `height` - fn block_hashes_from_height(&self, height: usize) -> Vec> { + fn block_hashes_from_height(&self, height: usize) -> Vec> { self.block_hashes() .iter() .skip(height.saturating_sub(1)) @@ -1308,7 +1308,7 @@ macro_rules! impl_state_ro { fn world(&self) -> &impl WorldReadOnly { &self.world } - fn block_hashes(&self) -> &[HashOf] { + fn block_hashes(&self) -> &[HashOf] { &self.block_hashes } fn transactions(&self) -> &impl StorageReadOnly, NonZeroUsize> { @@ -1477,7 +1477,6 @@ impl<'state> StateBlock<'state> { self.world.events_buffer.push( BlockEvent { header: block.as_ref().header().clone(), - hash: block.as_ref().hash(), status: BlockStatus::Applied, } .into(), diff --git a/core/src/sumeragi/main_loop.rs b/core/src/sumeragi/main_loop.rs index 1e134d28b5f..79d4ba866ac 100644 --- a/core/src/sumeragi/main_loop.rs +++ b/core/src/sumeragi/main_loop.rs @@ -120,7 +120,7 @@ impl Sumeragi { fn receive_network_packet( &self, - latest_block: HashOf, + latest_block: HashOf, view_change_proof_chain: &mut ProofChain, ) -> (Option, bool) { const MAX_CONTROL_MSG_IN_A_ROW: usize = 25; @@ -157,7 +157,7 @@ impl Sumeragi { fn receive_block_message_network_packet( &self, - latest_block: HashOf, + latest_block: HashOf, view_change_proof_chain: &ProofChain, ) -> Option { let current_view_change_index = @@ -421,7 +421,7 @@ impl Sumeragi { fn prune_view_change_proofs_and_calculate_current_index( &self, - latest_block: HashOf, + latest_block: HashOf, view_change_proof_chain: &mut ProofChain, ) -> usize { view_change_proof_chain.prune(latest_block); diff --git a/core/src/sumeragi/message.rs b/core/src/sumeragi/message.rs index 867b365a988..c3089a2d235 100644 --- a/core/src/sumeragi/message.rs +++ b/core/src/sumeragi/message.rs @@ -1,6 +1,6 @@ //! Contains message structures for p2p communication during consensus. use iroha_crypto::HashOf; -use iroha_data_model::block::{BlockSignature, SignedBlock}; +use iroha_data_model::block::{BlockHeader, BlockSignature, SignedBlock}; use iroha_macro::*; use parity_scale_codec::{Decode, Encode}; @@ -56,7 +56,7 @@ impl From<&ValidBlock> for BlockCreated { #[derive(Debug, Clone, Decode, Encode)] pub struct BlockSigned { /// Hash of the block being signed. - pub hash: HashOf, + pub hash: HashOf, /// Signature of the block pub signature: BlockSignature, } @@ -79,7 +79,7 @@ impl From<&ValidBlock> for BlockSigned { #[derive(Debug, Clone, Encode)] pub struct BlockCommitted { /// Hash of the block being signed. - pub hash: HashOf, + pub hash: HashOf, /// Set of signatures. pub signatures: Vec, } @@ -118,7 +118,7 @@ mod candidate { #[derive(Decode)] struct BlockCommittedCandidate { /// Hash of the block being signed. - pub hash: HashOf, + pub hash: HashOf, /// Set of signatures. pub signatures: Vec, } diff --git a/core/src/sumeragi/view_change.rs b/core/src/sumeragi/view_change.rs index fb698c72eb5..6cd53a07aff 100644 --- a/core/src/sumeragi/view_change.rs +++ b/core/src/sumeragi/view_change.rs @@ -4,7 +4,7 @@ use eyre::Result; use indexmap::IndexSet; use iroha_crypto::{HashOf, PublicKey, SignatureOf}; -use iroha_data_model::block::SignedBlock; +use iroha_data_model::block::BlockHeader; use parity_scale_codec::{Decode, Encode}; use thiserror::Error; @@ -25,7 +25,7 @@ pub enum Error { #[derive(Debug, Clone, Decode, Encode)] struct ViewChangeProofPayload { /// Hash of the latest committed block. - latest_block: HashOf, + latest_block: HashOf, /// Within a round, what is the index of the view change this proof is trying to prove. view_change_index: u32, } @@ -43,7 +43,7 @@ pub struct ProofBuilder(SignedViewChangeProof); impl ProofBuilder { /// Constructor from index. - pub fn new(latest_block: HashOf, view_change_index: usize) -> Self { + pub fn new(latest_block: HashOf, view_change_index: usize) -> Self { let view_change_index = view_change_index .try_into() .expect("INTERNAL BUG: Blockchain height should fit into usize"); @@ -109,7 +109,7 @@ impl ProofChain { pub fn verify_with_state( &self, topology: &Topology, - latest_block: HashOf, + latest_block: HashOf, ) -> usize { self.0 .iter() @@ -125,7 +125,7 @@ impl ProofChain { } /// Remove invalid proofs from the chain. - pub fn prune(&mut self, latest_block: HashOf) { + pub fn prune(&mut self, latest_block: HashOf) { let valid_count = self .0 .iter() @@ -147,7 +147,7 @@ impl ProofChain { &mut self, new_proof: SignedViewChangeProof, topology: &Topology, - latest_block: HashOf, + latest_block: HashOf, ) -> Result<(), Error> { if new_proof.payload.latest_block != latest_block { return Err(Error::BlockHashMismatch); @@ -175,7 +175,7 @@ impl ProofChain { &mut self, mut other: Self, topology: &Topology, - latest_block: HashOf, + latest_block: HashOf, ) -> Result<(), Error> { other.prune(latest_block); diff --git a/data_model/src/block.rs b/data_model/src/block.rs index 705aff16b93..e175c6383dc 100644 --- a/data_model/src/block.rs +++ b/data_model/src/block.rs @@ -58,7 +58,7 @@ mod model { pub height: NonZeroU64, /// Hash of the previous block in the chain. #[getset(get_copy = "pub")] - pub prev_block_hash: Option>, + pub prev_block_hash: Option>, /// Hash of merkle tree root of transactions' hashes. #[getset(get_copy = "pub")] pub transactions_hash: HashOf>, @@ -153,6 +153,12 @@ impl BlockHeader { pub const fn consensus_estimation(&self) -> Duration { Duration::from_millis(self.consensus_estimation_ms) } + + /// Calculate block hash + #[inline] + pub fn hash(&self) -> HashOf { + iroha_crypto::HashOf::new(&self) + } } impl BlockPayload { @@ -170,10 +176,8 @@ impl BlockPayload { } impl SignedBlockV1 { - fn hash(&self) -> iroha_crypto::HashOf { - iroha_crypto::HashOf::from_untyped_unchecked( - iroha_crypto::HashOf::new(&self.payload.header).into(), - ) + fn hash(&self) -> iroha_crypto::HashOf { + self.payload.header.hash() } } @@ -210,7 +214,7 @@ impl SignedBlock { /// Calculate block hash #[inline] - pub fn hash(&self) -> HashOf { + pub fn hash(&self) -> HashOf { let SignedBlock::V1(block) = self; block.hash() } diff --git a/data_model/src/events/pipeline.rs b/data_model/src/events/pipeline.rs index bbecb5ac47f..22897432501 100644 --- a/data_model/src/events/pipeline.rs +++ b/data_model/src/events/pipeline.rs @@ -12,10 +12,7 @@ use parity_scale_codec::{Decode, Encode}; use serde::{Deserialize, Serialize}; pub use self::model::*; -use crate::{ - block::{BlockHeader, SignedBlock}, - transaction::SignedTransaction, -}; +use crate::{block::BlockHeader, transaction::SignedTransaction}; #[model] mod model { @@ -61,7 +58,6 @@ mod model { #[getset(get = "pub")] pub struct BlockEvent { pub header: BlockHeader, - pub hash: HashOf, pub status: BlockStatus, } @@ -391,7 +387,6 @@ mod tests { .into(), BlockEvent { header: BlockHeader::dummy(nonzero!(7_u64)), - hash: HashOf::from_untyped_unchecked(Hash::prehashed([7_u8; Hash::LENGTH])), status: BlockStatus::Committed, } .into(), @@ -440,7 +435,6 @@ mod tests { .collect::>(), vec![BlockEvent { status: BlockStatus::Committed, - hash: HashOf::from_untyped_unchecked(Hash::prehashed([7_u8; Hash::LENGTH])), header: BlockHeader::dummy(nonzero!(7_u64)), } .into()], diff --git a/data_model/src/query/mod.rs b/data_model/src/query/mod.rs index 32878184256..9f9ac391426 100644 --- a/data_model/src/query/mod.rs +++ b/data_model/src/query/mod.rs @@ -63,7 +63,6 @@ mod model { use iroha_crypto::HashOf; use super::*; - use crate::block::SignedBlock; /// An iterable query bundled with a filter /// @@ -246,7 +245,7 @@ mod model { #[ffi_type] pub struct TransactionQueryOutput { /// The hash of the block to which `tx` belongs to - pub block_hash: HashOf, + pub block_hash: HashOf, /// Transaction #[getset(skip)] pub transaction: CommittedTransaction, @@ -634,7 +633,7 @@ pub mod role { #[derive(Display)] #[display(fmt = "Find all roles for `{id}` account")] #[repr(transparent)] - // SAFETY: `FindRolesByAccountId` has no trap representation in `EvaluatesTo` + // SAFETY: `FindRolesByAccountId` has no trap representation in `AccountId` #[ffi_type(unsafe {robust})] pub struct FindRolesByAccountId { /// `Id` of an account to find. @@ -664,7 +663,7 @@ pub mod permission { #[derive(Display)] #[display(fmt = "Find permission tokens specified for `{id}` account")] #[repr(transparent)] - // SAFETY: `FindPermissionsByAccountId` has no trap representation in `EvaluatesTo` + // SAFETY: `FindPermissionsByAccountId` has no trap representation in `AccountId` #[ffi_type(unsafe {robust})] pub struct FindPermissionsByAccountId { /// `Id` of an account to find. @@ -713,7 +712,7 @@ pub mod account { #[derive(Display)] #[display(fmt = "Find accounts with `{asset_definition}` asset")] #[repr(transparent)] - // SAFETY: `FindAccountsWithAsset` has no trap representation in `EvaluatesTo` + // SAFETY: `FindAccountsWithAsset` has no trap representation in `AssetDefinitionId` #[ffi_type(unsafe {robust})] pub struct FindAccountsWithAsset { /// `Id` of the definition of the asset which should be stored in founded accounts. @@ -758,7 +757,7 @@ pub mod asset { #[derive(Display)] #[display(fmt = "Find quantity of the `{id}` asset")] #[repr(transparent)] - // SAFETY: `FindAssetQuantityById` has no trap representation in `EvaluatesTo` + // SAFETY: `FindAssetQuantityById` has no trap representation in `AssetId` #[ffi_type(unsafe {robust})] pub struct FindAssetQuantityById { /// `Id` of an [`Asset`] to find quantity of. @@ -771,7 +770,7 @@ pub mod asset { #[derive(Display)] #[display(fmt = "Find total quantity of the `{id}` asset")] #[repr(transparent)] - // SAFETY: `FindTotalAssetQuantityByAssetDefinitionId` has no trap representation in `EvaluatesTo` + // SAFETY: `FindTotalAssetQuantityByAssetDefinitionId` has no trap representation in `AssetDefinitionId` #[ffi_type(unsafe {robust})] pub struct FindTotalAssetQuantityByAssetDefinitionId { /// `Id` of an [`Asset`] to find quantity of. @@ -921,7 +920,7 @@ pub mod trigger { #[derive(Display)] #[display(fmt = "Find `{id}` trigger")] #[repr(transparent)] - // SAFETY: `FindTriggerById` has no trap representation in `EvaluatesTo` + // SAFETY: `FindTriggerById` has no trap representation in `TriggerId` #[ffi_type(unsafe {robust})] pub struct FindTriggerById { /// The Identification of the trigger to be found. @@ -971,7 +970,7 @@ pub mod transaction { #[derive(Display)] #[display(fmt = "Find all transactions for `{account}` account")] #[repr(transparent)] - // SAFETY: `FindTransactionsByAccountId` has no trap representation in `EvaluatesTo` + // SAFETY: `FindTransactionsByAccountId` has no trap representation in `AccountId` #[ffi_type(unsafe {robust})] pub struct FindTransactionsByAccountId { /// Signer's [`AccountId`] under which transactions should be found. @@ -983,7 +982,7 @@ pub mod transaction { #[derive(Copy, Display)] #[display(fmt = "Find transaction with `{hash}` hash")] #[repr(transparent)] - // SAFETY: `FindTransactionByHash` has no trap representation in `EvaluatesTo>` + // SAFETY: `FindTransactionByHash` has no trap representation in `HashOf` #[ffi_type(unsafe {robust})] pub struct FindTransactionByHash { /// Transaction hash. @@ -1008,7 +1007,7 @@ pub mod block { use derive_more::Display; use iroha_crypto::HashOf; - use super::SignedBlock; + use super::BlockHeader; queries! { /// [`FindBlocks`] Iroha Query lists all blocks sorted by @@ -1029,11 +1028,11 @@ pub mod block { #[derive(Copy, Display)] #[display(fmt = "Find block header with `{hash}` hash")] #[repr(transparent)] - // SAFETY: `FindBlockHeaderByHash` has no trap representation in `EvaluatesTo>` + // SAFETY: `FindBlockHeaderByHash` has no trap representation in `HashOf` #[ffi_type(unsafe {robust})] pub struct FindBlockHeaderByHash { /// Block hash. - pub hash: HashOf, + pub hash: HashOf, } } @@ -1127,7 +1126,7 @@ pub mod error { /// Failed to find metadata key: `{0}` MetadataKey(Name), /// Block with hash `{0}` not found - Block(HashOf), + Block(HashOf), /// Transaction with hash `{0}` not found Transaction(HashOf), /// Peer with id `{0}` not found diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 48f65b1f935..b95927caa65 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -630,10 +630,6 @@ "name": "header", "type": "BlockHeader" }, - { - "name": "hash", - "type": "HashOf" - }, { "name": "status", "type": "BlockStatus" @@ -660,7 +656,7 @@ }, { "name": "prev_block_hash", - "type": "Option>" + "type": "Option>" }, { "name": "transactions_hash", @@ -1879,7 +1875,7 @@ "Struct": [ { "name": "hash", - "type": "HashOf" + "type": "HashOf" } ] }, @@ -1928,7 +1924,7 @@ { "tag": "Block", "discriminant": 5, - "type": "HashOf" + "type": "HashOf" }, { "tag": "Transaction", @@ -2096,8 +2092,8 @@ ] }, "Hash": "Array", + "HashOf": "Hash", "HashOf>": "Hash", - "HashOf": "Hash", "HashOf": "Hash", "IdBox": { "Enum": [ @@ -2706,8 +2702,8 @@ "Option": { "Option": "ForwardCursor" }, - "Option>": { - "Option": "HashOf" + "Option>": { + "Option": "HashOf" }, "Option>": { "Option": "HashOf" @@ -4404,7 +4400,7 @@ "Struct": [ { "name": "block_hash", - "type": "HashOf" + "type": "HashOf" }, { "name": "transaction", diff --git a/schema/gen/src/lib.rs b/schema/gen/src/lib.rs index f4943356722..4f179a90fd7 100644 --- a/schema/gen/src/lib.rs +++ b/schema/gen/src/lib.rs @@ -245,7 +245,7 @@ types!( Grant, Hash, HashOf>, - HashOf, + HashOf, HashOf, IdBox, InstructionBox, @@ -310,7 +310,7 @@ types!( Option, Option, Option, - Option>, + Option>, Option>, Option, Option, diff --git a/torii/src/lib.rs b/torii/src/lib.rs index a6a0f83d361..35513feb9a3 100644 --- a/torii/src/lib.rs +++ b/torii/src/lib.rs @@ -412,15 +412,15 @@ mod tests { async fn error_response_contains_details() { let err = Error::AcceptTransaction(iroha_core::tx::AcceptTransactionFail::ChainIdMismatch( iroha_data_model::isi::error::Mismatch { - expected: "123".try_into().unwrap(), - actual: "321".try_into().unwrap(), + expected: "123".into(), + actual: "321".into(), }, )); let response = err.into_response(); let body = response.into_body().collect().await.unwrap().to_bytes(); - let text = String::from_utf8(body.iter().map(|x| *x).collect()) - .expect("to be a valid UTF8 string"); + let text = + String::from_utf8(body.iter().copied().collect()).expect("to be a valid UTF8 string"); assert_eq!(text, "Failed to accept transaction\n\nCaused by:\n Chain id doesn't correspond to the id of current blockchain: Expected ChainId(\"123\"), actual ChainId(\"321\")"); } }