Skip to content

Commit

Permalink
fix: aggregate key in inspection receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Jan 11, 2025
1 parent 3a3dace commit 987cc0a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
18 changes: 9 additions & 9 deletions pallets/ddc-verification/src/aggregator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PHDTreePart>,
pub unverified_branches: Vec<InspectedTreePart>,
#[serde(rename = "verifiedBranches")]
pub verified_branches: Vec<PHDTreePart>,
pub verified_branches: Vec<InspectedTreePart>,
}

#[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<u64>,
#[serde(rename = "leafs")]
pub leafs: BTreeMap<u32, Vec<u64>>,
}
}
54 changes: 36 additions & 18 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 = 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.
Expand Down Expand Up @@ -749,7 +749,7 @@ pub mod pallet {
pub(crate) others: Vec<ConsolidatedAggregate<A>>,
}

#[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),
Expand Down Expand Up @@ -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 =
<T::OffchainIdentifierId as AppCrypto<T::Public, T::Signature>>::sign(
&payload,
Expand All @@ -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 #####");
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: 66046,
spec_version: 66048,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 24,
Expand Down

0 comments on commit 987cc0a

Please sign in to comment.