Skip to content

Commit

Permalink
move merkle tree to data_model
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Dec 1, 2021
1 parent c4e5693 commit fa4cd44
Show file tree
Hide file tree
Showing 11 changed files with 596 additions and 628 deletions.
5 changes: 3 additions & 2 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use std::{collections::BTreeSet, iter, marker::PhantomData};
use dashmap::{mapref::one::Ref as MapRef, DashMap};
use eyre::{Context, Result};
use iroha_crypto::{HashOf, KeyPair, SignatureOf, SignaturesOf};
use iroha_data_model::{current_time, events::prelude::*, transaction::prelude::*};
use iroha_data_model::{
current_time, events::prelude::*, merkle::MerkleTree, transaction::prelude::*,
};
use iroha_derive::Io;
use iroha_schema::IntoSchema;
use iroha_version::{declare_versioned_with_scale, version_with_scale};
use parity_scale_codec::{Decode, Encode};

use crate::{
merkle::MerkleTree,
prelude::*,
smartcontracts::permissions::{IsInstructionAllowedBoxed, IsQueryAllowedBoxed},
sumeragi::{
Expand Down
10 changes: 5 additions & 5 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use async_trait::async_trait;
use futures::{Stream, StreamExt, TryStreamExt};
use iroha_actor::{broker::*, prelude::*};
use iroha_crypto::HashOf;
use iroha_data_model::merkle::MerkleTree;
use iroha_version::scale::{DecodeVersioned, EncodeVersioned};
use pin_project::pin_project;
use serde::{Deserialize, Serialize};
Expand All @@ -27,7 +28,6 @@ use tokio_stream::wrappers::ReadDirStream;
use crate::{
block::VersionedCommittedBlock,
block_sync::ContinueSync,
merkle::MerkleTree,
prelude::*,
sumeragi::{self, UpdateNetworkTopology},
wsv::WorldTrait,
Expand Down Expand Up @@ -243,14 +243,14 @@ impl<W: WorldTrait, IO: DiskIO> KuraWithIO<W, IO> {
block: VersionedCommittedBlock,
) -> Result<HashOf<VersionedCommittedBlock>> {
match self.block_store.write(&block).await {
Ok(hash) => {
self.merkle_tree = self.merkle_tree.add(hash);
Ok(block_hash) => {
self.merkle_tree = self.merkle_tree.add(block_hash);
if let Err(error) = self.wsv.apply(block).await {
iroha_logger::warn!(%error, "Failed to execute transaction on WSV");
iroha_logger::warn!(%error, %block_hash, "Failed to apply block on WSV");
}
self.broker.issue_send(UpdateNetworkTopology).await;
self.broker.issue_send(ContinueSync).await;
Ok(hash)
Ok(block_hash)
}
Err(error) => {
let blocks = self
Expand Down
2 changes: 0 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod event;
pub mod genesis;
mod init;
pub mod kura;
mod merkle;
pub mod modules;
pub mod queue;
pub mod samples;
Expand All @@ -29,7 +28,6 @@ use smartcontracts::permissions::{IsInstructionAllowedBoxed, IsQueryAllowedBoxed
use tokio::{sync::broadcast, task::JoinHandle};

use crate::{
block::VersionedValidBlock,
block_sync::{
message::VersionedMessage as BlockSyncMessage, BlockSynchronizer, BlockSynchronizerTrait,
},
Expand Down
2 changes: 1 addition & 1 deletion core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crossbeam_queue::ArrayQueue;
use dashmap::{mapref::entry::Entry, DashMap};
use eyre::{Report, Result};
use iroha_crypto::HashOf;
use iroha_data_model::transaction::VersionedTransaction;
use iroha_data_model::prelude::*;
use thiserror::Error;

pub use self::config::Configuration;
Expand Down
6 changes: 2 additions & 4 deletions core/src/sumeragi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ use std::{
use dashmap::{DashMap, DashSet};
use eyre::{eyre, Result};
use futures::{prelude::*, stream::FuturesUnordered};
use iroha_actor::{broker::*, prelude::*};
use iroha_actor::{broker::*, prelude::*, Context};
use iroha_crypto::{HashOf, KeyPair};
use iroha_data_model::{
current_time, events::Event, peer::Id as PeerId, transaction::VersionedTransaction,
};
use iroha_data_model::prelude::*;
use iroha_logger::Instrument;
use iroha_p2p::{ConnectPeer, DisconnectPeer};
use network_topology::{Role, Topology};
Expand Down
39 changes: 14 additions & 25 deletions core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{cmp::min, time::Duration};

use eyre::{Result, WrapErr};
use iroha_crypto::{HashOf, SignaturesOf};
use iroha_crypto::SignaturesOf;
pub use iroha_data_model::prelude::*;
use iroha_derive::Io;
use iroha_version::{declare_versioned_with_scale, version_with_scale};
Expand Down Expand Up @@ -54,11 +54,6 @@ impl VersionedAcceptedTransaction {
AcceptedTransaction::from_transaction(transaction, max_instruction_number).map(Into::into)
}

/// Calculate transaction `Hash`.
pub fn hash(&self) -> HashOf<VersionedTransaction> {
self.as_inner_v1().hash().transmute()
}

/// Checks if this transaction is waiting longer than specified in `transaction_time_to_live` from `QueueConfiguration` or `time_to_live_ms` of this transaction.
/// Meaning that the transaction will be expired as soon as the lesser of the specified TTLs was reached.
pub fn is_expired(&self, transaction_time_to_live: Duration) -> bool {
Expand Down Expand Up @@ -104,16 +99,13 @@ impl VersionedAcceptedTransaction {
) -> VersionedRejectedTransaction {
self.into_inner_v1().reject(rejection_reason).into()
}
}

/// # Errors
/// Asserts specific instruction number of instruction in transaction constraint
pub fn check_instruction_len(&self, max_instruction_len: u64) -> Result<()> {
self.as_inner_v1()
.check_instruction_len(max_instruction_len)
}
impl Txn for VersionedAcceptedTransaction {
type HashOf = VersionedTransaction;

/// Returns payload of transaction
pub const fn payload(&self) -> &Payload {
#[inline]
fn payload(&self) -> &Payload {
&self.as_inner_v1().payload
}
}
Expand All @@ -134,12 +126,6 @@ pub struct AcceptedTransaction {
}

impl AcceptedTransaction {
/// # Errors
/// Asserts specific instruction number of instruction in transaction constraint
pub fn check_instruction_len(&self, max_instruction_len: u64) -> Result<()> {
self.payload.check_instruction_len(max_instruction_len)
}

/// Accepts transaction
///
/// # Errors
Expand All @@ -160,11 +146,6 @@ impl AcceptedTransaction {
})
}

/// Calculate transaction `Hash`.
pub fn hash(&self) -> HashOf<Transaction> {
HashOf::new(&self.payload).transmute()
}

/// Checks if this transaction is waiting longer than specified in `transaction_time_to_live` from `QueueConfiguration` or `time_to_live_ms` of this transaction.
/// Meaning that the transaction will be expired as soon as the lesser of the specified TTLs was reached.
pub fn is_expired(&self, transaction_time_to_live: Duration) -> bool {
Expand Down Expand Up @@ -311,6 +292,14 @@ impl AcceptedTransaction {
}
}
}
impl Txn for AcceptedTransaction {
type HashOf = Transaction;

#[inline]
fn payload(&self) -> &Payload {
&self.payload
}
}

impl IsInBlockchain for VersionedAcceptedTransaction {
#[inline]
Expand Down
2 changes: 0 additions & 2 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::{
};

use config::Configuration;
#[cfg(feature = "roles")]
use dashmap::DashMap;
use dashmap::{
mapref::one::{Ref as DashmapRef, RefMut as DashmapRefMut},
DashSet,
Expand Down
Loading

0 comments on commit fa4cd44

Please sign in to comment.