diff --git a/configs/swarm/executor.wasm b/configs/swarm/executor.wasm index 4cf05e9698e..714760c9eb2 100644 Binary files a/configs/swarm/executor.wasm and b/configs/swarm/executor.wasm differ diff --git a/core/src/sumeragi/main_loop.rs b/core/src/sumeragi/main_loop.rs index 3a579611e45..318e5acbb8d 100644 --- a/core/src/sumeragi/main_loop.rs +++ b/core/src/sumeragi/main_loop.rs @@ -646,7 +646,7 @@ impl Sumeragi { ), _ => { if let Some(mut voted_block) = voting_block.take() { - let actual_hash = voted_block.block.as_ref().hash_of_payload(); + let actual_hash = voted_block.block.as_ref().hash(); if hash != actual_hash { error!( @@ -697,7 +697,7 @@ impl Sumeragi { Role::Leader | Role::ValidatingPeer | Role::ObservingPeer, ) => { if let Some(mut voted_block) = voting_block.take() { - let actual_hash = voted_block.block.as_ref().hash_of_payload(); + let actual_hash = voted_block.block.as_ref().hash(); if actual_hash == hash { match voted_block diff --git a/core/src/sumeragi/message.rs b/core/src/sumeragi/message.rs index c61bab848d8..867b365a988 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::{BlockPayload, BlockSignature, SignedBlock}; +use iroha_data_model::block::{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, } @@ -64,7 +64,7 @@ pub struct BlockSigned { impl From<&ValidBlock> for BlockSigned { fn from(block: &ValidBlock) -> Self { Self { - hash: block.as_ref().hash_of_payload(), + hash: block.as_ref().hash(), signature: block .as_ref() .signatures() @@ -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, } @@ -87,7 +87,7 @@ pub struct BlockCommitted { impl From<&CommittedBlock> for BlockCommitted { fn from(block: &CommittedBlock) -> Self { Self { - hash: block.as_ref().hash_of_payload(), + hash: block.as_ref().hash(), signatures: block.as_ref().signatures().cloned().collect(), } } @@ -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/data_model/src/block.rs b/data_model/src/block.rs index 9a5c21b3824..e830d8f1cbd 100644 --- a/data_model/src/block.rs +++ b/data_model/src/block.rs @@ -125,8 +125,7 @@ mod model { #[derive( Debug, Display, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Serialize, IntoSchema, )] - #[cfg_attr(not(feature = "std"), display(fmt = "Signed block"))] - #[cfg_attr(feature = "std", display(fmt = "{}", "self.hash()"))] + #[display(fmt = "{}", "self.hash()")] #[ffi_type] pub struct SignedBlockV1 { /// Signatures of peers which approved this block. @@ -175,9 +174,10 @@ impl BlockPayload { } impl SignedBlockV1 { - #[cfg(feature = "std")] fn hash(&self) -> iroha_crypto::HashOf { - iroha_crypto::HashOf::from_untyped_unchecked(iroha_crypto::HashOf::new(self).into()) + iroha_crypto::HashOf::from_untyped_unchecked( + iroha_crypto::HashOf::new(&self.payload.header).into(), + ) } } @@ -223,7 +223,8 @@ impl SignedBlock { /// Calculate block hash #[inline] pub fn hash(&self) -> HashOf { - iroha_crypto::HashOf::new(self) + let SignedBlock::V1(block) = self; + block.hash() } /// Add signature to the block @@ -261,15 +262,6 @@ impl SignedBlock { std::mem::replace(&mut block.signatures, signatures) } - /// Calculate block payload [`Hash`](`iroha_crypto::HashOf`). - #[inline] - #[cfg(feature = "std")] - #[cfg(feature = "transparent_api")] - pub fn hash_of_payload(&self) -> iroha_crypto::HashOf { - let SignedBlock::V1(block) = self; - iroha_crypto::HashOf::new(&block.payload) - } - /// Add additional signatures to this block #[cfg(all(feature = "std", feature = "transparent_api"))] pub fn sign(&mut self, private_key: &iroha_crypto::PrivateKey, signatory: usize) {