Skip to content

Commit

Permalink
refactor: rename some types to match better the intent
Browse files Browse the repository at this point in the history
  • Loading branch information
rumenov committed Feb 7, 2024
1 parent a0ede14 commit 76804db
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 109 deletions.
1 change: 1 addition & 0 deletions 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/p2p/consensus_manager/BUILD.bazel
Expand Up @@ -13,6 +13,7 @@ DEPENDENCIES = [
"//rs/protobuf",
"//rs/p2p/quic_transport",
"//rs/types/types",
"//rs/types/base_types",
"@crate_index//:axum_0_7_0",
"@crate_index//:backoff",
"@crate_index//:bytes",
Expand Down
3 changes: 2 additions & 1 deletion rs/p2p/consensus_manager/Cargo.toml
Expand Up @@ -11,11 +11,12 @@ backoff = { workspace = true }
bytes = { workspace = true }
crossbeam-channel = { workspace = true }
futures = { workspace = true }
ic-base-types = { path = "../../types/base_types" }
ic-interfaces = { path = "../../interfaces" }
ic-logger = { path = "../../monitoring/logger" }
ic-protobuf = { path = "../../protobuf" }
ic-metrics = { path = "../../monitoring/metrics" }
ic-quic-transport = { path = "../quic_transport" }
ic-protobuf = { path = "../../protobuf" }
ic-types = { path = "../../types/types" }
phantom_newtype = { path = "../../phantom_newtype" }
prometheus = { workspace = true }
Expand Down
41 changes: 20 additions & 21 deletions rs/p2p/consensus_manager/src/lib.rs
@@ -1,8 +1,13 @@
use std::sync::{Arc, RwLock};

use crate::metrics::ConsensusManagerMetrics;
use crate::{
metrics::ConsensusManagerMetrics,
receiver::{build_axum_router, ConsensusManagerReceiver},
sender::ConsensusManagerSender,
};
use axum::Router;
use crossbeam_channel::Sender as CrossbeamSender;
use ic_base_types::NodeId;
use ic_interfaces::p2p::{
artifact_manager::ArtifactProcessorEvent,
consensus::{PriorityFnAndFilterProducer, ValidatedPoolReader},
Expand All @@ -15,11 +20,7 @@ use ic_protobuf::{
};
use ic_quic_transport::{ConnId, SubnetTopology, Transport};
use ic_types::artifact::{ArtifactKind, UnvalidatedArtifactMutation};
use ic_types::NodeId;
use phantom_newtype::AmountOf;
use receiver::build_axum_router;
use receiver::ConsensusManagerReceiver;
use sender::ConsensusManagerSender;
use tokio::{
runtime::Handle,
sync::{mpsc::Receiver, watch},
Expand Down Expand Up @@ -108,7 +109,7 @@ fn start_consensus_manager<Artifact, Pool>(
// Locally produced adverts to send to the node's peers.
adverts_to_send: Receiver<ArtifactProcessorEvent<Artifact>>,
// Adverts received from peers
adverts_received: Receiver<(AdvertUpdate<Artifact>, NodeId, ConnId)>,
adverts_received: Receiver<(SlotUpdate<Artifact>, NodeId, ConnId)>,
raw_pool: Arc<RwLock<Pool>>,
priority_fn_producer: Arc<dyn PriorityFnAndFilterProducer<Artifact, Pool>>,
sender: CrossbeamSender<UnvalidatedArtifactMutation<Artifact>>,
Expand Down Expand Up @@ -142,7 +143,7 @@ fn start_consensus_manager<Artifact, Pool>(
);
}

pub(crate) struct AdvertUpdate<Artifact: ArtifactKind> {
pub(crate) struct SlotUpdate<Artifact: ArtifactKind> {
slot_number: SlotNumber,
commit_id: CommitId,
update: Update<Artifact>,
Expand All @@ -153,22 +154,22 @@ pub(crate) enum Update<Artifact: ArtifactKind> {
Advert((Artifact::Id, Artifact::Attribute)),
}

impl<Artifact: ArtifactKind> From<AdvertUpdate<Artifact>> for pb::AdvertUpdate {
impl<Artifact: ArtifactKind> From<SlotUpdate<Artifact>> for pb::SlotUpdate {
fn from(
AdvertUpdate {
SlotUpdate {
slot_number,
commit_id,
update,
}: AdvertUpdate<Artifact>,
}: SlotUpdate<Artifact>,
) -> Self {
Self {
commit_id: commit_id.get(),
slot_id: slot_number.get(),
update: Some(match update {
Update::Artifact(artifact) => {
pb::advert_update::Update::Artifact(Artifact::PbMessage::proxy_encode(artifact))
pb::slot_update::Update::Artifact(Artifact::PbMessage::proxy_encode(artifact))
}
Update::Advert((id, attribute)) => pb::advert_update::Update::Advert(pb::Advert {
Update::Advert((id, attribute)) => pb::slot_update::Update::Advert(pb::Advert {
id: Artifact::PbId::proxy_encode(id),
attribute: Artifact::PbAttribute::proxy_encode(attribute),
}),
Expand All @@ -177,22 +178,20 @@ impl<Artifact: ArtifactKind> From<AdvertUpdate<Artifact>> for pb::AdvertUpdate {
}
}

impl<Artifact: ArtifactKind> TryFrom<pb::AdvertUpdate> for AdvertUpdate<Artifact> {
impl<Artifact: ArtifactKind> TryFrom<pb::SlotUpdate> for SlotUpdate<Artifact> {
type Error = ProxyDecodeError;
fn try_from(value: pb::AdvertUpdate) -> Result<Self, Self::Error> {
fn try_from(value: pb::SlotUpdate) -> Result<Self, Self::Error> {
Ok(Self {
slot_number: SlotNumber::from(value.slot_id),
commit_id: CommitId::from(value.commit_id),
update: match try_from_option_field(value.update, "update")? {
pb::advert_update::Update::Artifact(artifact) => {
pb::slot_update::Update::Artifact(artifact) => {
Update::Artifact(Artifact::PbMessage::proxy_decode(&artifact)?)
}
pb::advert_update::Update::Advert(pb::Advert { id, attribute }) => {
Update::Advert((
Artifact::PbId::proxy_decode(&id)?,
Artifact::PbAttribute::proxy_decode(&attribute)?,
))
}
pb::slot_update::Update::Advert(pb::Advert { id, attribute }) => Update::Advert((
Artifact::PbId::proxy_decode(&id)?,
Artifact::PbAttribute::proxy_decode(&attribute)?,
)),
},
})
}
Expand Down
14 changes: 7 additions & 7 deletions rs/p2p/consensus_manager/src/metrics.rs
Expand Up @@ -43,9 +43,9 @@ pub(crate) struct ConsensusManagerMetrics {
pub send_view_send_to_peer_delivered_total: IntCounter,
pub send_view_resend_reconnect_total: IntCounter,

// Slot manager
pub slot_manager_used_slots: IntGauge,
pub slot_manager_maximum_slots_total: IntCounter,
// Available slot set
pub slot_set_in_use_slots: IntGauge,
pub slot_set_allocated_slots_total: IntCounter,
}

impl ConsensusManagerMetrics {
Expand Down Expand Up @@ -250,17 +250,17 @@ impl ConsensusManagerMetrics {
.unwrap(),
),

slot_manager_used_slots: metrics_registry.register(
slot_set_in_use_slots: metrics_registry.register(
IntGauge::with_opts(opts!(
"ic_consensus_manager_slot_manager_used_slots",
"ic_consensus_manager_slot_set_in_use_slots",
"Active slots in use.",
const_labels.clone(),
))
.unwrap(),
),
slot_manager_maximum_slots_total: metrics_registry.register(
slot_set_allocated_slots_total: metrics_registry.register(
IntCounter::with_opts(opts!(
"ic_consensus_manager_slot_manager_maximum_slots_total",
"ic_consensus_manager_slot_set_allocated_slots_total",
"Maximum of slots simultaneously used.",
const_labels.clone(),
))
Expand Down

0 comments on commit 76804db

Please sign in to comment.