Skip to content

Commit

Permalink
chore: node pub key converter
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Jan 13, 2025
1 parent 987cc0a commit b75f4ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
54 changes: 24 additions & 30 deletions pallets/ddc-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub mod pallet {
133, 222, 234, 46, 190, 36, 6, 43, 198, 64, 231, 190,
]);
pub const EHD_TCAA_START: DdcEra = 28939383;
pub const EHD_TCAA_END: DdcEra = 28939394;
pub const EHD_TCAA_END: DdcEra = 28939395;

/// Delta usage of a bucket includes only the delta usage for the processing era reported by
/// collectors. This usage can be verified of unverified by inspectors.
Expand Down Expand Up @@ -183,8 +183,8 @@ pub mod pallet {

impl HistDocId {
pub fn to_string(&self) -> String {
let hex_key = format!("0x{}", self.0.get_hex());
format!("{}-{}-{}", hex_key, self.1, self.2)
let node_key_str: String = self.0.clone().into();
format!("{}-{}-{}", node_key_str, self.1, self.2)
}

pub fn from_string(s: &str) -> Result<Self, OCWError> {
Expand Down Expand Up @@ -1392,15 +1392,15 @@ pub mod pallet {
n_per_tcaa
};

Self::select_random_leaves(sample_size, ids, node_key.get_hex())
Self::select_random_leaves(sample_size, ids, node_key.clone().into())
} else {
remainder = remainder + (n_per_tcaa - ids_count);
ids
};

log::info!(
"Node {:?} - TCAA {:?}. Selecting {:?} leaves out of {:?} for inspection. Selected leaves {:?}. Additional reminder is {:?}.",
node_key.get_hex(),
node_key.clone(),
tcaa_id,
n_per_tcaa,
ids_count,
Expand Down Expand Up @@ -1443,11 +1443,8 @@ pub mod pallet {

if !verified_tcaas.is_empty() {
verified_phd_parts.push(aggregator_client::json::InspectedTreePart {
collector: format!("0x{}", phd_doc_id.0.clone().get_hex()),
aggregate: AggregateKey::NodeAggregateKey(format!(
"0x{}",
node_key.get_hex()
)),
collector: phd_doc_id.0.clone().into(),
aggregate: AggregateKey::NodeAggregateKey(node_key.clone().into()),
nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes
* of PHD merkle tree */
leafs: verified_tcaas,
Expand All @@ -1456,11 +1453,8 @@ pub mod pallet {

if !unverified_tcaas.is_empty() {
unverified_phd_parts.push(aggregator_client::json::InspectedTreePart {
collector: format!("0x{}", phd_doc_id.0.clone().get_hex()),
aggregate: AggregateKey::NodeAggregateKey(format!(
"0x{}",
node_key.get_hex()
)),
collector: phd_doc_id.0.clone().into(),
aggregate: AggregateKey::NodeAggregateKey(node_key.clone().into()),
nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes
* of PHD merkle tree */
leafs: unverified_tcaas,
Expand Down Expand Up @@ -1522,7 +1516,7 @@ pub mod pallet {
})?;

for (collector_key, collector_params) in collectors {
if collector_key.get_hex() != g_collector.clone().get_hex() {
if collector_key != g_collector {
continue;
};

Expand All @@ -1542,7 +1536,7 @@ pub mod pallet {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching EHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -1583,7 +1577,7 @@ pub mod pallet {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching EHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -1615,7 +1609,7 @@ pub mod pallet {
})?;

for (collector_key, collector_params) in collectors {
if collector_key.get_hex() != ehd_id.0.get_hex() {
if collector_key != ehd_id.0 {
continue;
};

Expand All @@ -1639,7 +1633,7 @@ pub mod pallet {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching EHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -1671,7 +1665,7 @@ pub mod pallet {
})?;

for (collector_key, collector_params) in collectors {
if collector_key.get_hex() != phd_id.0.get_hex() {
if collector_key != phd_id.0 {
continue;
};

Expand All @@ -1695,7 +1689,7 @@ pub mod pallet {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching EHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -1736,7 +1730,7 @@ pub mod pallet {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching PHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -3781,7 +3775,7 @@ pub mod pallet {
})?;

for (key, collector_params) in collectors {
if key.get_hex() != collector_key.get_hex() {
if key != collector_key {
continue;
};

Expand All @@ -3796,15 +3790,15 @@ pub mod pallet {

if let Ok(node_challenge_res) = client.challenge_node_aggregate(
era_id,
&format!("0x{}", node_key.get_hex()),
Into::<String>::into(node_key.clone()).as_str(),
tree_node_ids.clone(),
) {
return Ok(node_challenge_res);
} else {
log::warn!(
"Collector from cluster {:?} is unavailable while fetching EHD record or responded with unexpected body. Key: {:?} Host: {:?}",
cluster_id,
collector_key.get_hex(),
collector_key,
String::from_utf8(collector_params.host)
);
}
Expand Down Expand Up @@ -4010,7 +4004,7 @@ pub mod pallet {
// log::info!(
// "🏭 Obtained DAC Node for cluster_id: {:?} and with key: {:?}",
// cluster_id,
// node_pub_key.get_hex()
// node_pub_key
// );

// Add to the results if the mode matches
Expand Down Expand Up @@ -4043,7 +4037,7 @@ pub mod pallet {
log::warn!(
"Aggregator from cluster {:?} is unavailable while fetching nodes aggregates. Key: {:?} Host: {:?}",
cluster_id,
node_key.get_hex(),
node_key,
String::from_utf8(node_params.host.clone())
);
// skip unavailable aggregators and continue with available ones
Expand Down Expand Up @@ -4089,7 +4083,7 @@ pub mod pallet {
log::warn!(
"Aggregator from cluster {:?} is unavailable while fetching buckets aggregates. Key: {:?} Host: {:?}",
cluster_id,
node_key.get_hex(),
node_key,
String::from_utf8(node_params.host.clone())
);
// skip unavailable aggregators and continue with available ones
Expand Down Expand Up @@ -4128,7 +4122,7 @@ pub mod pallet {
log::warn!(
"Aggregator from cluster {:?} is unavailable while fetching processed eras. Key: {:?} Host: {:?}",
cluster_id,
node_key.get_hex(),
node_key,
String::from_utf8(node_params.host.clone())
);
// skip unavailable aggregators and continue with available ones
Expand Down
13 changes: 7 additions & 6 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use frame_support::parameter_types;
use frame_system::Config;
use polkadot_ckb_merkle_mountain_range::Merge;
use scale_info::{
prelude::{collections::BTreeMap, string::String, vec::Vec},
prelude::{collections::BTreeMap, format, string::String, vec::Vec},
TypeInfo,
};
use serde::{Deserialize, Serialize};
use sp_core::{crypto::KeyTypeId, hash::H160, H256};
use sp_runtime::{AccountId32, Perquintill, RuntimeDebug};
use sp_std::collections::btree_set::BTreeSet;

pub mod traits;

pub mod ocw_mutex;
Expand Down Expand Up @@ -131,17 +130,19 @@ pub struct AggregatorInfo {
pub node_params: StorageNodeParams,
}

// The `StoragePubKey` is the only variant of DDC node key. This enum should be replaced with
// trait-bounded type.
#[derive(
Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, PartialEq, Eq, Encode, Decode, TypeInfo,
)]
pub enum NodePubKey {
StoragePubKey(StorageNodePubKey),
}

impl NodePubKey {
pub fn get_hex(&self) -> String {
match self {
NodePubKey::StoragePubKey(pub_key_ref) => hex::encode(pub_key_ref),
impl From<NodePubKey> for String {
fn from(node_key: NodePubKey) -> Self {
match node_key {
NodePubKey::StoragePubKey(pub_key) => format!("0x{}", hex::encode(pub_key)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 66048,
spec_version: 66053,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 24,
Expand Down

0 comments on commit b75f4ec

Please sign in to comment.