Skip to content

Commit c9253d8

Browse files
committed
Replace Announce with NetworkAnnounce in network API and related code
Refactor Announce to store only hashes of injected transactions. Add conversions and mocks for NetworkAnnounce. Update accept_announce and related functions to use NetworkAnnounce. Adjust types and imports accordingly throughout the codebase.
1 parent 933a9b7 commit c9253d8

File tree

22 files changed

+699
-123
lines changed

22 files changed

+699
-123
lines changed

ethexe/common/src/consensus.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ use crate::{
2020
Announce, Digest, HashOf, ToDigest,
2121
ecdsa::{ContractSignature, VerifiedData},
2222
gear::BatchCommitment,
23+
network::NetworkAnnounce,
2324
};
2425
use alloc::vec::Vec;
2526
use gprimitives::CodeId;
2627
use k256::sha2::Digest as _;
2728
use parity_scale_codec::{Decode, Encode};
2829
use sha3::Keccak256;
2930

30-
pub type VerifiedAnnounce = VerifiedData<Announce>;
31+
pub type VerifiedAnnounce = VerifiedData<NetworkAnnounce>;
3132
pub type VerifiedValidationRequest = VerifiedData<BatchCommitmentValidationRequest>;
3233
pub type VerifiedValidationReply = VerifiedData<BatchCommitmentValidationReply>;
3334

ethexe/common/src/gear.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub struct StateTransition {
368368
/// and each zero byte costs 4 gas (see <https://evm.codes/about#gascosts>).
369369
///
370370
/// Negative numbers will be stored like this:
371-
/// ```
371+
/// ```text
372372
/// $ cast
373373
/// > -1 ether
374374
/// Type: int256

ethexe/common/src/mock.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::{
2727
events::BlockEvent,
2828
gear::{BatchCommitment, ChainCommitment, CodeCommitment, Message, StateTransition},
2929
injected::{AddressedInjectedTransaction, InjectedTransaction},
30+
network::NetworkAnnounce,
3031
};
3132
use alloc::{collections::BTreeMap, vec};
3233
use gear_core::code::{CodeMetadata, InstrumentedCode};
@@ -91,6 +92,29 @@ impl Mock<()> for Announce {
9192
}
9293
}
9394

95+
impl Mock<(H256, HashOf<Announce>)> for NetworkAnnounce {
96+
fn mock((block_hash, parent): (H256, HashOf<Announce>)) -> Self {
97+
NetworkAnnounce {
98+
block_hash,
99+
parent,
100+
gas_allowance: Some(100),
101+
injected_transactions: vec![],
102+
}
103+
}
104+
}
105+
106+
impl Mock<H256> for NetworkAnnounce {
107+
fn mock(block_hash: H256) -> Self {
108+
NetworkAnnounce::mock((block_hash, HashOf::random()))
109+
}
110+
}
111+
112+
impl Mock<()> for NetworkAnnounce {
113+
fn mock(_args: ()) -> Self {
114+
NetworkAnnounce::mock(H256::random())
115+
}
116+
}
117+
94118
impl Mock<()> for CodeCommitment {
95119
fn mock(_args: ()) -> Self {
96120
CodeCommitment {

ethexe/common/src/network.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ use core::{hash::Hash, num::NonZeroU32};
2626
use parity_scale_codec::{Decode, Encode};
2727
use sha3::Keccak256;
2828

29-
pub type ValidatorAnnounce = ValidatorMessage<Announce>;
29+
pub use crate::primitives::{NetworkAnnounce, NetworkAnnounceFromAnnounceError};
30+
31+
pub type ValidatorAnnounce = ValidatorMessage<NetworkAnnounce>;
3032
pub type ValidatorRequest = ValidatorMessage<BatchCommitmentValidationRequest>;
3133
pub type ValidatorReply = ValidatorMessage<BatchCommitmentValidationReply>;
3234

@@ -115,26 +117,26 @@ pub struct AnnouncesResponse {
115117
/// Corresponding request for this response
116118
request: AnnouncesRequest,
117119
/// List of announces
118-
announces: Vec<Announce>,
120+
announces: Vec<NetworkAnnounce>,
119121
}
120122

121123
impl AnnouncesResponse {
122124
/// # Safety
123125
///
124126
/// Response must be only created by network service
125-
pub unsafe fn from_parts(request: AnnouncesRequest, announces: Vec<Announce>) -> Self {
127+
pub unsafe fn from_parts(request: AnnouncesRequest, announces: Vec<NetworkAnnounce>) -> Self {
126128
Self { request, announces }
127129
}
128130

129131
pub fn request(&self) -> &AnnouncesRequest {
130132
&self.request
131133
}
132134

133-
pub fn announces(&self) -> &[Announce] {
135+
pub fn announces(&self) -> &[NetworkAnnounce] {
134136
&self.announces
135137
}
136138

137-
pub fn into_parts(self) -> (AnnouncesRequest, Vec<Announce>) {
139+
pub fn into_parts(self) -> (AnnouncesRequest, Vec<NetworkAnnounce>) {
138140
(self.request, self.announces)
139141
}
140142
}

0 commit comments

Comments
 (0)