Skip to content

Commit

Permalink
Update from revision 8a5b9a2e1468dfb286c77084a9b3597b9e3993b5
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinity-bot committed Aug 25, 2021
1 parent e362530 commit 35dd8f9
Show file tree
Hide file tree
Showing 123 changed files with 3,347 additions and 1,680 deletions.
45 changes: 25 additions & 20 deletions rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ members = [
"crypto/internal/crypto_lib/bls12_381/common",
"crypto/internal/crypto_lib/fs_ni_dkg",
"crypto/internal/crypto_lib/multi_sig/bls12_381",
"crypto/internal/crypto_lib/sha2",
"crypto/secrets_containers",
"crypto/internal/crypto_lib/threshold_sig/bls12_381",
"crypto/internal/crypto_lib/tls",
Expand Down
2 changes: 1 addition & 1 deletion rs/artifact_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ic-metrics = { path = "../monitoring/metrics" }
ic-types = { path = "../types/types" }
crossbeam-channel = "0.5.0"
slog = { version = "2.5.2", features = ["nested-values", "max_level_trace", "release_max_level_debug"] }
tokio = { version = "1.2.0", features = ["full"] }
tokio = { version = "1.9.0", features = ["full"] }
prometheus = { version = "0.12.0", features = [ "process" ] }
serde = { version = "1.0.99", features = ["derive", "rc"] }
serde_json = "1.0.54"
Expand Down
20 changes: 20 additions & 0 deletions rs/artifact_manager/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,23 @@ impl ArtifactKind for DkgArtifact {
}
}
}

/// The `ArtifactKind` of ECDSA messages.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct EcdsaArtifact;

/// `EcdsaArtifact` implements the `ArtifactKind` trait.
impl ArtifactKind for EcdsaArtifact {
const TAG: ArtifactTag = ArtifactTag::EcdsaArtifact;
type Id = EcdsaMessageId;
type Message = EcdsaMessage;
type SerializeAs = EcdsaMessage;
type Attribute = EcdsaMessageAttribute;
type Filter = ();

/// The function converts a `EcdsaMessage` into an advert for a
/// `EcdsaArtifact`.
fn message_to_advert(_msg: &EcdsaMessage) -> Advert<EcdsaArtifact> {
unimplemented!()
}
}
53 changes: 52 additions & 1 deletion rs/artifact_manager/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use ic_interfaces::{
consensus::ConsensusGossip,
consensus_pool::{ConsensusPool, ConsensusPoolCache},
dkg::{DkgGossip, DkgPool},
gossip_pool::{CertificationGossipPool, ConsensusGossipPool, DkgGossipPool, IngressGossipPool},
ecdsa::{EcdsaGossip, EcdsaPool},
gossip_pool::{
CertificationGossipPool, ConsensusGossipPool, DkgGossipPool, EcdsaGossipPool,
IngressGossipPool,
},
ingress_pool::IngressPool,
time_source::TimeSource,
};
Expand Down Expand Up @@ -616,3 +620,50 @@ impl<Pool: DkgPool + DkgGossipPool + Send + Sync> ArtifactClient<DkgArtifact> fo
Box::new(SingleChunked::Dkg)
}
}

/// The ECDSA client.
pub struct EcdsaClient<Pool> {
ecdsa_pool: Arc<RwLock<Pool>>,
ecdsa_gossip: Arc<dyn EcdsaGossip>,
}

impl<Pool> EcdsaClient<Pool> {
pub fn new<T: EcdsaGossip + 'static>(ecdsa_pool: Arc<RwLock<Pool>>, gossip: T) -> Self {
Self {
ecdsa_pool,
ecdsa_gossip: Arc::new(gossip),
}
}
}

