From eb0d28b59b550abc7a942a49f85c07bf4fa7f9b2 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 22 Oct 2024 20:33:12 +0700 Subject: [PATCH 1/8] feat: rbac --- .../src/metadata/cip509/mod.rs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/rust/cardano-chain-follower/src/metadata/cip509/mod.rs b/rust/cardano-chain-follower/src/metadata/cip509/mod.rs index 6a622e8cd..202156ab6 100644 --- a/rust/cardano-chain-follower/src/metadata/cip509/mod.rs +++ b/rust/cardano-chain-follower/src/metadata/cip509/mod.rs @@ -24,7 +24,7 @@ use pallas::{ minicbor::{Encode, Encoder}, utils::Bytes, }, - ledger::traverse::MultiEraTx, + ledger::traverse::MultiEraTxWithRawAuxiliary, }; use rbac::{certs::C509Cert, role_data::RoleData}; use strum::FromRepr; @@ -189,7 +189,7 @@ impl Cip509 { /// /// Nothing. IF CIP509 Metadata is found it will be updated in `decoded_metadata`. pub(crate) fn decode_and_validate( - decoded_metadata: &DecodedMetadata, txn: &MultiEraTx, raw_aux_data: &RawAuxData, + decoded_metadata: &DecodedMetadata, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, txn_idx: usize, ) { // Get the CIP509 metadata if possible @@ -297,13 +297,13 @@ impl Cip509 { /// Transaction inputs hash validation. /// Must exist and match the hash of the transaction inputs. fn validate_txn_inputs_hash( - &self, txn: &MultiEraTx, validation_report: &mut ValidationReport, + &self, txn: &MultiEraTxWithRawAuxiliary, validation_report: &mut ValidationReport, decoded_metadata: &DecodedMetadata, ) -> Option { let mut buffer = Vec::new(); let mut e = Encoder::new(&mut buffer); match txn { - MultiEraTx::AlonzoCompatible(tx, _) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(tx, _) => { let inputs = tx.transaction_body.inputs.clone(); if let Err(e) = e.array(inputs.len() as u64) { self.validation_failure( @@ -324,7 +324,7 @@ impl Cip509 { } } }, - MultiEraTx::Babbage(tx) => { + MultiEraTxWithRawAuxiliary::Babbage(tx) => { let inputs = tx.transaction_body.inputs.clone(); if let Err(e) = e.array(inputs.len() as u64) { self.validation_failure( @@ -345,7 +345,7 @@ impl Cip509 { } } }, - MultiEraTx::Conway(tx) => { + MultiEraTxWithRawAuxiliary::Conway(tx) => { let inputs = tx.transaction_body.inputs.clone(); if let Err(e) = e.array(inputs.len() as u64) { self.validation_failure( @@ -398,11 +398,11 @@ impl Cip509 { /// Also log out the pre-computed hash where the validation signature (99) set to /// zero. fn validate_aux( - &mut self, txn: &MultiEraTx, validation_report: &mut ValidationReport, + &mut self, txn: &MultiEraTxWithRawAuxiliary, validation_report: &mut ValidationReport, decoded_metadata: &DecodedMetadata, ) -> Option { match txn { - MultiEraTx::AlonzoCompatible(tx, _) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(tx, _) => { if let pallas::codec::utils::Nullable::Some(a) = &tx.auxiliary_data { let original_aux = a.raw_cbor(); let aux_data_hash = @@ -432,7 +432,7 @@ impl Cip509 { None } }, - MultiEraTx::Babbage(tx) => { + MultiEraTxWithRawAuxiliary::Babbage(tx) => { if let pallas::codec::utils::Nullable::Some(a) = &tx.auxiliary_data { let original_aux = a.raw_cbor(); let aux_data_hash = @@ -462,7 +462,7 @@ impl Cip509 { None } }, - MultiEraTx::Conway(tx) => { + MultiEraTxWithRawAuxiliary::Conway(tx) => { if let pallas::codec::utils::Nullable::Some(a) = &tx.auxiliary_data { let original_aux = a.raw_cbor(); let aux_data_hash = @@ -535,12 +535,12 @@ impl Cip509 { /// Validate the stake public key in the certificate with witness set in transaction. #[allow(clippy::too_many_lines)] fn validate_stake_public_key( - &self, txn: &MultiEraTx, validation_report: &mut ValidationReport, + &self, txn: &MultiEraTxWithRawAuxiliary, validation_report: &mut ValidationReport, decoded_metadata: &DecodedMetadata, txn_idx: usize, ) -> Option { let mut pk_addrs = Vec::new(); match txn { - MultiEraTx::AlonzoCompatible(..) | MultiEraTx::Babbage(_) | MultiEraTx::Conway(_) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(..) | MultiEraTxWithRawAuxiliary::Babbage(_) | MultiEraTxWithRawAuxiliary::Conway(_) => { // X509 certificate if let Some(x509_certs) = &self.x509_chunks.0.x509_certs { for cert in x509_certs { @@ -740,7 +740,7 @@ impl Cip509 { /// Validate the payment key #[allow(clippy::too_many_lines)] fn validate_payment_key( - &self, txn: &MultiEraTx, validation_report: &mut ValidationReport, + &self, txn: &MultiEraTxWithRawAuxiliary, validation_report: &mut ValidationReport, decoded_metadata: &DecodedMetadata, txn_idx: usize, role_data: &RoleData, ) -> Option { if let Some(payment_key) = role_data.payment_key { @@ -754,7 +754,7 @@ impl Cip509 { return None; } match txn { - MultiEraTx::AlonzoCompatible(tx, _) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(tx, _) => { // Handle negative payment keys (reference to tx output) if payment_key < 0 { let witness = match TxWitness::new(&[txn.clone()]) { @@ -819,7 +819,7 @@ impl Cip509 { } return Some(true); }, - MultiEraTx::Babbage(tx) => { + MultiEraTxWithRawAuxiliary::Babbage(tx) => { // Negative indicates reference to tx output if payment_key < 0 { let index = match decremented_index(payment_key.abs()) { @@ -887,7 +887,7 @@ impl Cip509 { } return Some(true); }, - MultiEraTx::Conway(tx) => { + MultiEraTxWithRawAuxiliary::Conway(tx) => { // Negative indicates reference to tx output if payment_key < 0 { let index = match decremented_index(payment_key.abs()) { @@ -1025,7 +1025,7 @@ mod tests { .expect("Failed to decode hex block.") } - fn cip_509_aux_data(tx: &MultiEraTx<'_>) -> Vec { + fn cip_509_aux_data(tx: &pallas::ledger::traverse::MultiEraTxWithRawAuxiliary<'_>) -> Vec { let raw_auxiliary_data = tx .as_conway() .unwrap() @@ -1079,7 +1079,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); @@ -1101,7 +1101,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); @@ -1124,7 +1124,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); @@ -1147,7 +1147,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); @@ -1183,7 +1183,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_3(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); @@ -1220,7 +1220,7 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_2(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlock::decode(&conway_block_data) + let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); From 9784eba5c69636df98bc9202c74c9b05eaba6324 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 22 Oct 2024 20:35:34 +0700 Subject: [PATCH 2/8] feat: witness --- rust/cardano-chain-follower/src/witness.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/cardano-chain-follower/src/witness.rs b/rust/cardano-chain-follower/src/witness.rs index f649d6b9f..e5a77b392 100644 --- a/rust/cardano-chain-follower/src/witness.rs +++ b/rust/cardano-chain-follower/src/witness.rs @@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter}; use dashmap::DashMap; -use pallas::{codec::utils::Bytes, ledger::traverse::MultiEraTx}; +use pallas::{codec::utils::Bytes, ledger::traverse::MultiEraTxWithRawAuxiliary}; use crate::utils::blake2b_244; @@ -17,11 +17,11 @@ pub(crate) struct TxWitness(WitnessMap); impl TxWitness { /// Create a new `TxWitness` from a list of `MultiEraTx`. - pub(crate) fn new(txs: &[MultiEraTx]) -> anyhow::Result { + pub(crate) fn new(txs: &[MultiEraTxWithRawAuxiliary]) -> anyhow::Result { let map: WitnessMap = DashMap::new(); for (i, tx) in txs.iter().enumerate() { match tx { - MultiEraTx::AlonzoCompatible(tx, _) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(tx, _) => { let witness_set = &tx.transaction_witness_set; if let Some(vkey_witness_set) = witness_set.vkeywitness.clone() { for vkey_witness in vkey_witness_set { @@ -33,7 +33,7 @@ impl TxWitness { } }; }, - MultiEraTx::Babbage(tx) => { + MultiEraTxWithRawAuxiliary::Babbage(tx) => { let witness_set = &tx.transaction_witness_set; if let Some(vkey_witness_set) = witness_set.vkeywitness.clone() { for vkey_witness in vkey_witness_set { @@ -45,7 +45,7 @@ impl TxWitness { } } }, - MultiEraTx::Conway(tx) => { + MultiEraTxWithRawAuxiliary::Conway(tx) => { let witness_set = &tx.transaction_witness_set; if let Some(vkey_witness_set) = &witness_set.vkeywitness.clone() { for vkey_witness in vkey_witness_set { @@ -103,7 +103,7 @@ mod tests { #[test] fn tx_witness() { let alonzo = alonzo_block(); - let alonzo_block = pallas::ledger::traverse::MultiEraBlock::decode(&alonzo) + let alonzo_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&alonzo) .expect("Failed to decode MultiEraBlock"); let txs_alonzo = alonzo_block.txs(); let tx_witness_alonzo = TxWitness::new(&txs_alonzo).expect("Failed to create TxWitness"); @@ -117,7 +117,7 @@ mod tests { assert!(tx_witness_alonzo.check_witness_in_tx(&vkey1_hash, 0)); let babbage = babbage_block(); - let babbage_block = pallas::ledger::traverse::MultiEraBlock::decode(&babbage) + let babbage_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&babbage) .expect("Failed to decode MultiEraBlock"); let txs_babbage = babbage_block.txs(); let tx_witness_babbage = TxWitness::new(&txs_babbage).expect("Failed to create TxWitness"); From ca5ffc34680fb599ce4fcc111f547518f923cd7a Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 22 Oct 2024 20:44:09 +0700 Subject: [PATCH 3/8] feat: multi era block --- .../src/metadata/cip36.rs | 8 ++--- .../src/metadata/mod.rs | 8 ++--- .../src/multi_era_block_data.rs | 30 ++++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/rust/cardano-chain-follower/src/metadata/cip36.rs b/rust/cardano-chain-follower/src/metadata/cip36.rs index e277840a4..1b3c54c06 100644 --- a/rust/cardano-chain-follower/src/metadata/cip36.rs +++ b/rust/cardano-chain-follower/src/metadata/cip36.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use ed25519_dalek::Verifier; use minicbor::Decoder; -use pallas::ledger::traverse::MultiEraTx; +use pallas::ledger::traverse::MultiEraTxWithRawAuxiliary; use tracing::debug; use super::{ @@ -91,7 +91,7 @@ impl Cip36 { /// Nothing. IF CIP36 Metadata is found it will be updated in `decoded_metadata`. #[allow(clippy::too_many_lines)] pub(crate) fn decode_and_validate( - decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTx, raw_aux_data: &RawAuxData, + decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, catalyst_strict: bool, chain: Network, ) { let k61284 = raw_aux_data.get_metadata(LABEL); @@ -377,7 +377,7 @@ impl Cip36 { /// Decode the Payment Address Metadata in the CIP36 Metadata map. fn decode_payment_address( &mut self, decoder: &mut Decoder, validation_report: &mut ValidationReport, - decoded_metadata: &DecodedMetadata, _txn: &MultiEraTx, chain: Network, + decoded_metadata: &DecodedMetadata, _txn: &MultiEraTxWithRawAuxiliary, chain: Network, ) -> Option { let raw_address = match decoder.bytes() { Ok(address) => address, @@ -969,7 +969,7 @@ mod tests { let mut cip36 = create_empty_cip36(false); let mut decoder = Decoder::new(&hex_data); let mut report = ValidationReport::new(); - let multi_era_tx: *const MultiEraTx = std::ptr::null(); + let multi_era_tx: *const MultiEraTxWithRawAuxiliary = std::ptr::null(); let multi_era_tx = unsafe { &*multi_era_tx }; let rc = cip36.decode_payment_address( diff --git a/rust/cardano-chain-follower/src/metadata/mod.rs b/rust/cardano-chain-follower/src/metadata/mod.rs index 1f624f398..ae6fba675 100644 --- a/rust/cardano-chain-follower/src/metadata/mod.rs +++ b/rust/cardano-chain-follower/src/metadata/mod.rs @@ -5,7 +5,7 @@ use std::{fmt::Debug, sync::Arc}; use cip36::Cip36; use cip509::Cip509; use dashmap::DashMap; -use pallas::ledger::traverse::{MultiEraBlock, MultiEraTx}; +use pallas::ledger::traverse::{MultiEraBlockWithRawAuxiliary, MultiEraTxWithRawAuxiliary}; use raw_aux_data::RawAuxData; use tracing::error; @@ -50,7 +50,7 @@ pub(crate) struct DecodedMetadata(DashMap>); impl DecodedMetadata { /// Create new decoded metadata for a transaction. fn new( - chain: Network, slot: u64, txn: &MultiEraTx, raw_aux_data: &RawAuxData, txn_idx: usize, + chain: Network, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, txn_idx: usize, ) -> Self { let decoded_metadata = Self(DashMap::new()); @@ -98,7 +98,7 @@ impl DecodedTransaction { /// Insert another transaction worth of data into the Decoded Aux Data fn insert( &mut self, chain: Network, slot: u64, txn_idx: u32, cbor_data: &[u8], - transactions: &[MultiEraTx], + transactions: &[MultiEraTxWithRawAuxiliary], ) { let txn_idx = usize_from_saturating(txn_idx); @@ -115,7 +115,7 @@ impl DecodedTransaction { } /// Create a new `DecodedTransaction`. - pub(crate) fn new(chain: Network, block: &MultiEraBlock) -> Self { + pub(crate) fn new(chain: Network, block: &MultiEraBlockWithRawAuxiliary) -> Self { let mut decoded_aux_data = DecodedTransaction { raw: DashMap::new(), decoded: DashMap::new(), diff --git a/rust/cardano-chain-follower/src/multi_era_block_data.rs b/rust/cardano-chain-follower/src/multi_era_block_data.rs index c5f1e85b6..42a91639c 100644 --- a/rust/cardano-chain-follower/src/multi_era_block_data.rs +++ b/rust/cardano-chain-follower/src/multi_era_block_data.rs @@ -10,6 +10,7 @@ use std::{cmp::Ordering, fmt::Display, sync::Arc}; use ouroboros::self_referencing; +use pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary; use tracing::debug; use crate::{ @@ -30,7 +31,7 @@ pub(crate) struct SelfReferencedMultiEraBlock { /// References the `raw_data` field. #[borrows(raw_data)] #[covariant] - block: pallas::ledger::traverse::MultiEraBlock<'this>, + block: MultiEraBlockWithRawAuxiliary<'this>, } /// Multi-era block - inner. @@ -89,7 +90,7 @@ impl MultiEraBlock { let builder = SelfReferencedMultiEraBlockTryBuilder { raw_data, block_builder: |raw_data| -> Result<_, Error> { - pallas::ledger::traverse::MultiEraBlock::decode(raw_data) + MultiEraBlockWithRawAuxiliary::decode(raw_data) .map_err(|err| Error::Codec(err.to_string())) }, }; @@ -104,7 +105,7 @@ impl MultiEraBlock { let byron_block = matches!( decoded_block, - pallas::ledger::traverse::MultiEraBlock::Byron(_) + MultiEraBlockWithRawAuxiliary::Byron(_) ); // debug!("New Block: {slot} {point} {}", *previous); @@ -180,7 +181,7 @@ impl MultiEraBlock { /// The decoded block data, which can easily be processed by a consumer. #[must_use] #[allow(clippy::missing_panics_doc)] - pub fn decode(&self) -> &pallas::ledger::traverse::MultiEraBlock { + pub fn decode(&self) -> &MultiEraBlockWithRawAuxiliary { self.inner.data.borrow_block() } @@ -308,15 +309,15 @@ impl Display for MultiEraBlock { }; let block_era = match block { - pallas::ledger::traverse::MultiEraBlock::EpochBoundary(_) => { + MultiEraBlockWithRawAuxiliary::EpochBoundary(_) => { "Byron Epoch Boundary".to_string() }, - pallas::ledger::traverse::MultiEraBlock::AlonzoCompatible(_, era) => { + MultiEraBlockWithRawAuxiliary::AlonzoCompatible(_, era) => { format!("{era}") }, - pallas::ledger::traverse::MultiEraBlock::Babbage(_) => "Babbage".to_string(), - pallas::ledger::traverse::MultiEraBlock::Byron(_) => "Byron".to_string(), - pallas::ledger::traverse::MultiEraBlock::Conway(_) => "Conway".to_string(), + MultiEraBlockWithRawAuxiliary::Babbage(_) => "Babbage".to_string(), + MultiEraBlockWithRawAuxiliary::Byron(_) => "Byron".to_string(), + MultiEraBlockWithRawAuxiliary::Conway(_) => "Conway".to_string(), _ => "Unknown".to_string(), }; write!(f, "{block_era} block : {}, Previous {} : Slot# {slot} : {fork} : Block# {block_number} : Size {size} : Txns {txns} : AuxData? {aux_data}", @@ -373,6 +374,7 @@ pub(crate) mod tests { use anyhow::Ok; + use super::*; use crate::{point::ORIGIN_POINT, MultiEraBlock, Network, Point}; struct TestRecord { @@ -457,7 +459,7 @@ pub(crate) mod tests { fn test_multi_era_block_point_compare_1() -> anyhow::Result<()> { for (i, test_block) in test_blocks().into_iter().enumerate() { let pallas_block = - pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?; + MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new( pallas_block.slot().add(i as u64), @@ -482,7 +484,7 @@ pub(crate) mod tests { fn test_multi_era_block_point_compare_2() -> anyhow::Result<()> { for test_block in test_blocks() { let pallas_block = - pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?; + MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new(pallas_block.slot() - 1, vec![0; 32]); @@ -500,7 +502,7 @@ pub(crate) mod tests { fn test_multi_era_block_point_compare_3() -> anyhow::Result<()> { for test_block in test_blocks() { let pallas_block = - pallas::ledger::traverse::MultiEraBlock::decode(test_block.raw.as_slice())?; + MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new( pallas_block.slot() - 1, @@ -525,7 +527,7 @@ pub(crate) mod tests { raw_blocks .iter() .map(|block| { - let prev_point = pallas::ledger::traverse::MultiEraBlock::decode(block.as_slice()) + let prev_point = MultiEraBlockWithRawAuxiliary::decode(block.as_slice()) .map(|block| { Point::new( block.slot() - 1, @@ -549,7 +551,7 @@ pub(crate) mod tests { raw_blocks .iter() .map(|block| { - pallas::ledger::traverse::MultiEraBlock::decode(block.as_slice()) + MultiEraBlockWithRawAuxiliary::decode(block.as_slice()) .map(|block| { Point::new( block.slot(), From 9343cdf8ba96a9f03f57804d6adbf6b3c21ce88f Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 22 Oct 2024 20:47:15 +0700 Subject: [PATCH 4/8] feat: all --- rust/cardano-chain-follower/src/follow.rs | 4 +++- rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rust/cardano-chain-follower/src/follow.rs b/rust/cardano-chain-follower/src/follow.rs index 95972ce23..95f8d495f 100644 --- a/rust/cardano-chain-follower/src/follow.rs +++ b/rust/cardano-chain-follower/src/follow.rs @@ -361,13 +361,15 @@ impl ChainFollower { #[cfg(test)] mod tests { + use pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary; + use super::*; fn mock_block() -> MultiEraBlock { let raw_block = hex::decode(include_str!("./../test_data/shelley.block")) .expect("Failed to decode hex block."); - let pallas_block = pallas::ledger::traverse::MultiEraBlock::decode(raw_block.as_slice()) + let pallas_block = MultiEraBlockWithRawAuxiliary::decode(raw_block.as_slice()) .expect("cannot decode block"); let previous_point = Point::new( diff --git a/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs b/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs index 3e1d4f079..fdc1e47d7 100644 --- a/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs +++ b/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs @@ -7,6 +7,7 @@ use std::{ }; use logcall::logcall; +use pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary; use tokio::task; use tracing::{debug, error}; use tracing_log::log; @@ -85,7 +86,7 @@ impl MithrilSnapshotIterator { match next { Some(Ok(raw_block)) => { - let Ok(block) = pallas::ledger::traverse::MultiEraBlock::decode(&raw_block) + let Ok(block) = MultiEraBlockWithRawAuxiliary::decode(&raw_block) else { return None; }; @@ -238,7 +239,7 @@ impl Iterator for MithrilSnapshotIteratorInner { // We cannot fully decode this block because we don't know its previous point, // So this MUST be the first block in iteration, so use it as the previous. if let Ok(raw_decoded_block) = - pallas::ledger::traverse::MultiEraBlock::decode(&block) + MultiEraBlockWithRawAuxiliary::decode(&block) { // debug!("Pre Previous update 2 : {:?}", self.previous); self.previous = From bb3b10e175114f7171a974809bf60ab6d7bc0a93 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Tue, 22 Oct 2024 20:49:37 +0700 Subject: [PATCH 5/8] chore: fmtfix --- .../src/metadata/cip36.rs | 4 +- .../src/metadata/cip509/mod.rs | 38 +++++++++++-------- .../src/metadata/mod.rs | 3 +- .../src/mithril_snapshot_iterator.rs | 7 +--- .../src/multi_era_block_data.rs | 18 +++------ rust/cardano-chain-follower/src/witness.rs | 5 ++- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/rust/cardano-chain-follower/src/metadata/cip36.rs b/rust/cardano-chain-follower/src/metadata/cip36.rs index 1b3c54c06..375d1dfa1 100644 --- a/rust/cardano-chain-follower/src/metadata/cip36.rs +++ b/rust/cardano-chain-follower/src/metadata/cip36.rs @@ -91,8 +91,8 @@ impl Cip36 { /// Nothing. IF CIP36 Metadata is found it will be updated in `decoded_metadata`. #[allow(clippy::too_many_lines)] pub(crate) fn decode_and_validate( - decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, - catalyst_strict: bool, chain: Network, + decoded_metadata: &DecodedMetadata, slot: u64, txn: &MultiEraTxWithRawAuxiliary, + raw_aux_data: &RawAuxData, catalyst_strict: bool, chain: Network, ) { let k61284 = raw_aux_data.get_metadata(LABEL); let k61285 = raw_aux_data.get_metadata(SIG_LABEL); diff --git a/rust/cardano-chain-follower/src/metadata/cip509/mod.rs b/rust/cardano-chain-follower/src/metadata/cip509/mod.rs index 202156ab6..80ebc4873 100644 --- a/rust/cardano-chain-follower/src/metadata/cip509/mod.rs +++ b/rust/cardano-chain-follower/src/metadata/cip509/mod.rs @@ -189,8 +189,8 @@ impl Cip509 { /// /// Nothing. IF CIP509 Metadata is found it will be updated in `decoded_metadata`. pub(crate) fn decode_and_validate( - decoded_metadata: &DecodedMetadata, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, - txn_idx: usize, + decoded_metadata: &DecodedMetadata, txn: &MultiEraTxWithRawAuxiliary, + raw_aux_data: &RawAuxData, txn_idx: usize, ) { // Get the CIP509 metadata if possible let Some(k509) = raw_aux_data.get_metadata(LABEL) else { @@ -540,7 +540,9 @@ impl Cip509 { ) -> Option { let mut pk_addrs = Vec::new(); match txn { - MultiEraTxWithRawAuxiliary::AlonzoCompatible(..) | MultiEraTxWithRawAuxiliary::Babbage(_) | MultiEraTxWithRawAuxiliary::Conway(_) => { + MultiEraTxWithRawAuxiliary::AlonzoCompatible(..) + | MultiEraTxWithRawAuxiliary::Babbage(_) + | MultiEraTxWithRawAuxiliary::Conway(_) => { // X509 certificate if let Some(x509_certs) = &self.x509_chunks.0.x509_certs { for cert in x509_certs { @@ -1079,8 +1081,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // Forth transaction of this test data contains the CIP509 auxiliary data @@ -1101,8 +1104,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // Forth transaction of this test data contains the CIP509 auxiliary data @@ -1124,8 +1128,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // Forth transaction of this test data contains the CIP509 auxiliary data @@ -1147,8 +1152,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_1(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // Forth transaction of this test data contains the CIP509 auxiliary data @@ -1183,8 +1189,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_3(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // First transaction of this test data contains the CIP509 auxiliary data @@ -1220,8 +1227,9 @@ mod tests { let decoded_metadata = DecodedMetadata(DashMap::new()); let mut validation_report = ValidationReport::new(); let conway_block_data = conway_2(); - let multi_era_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) - .expect("Failed to decode MultiEraBlock"); + let multi_era_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&conway_block_data) + .expect("Failed to decode MultiEraBlock"); let transactions = multi_era_block.txs(); // Forth transaction of this test data contains the CIP509 auxiliary data diff --git a/rust/cardano-chain-follower/src/metadata/mod.rs b/rust/cardano-chain-follower/src/metadata/mod.rs index ae6fba675..5ce24cf3d 100644 --- a/rust/cardano-chain-follower/src/metadata/mod.rs +++ b/rust/cardano-chain-follower/src/metadata/mod.rs @@ -50,7 +50,8 @@ pub(crate) struct DecodedMetadata(DashMap>); impl DecodedMetadata { /// Create new decoded metadata for a transaction. fn new( - chain: Network, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, txn_idx: usize, + chain: Network, slot: u64, txn: &MultiEraTxWithRawAuxiliary, raw_aux_data: &RawAuxData, + txn_idx: usize, ) -> Self { let decoded_metadata = Self(DashMap::new()); diff --git a/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs b/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs index fdc1e47d7..343dbbdb1 100644 --- a/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs +++ b/rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs @@ -86,8 +86,7 @@ impl MithrilSnapshotIterator { match next { Some(Ok(raw_block)) => { - let Ok(block) = MultiEraBlockWithRawAuxiliary::decode(&raw_block) - else { + let Ok(block) = MultiEraBlockWithRawAuxiliary::decode(&raw_block) else { return None; }; @@ -238,9 +237,7 @@ impl Iterator for MithrilSnapshotIteratorInner { // We cannot fully decode this block because we don't know its previous point, // So this MUST be the first block in iteration, so use it as the previous. - if let Ok(raw_decoded_block) = - MultiEraBlockWithRawAuxiliary::decode(&block) - { + if let Ok(raw_decoded_block) = MultiEraBlockWithRawAuxiliary::decode(&block) { // debug!("Pre Previous update 2 : {:?}", self.previous); self.previous = Point::new(raw_decoded_block.slot(), raw_decoded_block.hash().to_vec()); diff --git a/rust/cardano-chain-follower/src/multi_era_block_data.rs b/rust/cardano-chain-follower/src/multi_era_block_data.rs index 42a91639c..febdb7a30 100644 --- a/rust/cardano-chain-follower/src/multi_era_block_data.rs +++ b/rust/cardano-chain-follower/src/multi_era_block_data.rs @@ -103,10 +103,7 @@ impl MultiEraBlock { let point = Point::new(slot, decoded_block.hash().to_vec()); - let byron_block = matches!( - decoded_block, - MultiEraBlockWithRawAuxiliary::Byron(_) - ); + let byron_block = matches!(decoded_block, MultiEraBlockWithRawAuxiliary::Byron(_)); // debug!("New Block: {slot} {point} {}", *previous); @@ -309,9 +306,7 @@ impl Display for MultiEraBlock { }; let block_era = match block { - MultiEraBlockWithRawAuxiliary::EpochBoundary(_) => { - "Byron Epoch Boundary".to_string() - }, + MultiEraBlockWithRawAuxiliary::EpochBoundary(_) => "Byron Epoch Boundary".to_string(), MultiEraBlockWithRawAuxiliary::AlonzoCompatible(_, era) => { format!("{era}") }, @@ -458,8 +453,7 @@ pub(crate) mod tests { #[test] fn test_multi_era_block_point_compare_1() -> anyhow::Result<()> { for (i, test_block) in test_blocks().into_iter().enumerate() { - let pallas_block = - MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; + let pallas_block = MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new( pallas_block.slot().add(i as u64), @@ -483,8 +477,7 @@ pub(crate) mod tests { #[test] fn test_multi_era_block_point_compare_2() -> anyhow::Result<()> { for test_block in test_blocks() { - let pallas_block = - MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; + let pallas_block = MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new(pallas_block.slot() - 1, vec![0; 32]); @@ -501,8 +494,7 @@ pub(crate) mod tests { #[test] fn test_multi_era_block_point_compare_3() -> anyhow::Result<()> { for test_block in test_blocks() { - let pallas_block = - MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; + let pallas_block = MultiEraBlockWithRawAuxiliary::decode(test_block.raw.as_slice())?; let previous_point = Point::new( pallas_block.slot() - 1, diff --git a/rust/cardano-chain-follower/src/witness.rs b/rust/cardano-chain-follower/src/witness.rs index e5a77b392..bc6cffa65 100644 --- a/rust/cardano-chain-follower/src/witness.rs +++ b/rust/cardano-chain-follower/src/witness.rs @@ -117,8 +117,9 @@ mod tests { assert!(tx_witness_alonzo.check_witness_in_tx(&vkey1_hash, 0)); let babbage = babbage_block(); - let babbage_block = pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&babbage) - .expect("Failed to decode MultiEraBlock"); + let babbage_block = + pallas::ledger::traverse::MultiEraBlockWithRawAuxiliary::decode(&babbage) + .expect("Failed to decode MultiEraBlock"); let txs_babbage = babbage_block.txs(); let tx_witness_babbage = TxWitness::new(&txs_babbage).expect("Failed to create TxWitness"); let vkey2_hash: [u8; 28] = From b24f4720b7994fa6dd232f832bd2d88dbcb6eda9 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Wed, 30 Oct 2024 20:02:04 +0700 Subject: [PATCH 6/8] chore: update latest pallas --- rust/cardano-chain-follower/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/cardano-chain-follower/Cargo.toml b/rust/cardano-chain-follower/Cargo.toml index 78a198765..fa78e6305 100644 --- a/rust/cardano-chain-follower/Cargo.toml +++ b/rust/cardano-chain-follower/Cargo.toml @@ -11,9 +11,9 @@ license.workspace = true workspace = true [dependencies] -pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" } -pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" } -pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" } +pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } +pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } +pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } # cspell: words licence mithril-client = { version = "0.8.18", default-features = false, features = [ From 39f7de8527b8d34c6ca6c1fbf2b06644af885547 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 1 Nov 2024 11:35:22 +0200 Subject: [PATCH 7/8] try new cat-ci --- rust/Earthfile | 2 +- rust/deny.toml | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rust/Earthfile b/rust/Earthfile index 0339348a2..683ff2faa 100644 --- a/rust/Earthfile +++ b/rust/Earthfile @@ -1,6 +1,6 @@ VERSION 0.8 -IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.2.19 AS rust-ci +IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:feat/deny.toml AS rust-ci COPY_SRC: FUNCTION diff --git a/rust/deny.toml b/rust/deny.toml index 77f0259f1..cb0005992 100644 --- a/rust/deny.toml +++ b/rust/deny.toml @@ -16,11 +16,7 @@ targets = [ [advisories] version = 2 -ignore = [ - { id = "RUSTSEC-2020-0168", reason = "`mach` is used by wasmtime and we have no control over that." }, - { id = "RUSTSEC-2021-0145", reason = "we don't target windows, and don't use a custom global allocator." }, - { id = "RUSTSEC-2024-0370", reason = "`proc-macro-error` is used by crates we rely on, we can't control what they use."}, -] +ignore = [] [bans] multiple-versions = "warn" @@ -58,6 +54,9 @@ allow-git = [ "https://github.com/input-output-hk/catalyst-mithril.git", "https://github.com/bytecodealliance/wasmtime", "https://github.com/aldanor/hdf5-rust", + "https://github.com/txpipe/vrf", + "https://github.com/txpipe/kes", + "https://github.com/txpipe/curve25519-dalek", ] [licenses] From de7fa876a738182e9db7ac710975bf853b78f554 Mon Sep 17 00:00:00 2001 From: Apisit Ritreungroj Date: Mon, 11 Nov 2024 19:38:22 +0700 Subject: [PATCH 8/8] feat: update latest after ci fix --- rust/cardano-chain-follower/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/cardano-chain-follower/Cargo.toml b/rust/cardano-chain-follower/Cargo.toml index fa78e6305..2e9d24747 100644 --- a/rust/cardano-chain-follower/Cargo.toml +++ b/rust/cardano-chain-follower/Cargo.toml @@ -11,9 +11,9 @@ license.workspace = true workspace = true [dependencies] -pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } -pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } -pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "c66bb4f1bb38ace465f6d385c195f98f09043f48" } +pallas = { version = "0.31.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "51c0aa752926ecebafbf7b4ba90f62f835b78805" } +pallas-hardano = { version = "0.31.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "51c0aa752926ecebafbf7b4ba90f62f835b78805" } +pallas-crypto = { version = "0.31.0", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "51c0aa752926ecebafbf7b4ba90f62f835b78805" } # cspell: words licence mithril-client = { version = "0.8.18", default-features = false, features = [