Skip to content
5 changes: 4 additions & 1 deletion ethexe/common/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
Announce, Digest, HashOf, ToDigest,
ecdsa::{ContractSignature, VerifiedData},
gear::BatchCommitment,
network::NetworkAnnounce,
};
use alloc::vec::Vec;
use gprimitives::CodeId;
Expand All @@ -36,7 +37,9 @@ pub const DEFAULT_BATCH_SIZE_LIMIT: u64 = 100 * 1024;
/// Default threshold for producer to submit commitment despite of no transitions
pub const DEFAULT_CHAIN_DEEPNESS_THRESHOLD: u32 = 500;

pub type VerifiedAnnounce = VerifiedData<Announce>;
// pub type VerifiedAnnounce = VerifiedData<Announce>;

pub type VerifiedAnnounce = VerifiedData<NetworkAnnounce>;
pub type VerifiedValidationRequest = VerifiedData<BatchCommitmentValidationRequest>;
pub type VerifiedValidationReply = VerifiedData<BatchCommitmentValidationReply>;

Expand Down
4 changes: 2 additions & 2 deletions ethexe/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub trait OnChainStorageRW: OnChainStorageRO {
fn set_block_synced(&self, block_hash: H256);
}

#[auto_impl::auto_impl(&)]
#[auto_impl::auto_impl(&, Box)]
pub trait InjectedStorageRO {
/// Returns the transactions by its hash.
fn injected_transaction(
Expand Down Expand Up @@ -260,7 +260,7 @@ mod tests {
#[test]
fn ensure_types_unchanged() {
const EXPECTED_TYPE_INFO_HASH: &str =
"d27a8b20ef1490fd5a73fd7a04780b373d42d73c4444fea555d10985ce203125";
"d6afd104446d5e9527fe390730751141a08f8c689ff9c09c041ae18a4a15b107";

let types = [
meta_type::<BlockMeta>(),
Expand Down
32 changes: 32 additions & 0 deletions ethexe/common/src/injected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::string::{String, ToString};
use core::hash::Hash;
use gear_core::{limited::LimitedVec, rpc::ReplyInfo};
use gprimitives::{ActorId, H256, MessageId};
use gsigner::Signature;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sha3::{Digest, Keccak256};
Expand Down Expand Up @@ -127,6 +128,37 @@ impl InjectedTransaction {
}
}

/// Announce injected transaction representation. Contains the signature
/// over [InjectedTransaction] and its hash.
///
/// NOTE: can be constructed only from [`SignedInjectedTransaction`].
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq, TypeInfo, Hash)]
pub struct AnnounceInjectedTransaction {
signature: Signature,
hash: HashOf<InjectedTransaction>,
}

impl AnnounceInjectedTransaction {
pub fn from_signed_tx(signed_tx: &SignedInjectedTransaction) -> Self {
Self {
signature: *signed_tx.signature(),
hash: signed_tx.data().to_hash(),
}
}

pub fn into_parts(&self) -> (Signature, HashOf<InjectedTransaction>) {
(self.signature, self.hash)
}

pub fn signature(&self) -> &Signature {
&self.signature
}

pub fn tx_hash(&self) -> HashOf<InjectedTransaction> {
self.hash
}
}

/// [`Promise`] represents the guaranteed reply for [`InjectedTransaction`].
///
/// Note: Validator must ensure the validity of the promise, because of it can be slashed for
Expand Down
24 changes: 24 additions & 0 deletions ethexe/common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
events::BlockEvent,
gear::{BatchCommitment, ChainCommitment, CodeCommitment, Message, StateTransition},
injected::{AddressedInjectedTransaction, InjectedTransaction},
network::NetworkAnnounce,
};
use alloc::{collections::BTreeMap, vec};
use gear_core::{
Expand Down Expand Up @@ -106,6 +107,29 @@ impl Mock<()> for Announce {
}
}

impl Mock<(H256, HashOf<Announce>)> for NetworkAnnounce {
fn mock((block_hash, parent): (H256, HashOf<Announce>)) -> Self {
NetworkAnnounce {
block_hash,
parent,
gas_allowance: Some(100),
injected_transactions: vec![],
}
}
}

impl Mock<H256> for NetworkAnnounce {
fn mock(block_hash: H256) -> Self {
NetworkAnnounce::mock((block_hash, HashOf::random()))
}
}

impl Mock<()> for NetworkAnnounce {
fn mock(_args: ()) -> Self {
NetworkAnnounce::mock(H256::random())
}
}

impl Mock<()> for CodeCommitment {
fn mock(_args: ()) -> Self {
CodeCommitment {
Expand Down
12 changes: 7 additions & 5 deletions ethexe/common/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use core::{hash::Hash, num::NonZeroU32};
use parity_scale_codec::{Decode, Encode};
use sha3::Keccak256;

pub type ValidatorAnnounce = ValidatorMessage<Announce>;
pub use crate::primitives::{NetworkAnnounce, NetworkAnnounceFromAnnounceError};

pub type ValidatorAnnounce = ValidatorMessage<NetworkAnnounce>;
pub type ValidatorRequest = ValidatorMessage<BatchCommitmentValidationRequest>;
pub type ValidatorReply = ValidatorMessage<BatchCommitmentValidationReply>;

Expand Down Expand Up @@ -115,26 +117,26 @@ pub struct AnnouncesResponse {
/// Corresponding request for this response
request: AnnouncesRequest,
/// List of announces
announces: Vec<Announce>,
announces: Vec<NetworkAnnounce>,
}

impl AnnouncesResponse {
/// # Safety
///
/// Response must be only created by network service
pub unsafe fn from_parts(request: AnnouncesRequest, announces: Vec<Announce>) -> Self {
pub unsafe fn from_parts(request: AnnouncesRequest, announces: Vec<NetworkAnnounce>) -> Self {
Self { request, announces }
}

pub fn request(&self) -> &AnnouncesRequest {
&self.request
}

pub fn announces(&self) -> &[Announce] {
pub fn announces(&self) -> &[NetworkAnnounce] {
&self.announces
}

pub fn into_parts(self) -> (AnnouncesRequest, Vec<Announce>) {
pub fn into_parts(self) -> (AnnouncesRequest, Vec<NetworkAnnounce>) {
(self.request, self.announces)
}
}
Loading
Loading