Skip to content

Commit

Permalink
Merge branch 'rumenov/rmvalded' into 'master'
Browse files Browse the repository at this point in the history
refactor: move the ValidatedArtifact type to the consensus_pool module

The type is exclusively used by consensus so no point in being defined in the artifact_pool module which defines the API between consensus and P2P. 

See merge request dfinity-lab/public/ic!15565
  • Loading branch information
rumenov committed Oct 28, 2023
2 parents 8d77465 + 4b1d17e commit 4ee333a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rs/artifact_pool/src/inmemory_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub mod test {
use std::collections::HashSet;

use super::*;
use ic_interfaces::artifact_pool::ValidatedArtifact;
use ic_interfaces::consensus_pool::ValidatedArtifact;
use ic_test_utilities::consensus::{fake::*, make_genesis};

fn make_summary(genesis_height: Height) -> ic_types::consensus::dkg::Summary {
Expand Down
2 changes: 1 addition & 1 deletion rs/artifact_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod rocksdb_iterator;
#[cfg(feature = "rocksdb_backend")]
mod rocksdb_pool;

use ic_interfaces::artifact_pool::{UnvalidatedArtifact, ValidatedArtifact};
use ic_interfaces::{artifact_pool::UnvalidatedArtifact, consensus_pool::ValidatedArtifact};
use ic_types::{ReplicaVersion, Time};
use std::convert::TryFrom;
use std::fs;
Expand Down
8 changes: 3 additions & 5 deletions rs/artifact_pool/src/rocksdb_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use crate::rocksdb_iterator::{StandaloneIterator, StandaloneSnapshot};
use bincode::{deserialize, serialize};
use byteorder::{BigEndian, ReadBytesExt};
use ic_config::artifact_pool::RocksDBConfig;

use ic_interfaces::artifact_pool::ValidatedArtifact;
use ic_interfaces::consensus_pool::{
HeightIndexedPool, HeightRange, OnlyError, PoolSection, ValidatedConsensusArtifact,
HeightIndexedPool, HeightRange, OnlyError, PoolSection, ValidatedArtifact,
ValidatedConsensusArtifact,
};
use ic_logger::{info, warn, ReplicaLogger};
use ic_protobuf::types::v1 as pb;
use ic_types::artifact::CertificationMessageId;
use ic_types::{
artifact::ConsensusMessageId,
artifact::{CertificationMessageId, ConsensusMessageId},
batch::BatchPayload,
consensus::{
certification::{Certification, CertificationMessage, CertificationShare},
Expand Down
16 changes: 0 additions & 16 deletions rs/interfaces/src/artifact_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use ic_types::{
artifact::{Advert, ArtifactKind, PriorityFn},
NodeId, Time,
};
use serde::{Deserialize, Serialize};

/// Produces mutations to be applied on the artifact pool.
pub trait ChangeSetProducer<Pool>: Send {
Expand Down Expand Up @@ -111,21 +110,6 @@ pub struct UnvalidatedArtifact<T> {
pub timestamp: Time,
}

/// Validated artifact
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ValidatedArtifact<T> {
pub msg: T,
pub timestamp: Time,
}

// Traits for accessing data for (un)validated artifacts follow.

impl<T> AsRef<T> for ValidatedArtifact<T> {
fn as_ref(&self) -> &T {
&self.msg
}
}

impl<T> AsRef<T> for UnvalidatedArtifact<T> {
fn as_ref(&self) -> &T {
&self.message
Expand Down
15 changes: 14 additions & 1 deletion rs/interfaces/src/consensus_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The consensus pool public interface.

use crate::artifact_pool::{UnvalidatedArtifact, ValidatedArtifact};
use crate::artifact_pool::UnvalidatedArtifact;
use ic_base_types::RegistryVersion;
use ic_protobuf::{
proxy::{try_from_option_field, ProxyDecodeError},
Expand All @@ -22,6 +22,19 @@ use std::sync::Arc;
/// The height, at which we consider a replica to be behind
pub const HEIGHT_CONSIDERED_BEHIND: Height = Height::new(20);

/// Validated artifact
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ValidatedArtifact<T> {
pub msg: T,
pub timestamp: Time,
}

impl<T> AsRef<T> for ValidatedArtifact<T> {
fn as_ref(&self) -> &T {
&self.msg
}
}

pub type ChangeSet = Vec<ChangeAction>;

/// Change actions applicable to the consensus pool.
Expand Down
2 changes: 1 addition & 1 deletion rs/interfaces/src/ingress_pool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The ingress pool public interface.
use crate::artifact_pool::{UnvalidatedArtifact, ValidatedArtifact};
use crate::{artifact_pool::UnvalidatedArtifact, consensus_pool::ValidatedArtifact};
use ic_types::{
artifact::IngressMessageId,
crypto::CryptoHash,
Expand Down

0 comments on commit 4ee333a

Please sign in to comment.