Skip to content

Commit e5a2fd1

Browse files
authored
fix(rust/cardano-chain-follower): Use CIP509 from rbac-registration (#96)
* fix: remove Cip509 from chain follower Signed-off-by: bkioshn <[email protected]> * feat: add rbac-registration lib to chain-follower Signed-off-by: bkioshn <[email protected]> * fix: modify cip509 metadatum Signed-off-by: bkioshn <[email protected]> * fix: remove unused function Signed-off-by: bkioshn <[email protected]> * fix: remove unused transaction index Signed-off-by: bkioshn <[email protected]> * fix: remove unused dependencies Signed-off-by: bkioshn <[email protected]> * fix: add getter function Signed-off-by: bkioshn <[email protected]> * fix: remove label Signed-off-by: bkioshn <[email protected]> * test: test new rbac-reg branch Signed-off-by: bkioshn <[email protected]> * fix: remove getter (for consistency) Signed-off-by: bkioshn <[email protected]> * fix: update rbac-registration to tag v0.0.8 Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]>
1 parent 1747c61 commit e5a2fd1

File tree

13 files changed

+88
-2242
lines changed

13 files changed

+88
-2242
lines changed

rust/cardano-chain-follower/Cargo.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mithril-client = { version = "0.8.18", default-features = false, features = [
2121
"num-integer-backend",
2222
] }
2323

24-
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git" , tag = "v0.0.3" }
24+
rbac-registration = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.8" }
2525

2626
thiserror = "1.0.64"
2727
tokio = { version = "1.40.0", features = [
@@ -53,9 +53,7 @@ mimalloc = { version = "0.1.43", optional = true }
5353
memx = "0.1.32"
5454
fmmap = { version = "0.3.3", features = ["sync", "tokio-async"] }
5555
minicbor = { version = "0.25.1", features = ["alloc", "derive", "half"] }
56-
brotli = "7.0.0"
5756
zstd = "0.13.2"
58-
x509-cert = "0.2.5"
5957
ed25519-dalek = "2.1.1"
6058
blake2b_simd = "1.0.2"
6159
num-traits = "0.2.19"
@@ -65,9 +63,6 @@ ureq = { version = "2.10.1", features = ["native-certs"] }
6563
http = "1.1.0"
6664
hickory-resolver = { version = "0.24.1", features = ["dns-over-rustls"] }
6765
moka = { version = "0.12.8", features = ["sync"] }
68-
der-parser = "9.0.0"
69-
regex = "1.11.0"
70-
bech32 = "0.11.0"
7166

7267
[dev-dependencies]
7368
hex = "0.4.3"

rust/cardano-chain-follower/examples/follow_chains.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#[cfg(feature = "mimalloc")]
99
use mimalloc::MiMalloc;
10+
use rbac_registration::cardano::cip509;
1011

1112
/// Use Mimalloc for the global allocator.
1213
#[cfg(feature = "mimalloc")]
@@ -329,10 +330,7 @@ fn update_biggest_aux_data(
329330
None => 0,
330331
};
331332

332-
let raw_size_cip509 = match chain_update
333-
.data
334-
.txn_raw_metadata(tx_idx, Metadata::cip509::LABEL)
335-
{
333+
let raw_size_cip509 = match chain_update.data.txn_raw_metadata(tx_idx, cip509::LABEL) {
336334
Some(raw) => raw.len(),
337335
None => 0,
338336
};
@@ -368,10 +366,7 @@ fn log_bad_cip36_info(chain_update: &ChainUpdate, network: Network, tx_idx: usiz
368366

369367
/// Helper function for logging CIP509 validation.
370368
fn log_cip509_info(chain_update: &ChainUpdate, block_num: u64, network: Network, tx_idx: usize) {
371-
if let Some(decoded_metadata) = chain_update
372-
.data
373-
.txn_metadata(tx_idx, Metadata::cip509::LABEL)
374-
{
369+
if let Some(decoded_metadata) = chain_update.data.txn_metadata(tx_idx, cip509::LABEL) {
375370
info!("Block Number {}", block_num);
376371

377372
if let Metadata::DecodedMetadataValues::Cip509(cip509) = &decoded_metadata.value {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//! Cardano Improvement Proposal 509 (CIP-509) metadata module.
2+
//! Doc Reference: <https://github.com/input-output-hk/catalyst-CIPs/tree/x509-envelope-metadata/CIP-XXXX>
3+
//! CDDL Reference: <https://github.com/input-output-hk/catalyst-CIPs/blob/x509-envelope-metadata/CIP-XXXX/x509-envelope.cddl>
4+
5+
use std::sync::Arc;
6+
7+
use minicbor::{Decode, Decoder};
8+
use pallas::ledger::traverse::MultiEraTx;
9+
use rbac_registration::cardano::cip509::{Cip509 as RbacRegCip509, Cip509Validation, LABEL};
10+
11+
use super::{
12+
DecodedMetadata, DecodedMetadataItem, DecodedMetadataValues, RawAuxData, ValidationReport,
13+
};
14+
15+
/// CIP509 metadatum.
16+
#[derive(Debug, PartialEq, Clone, Default)]
17+
pub struct Cip509 {
18+
/// CIP509 data.
19+
pub cip509: RbacRegCip509,
20+
/// Validation value, not a part of CIP509, justs storing validity of the data.
21+
pub validation: Cip509Validation,
22+
}
23+
24+
impl Cip509 {
25+
/// Decode and validate CIP509 Metadata
26+
///
27+
/// # Returns
28+
///
29+
/// Nothing. IF CIP509 Metadata is found it will be updated in `decoded_metadata`.
30+
pub(crate) fn decode_and_validate(
31+
decoded_metadata: &DecodedMetadata, txn: &MultiEraTx, raw_aux_data: &RawAuxData,
32+
) {
33+
// Get the CIP509 metadata if possible
34+
let Some(k509) = raw_aux_data.get_metadata(LABEL) else {
35+
return;
36+
};
37+
38+
let mut validation_report = ValidationReport::new();
39+
let mut decoder = Decoder::new(k509.as_slice());
40+
41+
let cip509 = match RbacRegCip509::decode(&mut decoder, &mut ()) {
42+
Ok(metadata) => metadata,
43+
Err(e) => {
44+
Cip509::default().validation_failure(
45+
&format!("Failed to decode CIP509 metadata: {e}"),
46+
&mut validation_report,
47+
decoded_metadata,
48+
);
49+
return;
50+
},
51+
};
52+
53+
// Validate the decoded metadata
54+
let validation = cip509.validate(txn, &mut validation_report);
55+
56+
// Create a Cip509 struct and insert it into decoded_metadata
57+
decoded_metadata.0.insert(
58+
LABEL,
59+
Arc::new(DecodedMetadataItem {
60+
value: DecodedMetadataValues::Cip509(Arc::new(Cip509 { cip509, validation })),
61+
report: validation_report.clone(),
62+
}),
63+
);
64+
}
65+
66+
/// Handle validation failure.
67+
fn validation_failure(
68+
&self, reason: &str, validation_report: &mut ValidationReport,
69+
decoded_metadata: &DecodedMetadata,
70+
) {
71+
validation_report.push(reason.into());
72+
decoded_metadata.0.insert(
73+
LABEL,
74+
Arc::new(DecodedMetadataItem {
75+
value: DecodedMetadataValues::Cip509(Arc::new(self.clone()).clone()),
76+
report: validation_report.clone(),
77+
}),
78+
);
79+
}
80+
}

rust/cardano-chain-follower/src/metadata/cip509/decode_helper.rs

-215
This file was deleted.

0 commit comments

Comments
 (0)