From b75f4ecf81b60ef85308cab3889617c4eda8388a Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 13 Jan 2025 14:42:07 +0100 Subject: [PATCH] chore: node pub key converter --- pallets/ddc-verification/src/lib.rs | 54 +++++++++++++---------------- primitives/src/lib.rs | 13 +++---- runtime/cere-dev/src/lib.rs | 2 +- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/pallets/ddc-verification/src/lib.rs b/pallets/ddc-verification/src/lib.rs index e78303d66..ff31f075b 100644 --- a/pallets/ddc-verification/src/lib.rs +++ b/pallets/ddc-verification/src/lib.rs @@ -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. @@ -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 { @@ -1392,7 +1392,7 @@ 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 @@ -1400,7 +1400,7 @@ pub mod pallet { 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, @@ -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, @@ -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, @@ -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; }; @@ -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) ); } @@ -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) ); } @@ -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; }; @@ -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) ); } @@ -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; }; @@ -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) ); } @@ -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) ); } @@ -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; }; @@ -3796,7 +3790,7 @@ pub mod pallet { if let Ok(node_challenge_res) = client.challenge_node_aggregate( era_id, - &format!("0x{}", node_key.get_hex()), + Into::::into(node_key.clone()).as_str(), tree_node_ids.clone(), ) { return Ok(node_challenge_res); @@ -3804,7 +3798,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) ); } @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 9c826e6f6..00a6573c5 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -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; @@ -131,6 +130,8 @@ 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, )] @@ -138,10 +139,10 @@ 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 for String { + fn from(node_key: NodePubKey) -> Self { + match node_key { + NodePubKey::StoragePubKey(pub_key) => format!("0x{}", hex::encode(pub_key)), } } } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 1c947f6d3..06259cd91 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -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,