impl<Pool: EcdsaPool + EcdsaGossipPool + Send + Sync> ArtifactClient<EcdsaArtifact>
for EcdsaClient<Pool>
{
fn check_artifact_acceptance(
&self,
msg: EcdsaMessage,
_peer_id: &NodeId,
) -> Result<ArtifactAcceptance<EcdsaMessage>, ArtifactPoolError> {
Ok(ArtifactAcceptance::AcceptedForProcessing(msg))
}

fn has_artifact(&self, msg_id: &EcdsaMessageId) -> bool {
self.ecdsa_pool.read().unwrap().contains(msg_id)
}

fn get_validated_by_identifier(&self, msg_id: &EcdsaMessageId) -> Option<EcdsaMessage> {
self.ecdsa_pool
.read()
.unwrap()
.get_validated_by_identifier(msg_id)
}

fn get_priority_function(&self) -> Option<PriorityFn<EcdsaMessageId, EcdsaMessageAttribute>> {
let ecdsa_pool = &*self.ecdsa_pool.read().unwrap();
Some(self.ecdsa_gossip.get_priority_function(ecdsa_pool))
}

fn get_chunk_tracker(&self, _id: &EcdsaMessageId) -> Box<dyn Chunkable + Send + Sync> {
Box::new(SingleChunked::Ecdsa)
}
}
71 changes: 71 additions & 0 deletions rs/artifact_manager/src/processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ic_interfaces::{
consensus::{Consensus, ConsensusGossip},
consensus_pool::{ChangeAction as ConsensusAction, ConsensusPoolCache, MutableConsensusPool},
dkg::{ChangeAction as DkgChangeAction, Dkg, DkgGossip, MutableDkgPool},
ecdsa::{Ecdsa, EcdsaGossip, MutableEcdsaPool},
ingress_manager::IngressHandler,
ingress_pool::{
ChangeAction as IngressAction, IngressPoolObject, IngressPoolSelect, MutableIngressPool,
Expand Down Expand Up @@ -702,3 +703,73 @@ impl<PoolDkg: MutableDkgPool + Send + Sync + 'static> ArtifactProcessor<DkgArtif
(adverts, changed)
}
}

/// ECDSA `OnStateChange` client.
pub struct EcdsaProcessor<PoolEcdsa> {
ecdsa_pool: Arc<RwLock<PoolEcdsa>>,
client: Box<dyn Ecdsa>,
}

impl<PoolEcdsa: MutableEcdsaPool + Send + Sync + 'static> EcdsaProcessor<PoolEcdsa> {
#[allow(clippy::too_many_arguments)]
pub fn build<
C: Ecdsa + 'static,
G: EcdsaGossip + 'static,
S: Fn(Advert<EcdsaArtifact>) + Send + 'static,
F: FnOnce() -> (C, G),
>(
send_advert: S,
setup: F,
time_source: Arc<SysTimeSource>,
ecdsa_pool: Arc<RwLock<PoolEcdsa>>,
metrics_registry: MetricsRegistry,
rt_handle: tokio::runtime::Handle,
) -> (
clients::EcdsaClient<PoolEcdsa>,
ArtifactProcessorManager<EcdsaArtifact>,
) {
let (ecdsa, ecdsa_gossip) = setup();
let client = Self {
ecdsa_pool: ecdsa_pool.clone(),
client: Box::new(ecdsa),
};
let manager = ArtifactProcessorManager::new(
time_source,
metrics_registry,
BoxOrArcClient::BoxClient(Box::new(client)),
send_advert,
rt_handle,
);
(clients::EcdsaClient::new(ecdsa_pool, ecdsa_gossip), manager)
}
}

impl<PoolEcdsa: MutableEcdsaPool + Send + Sync + 'static> ArtifactProcessor<EcdsaArtifact>
for EcdsaProcessor<PoolEcdsa>
{
fn process_changes(
&self,
_time_source: &dyn TimeSource,
artifacts: Vec<UnvalidatedArtifact<EcdsaMessage>>,
) -> (Vec<Advert<EcdsaArtifact>>, ProcessingResult) {
{
let mut ecdsa_pool = self.ecdsa_pool.write().unwrap();
for artifact in artifacts {
ecdsa_pool.insert(artifact)
}
}

let change_set = {
let ecdsa_pool = self.ecdsa_pool.read().unwrap();
self.client.on_state_change(&*ecdsa_pool)
};
let changed = if !change_set.is_empty() {
ProcessingResult::StateChanged
} else {
ProcessingResult::StateUnchanged
};

self.ecdsa_pool.write().unwrap().apply_changes(change_set);
(vec![], changed)
}
}
Loading

0 comments on commit 35dd8f9

Please sign in to comment.