From 987cc0a0e4bb61d525abd80bedf825b62c1bf92d Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sat, 11 Jan 2025 01:33:32 +0100 Subject: [PATCH] fix: aggregate key in inspection receipt --- .../ddc-verification/src/aggregator_client.rs | 18 +++---- pallets/ddc-verification/src/lib.rs | 54 ++++++++++++------- runtime/cere-dev/src/lib.rs | 2 +- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/pallets/ddc-verification/src/aggregator_client.rs b/pallets/ddc-verification/src/aggregator_client.rs index fe552cd7f..635ec79a8 100644 --- a/pallets/ddc-verification/src/aggregator_client.rs +++ b/pallets/ddc-verification/src/aggregator_client.rs @@ -909,25 +909,25 @@ pub(crate) mod json { pub ehd_id: String, pub inspector: String, pub signature: String, - #[serde(rename = "inspectionResult")] - pub inspection_result: InspectionResult, + #[serde(rename = "nodesInspection")] + pub nodes_inspection: InspectionResult, + #[serde(rename = "bucketsInspection")] + pub buckets_inspection: InspectionResult, } #[derive(Debug, Serialize, Deserialize, Clone, Hash, Encode, Decode)] pub struct InspectionResult { #[serde(rename = "unverifiedBranches")] - pub unverified_branches: Vec, + pub unverified_branches: Vec, #[serde(rename = "verifiedBranches")] - pub verified_branches: Vec, + pub verified_branches: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Hash, Encode, Decode)] - pub struct PHDTreePart { - #[serde(rename = "phdId")] - pub phd_id: String, - #[serde(rename = "nodes")] + pub struct InspectedTreePart { + pub collector: String, + pub aggregate: AggregateKey, pub nodes: Vec, - #[serde(rename = "leafs")] pub leafs: BTreeMap>, } } diff --git a/pallets/ddc-verification/src/lib.rs b/pallets/ddc-verification/src/lib.rs index 8949c1220..e78303d66 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 = 28939392; + pub const EHD_TCAA_END: DdcEra = 28939394; /// 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. @@ -749,7 +749,7 @@ pub mod pallet { pub(crate) others: Vec>, } - #[derive(Debug, Clone, Encode, Decode, TypeInfo, PartialEq)] + #[derive(Debug, Serialize, Deserialize, Clone, Encode, Decode, Hash, TypeInfo, PartialEq)] pub enum AggregateKey { NodeAggregateKey(String), BucketSubAggregateKey(BucketId, String), @@ -1441,27 +1441,44 @@ pub mod pallet { } } - verified_phd_parts.push(aggregator_client::json::PHDTreePart { - phd_id: phd_doc_id.clone().to_string(), - nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes of - * PHD merkle tree */ - leafs: verified_tcaas, - }); - - unverified_phd_parts.push(aggregator_client::json::PHDTreePart { - phd_id: phd_doc_id.clone().to_string(), - nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes of - * PHD merkle tree */ - leafs: unverified_tcaas, - }); + 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() + )), + nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes + * of PHD merkle tree */ + leafs: verified_tcaas, + }); + } + + 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() + )), + nodes: Vec::new(), /* todo: re-calculate aggregations in branch nodes + * of PHD merkle tree */ + leafs: unverified_tcaas, + }); + } } - let inspection_result = aggregator_client::json::InspectionResult { + let nodes_inspection = aggregator_client::json::InspectionResult { unverified_branches: unverified_phd_parts, verified_branches: verified_phd_parts, }; - let payload = (ehd_doc_id.clone().to_string(), inspection_result.clone()).encode(); + let buckets_inspection = aggregator_client::json::InspectionResult { + unverified_branches: vec![], + verified_branches: vec![], + }; + + let payload = (ehd_doc_id.clone().to_string(), nodes_inspection.clone()).encode(); let signature = >::sign( &payload, @@ -1476,7 +1493,8 @@ pub mod pallet { ehd_id: ehd_doc_id.clone().to_string(), inspector, signature, - inspection_result, + nodes_inspection, + buckets_inspection, }; log::info!("##### INSPECTION RECEIPT #####"); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 9e892bca8..1c947f6d3 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: 66046, + spec_version: 66048, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 24,