Skip to content

Commit

Permalink
Update visit_da method and some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibek Pandey committed Jan 31, 2025
1 parent 09119cd commit 451fa5a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
10 changes: 6 additions & 4 deletions crates/btcio/src/reader/ops_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use strata_state::{
tx::{DepositInfo, DepositRequestInfo, ProtocolOperation},
};

/// Ops visitor for rollup client.
/// Ops visitor for rollup client. This is intended to get Da commitment as well as process/store da
/// blob.
#[derive(Clone, Debug)]
pub struct ClientOpsVisitor {
ops: Vec<ProtocolOperation>,
Expand All @@ -24,12 +25,13 @@ impl OpsVisitor for ClientOpsVisitor {
self.ops
}

fn visit_da<'a>(&mut self, data: &'a [&'a [u8]]) {
fn visit_da<'a>(&mut self, chunks: impl Iterator<Item = &'a [u8]>) {
let mut hasher = Sha256::new();
for d in data {
hasher.update(d);
for chunk in chunks {
hasher.update(chunk);
}
let hash: [u8; 32] = hasher.finalize().into();
// TODO: store da in db
self.ops.push(ProtocolOperation::DaCommitment(hash.into()));
}

Expand Down
8 changes: 3 additions & 5 deletions crates/l1tx/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ fn parse_deposits(
extract_deposit_info(tx, &filter_conf.deposit_config).into_iter()
}

pub type DaBlobRaw<'a> = &'a [&'a [u8]];

/// Parse da blobs from [`Transaction`].
fn parse_da_blobs<'a>(
_tx: &'a Transaction,
_filter_conf: &TxFilterConfig,
) -> impl Iterator<Item = DaBlobRaw<'a>> {
// TODO: implement this when we have da
std::iter::empty()
) -> impl Iterator<Item = impl Iterator<Item = &'a [u8]> + 'a> {
// TODO: actually implement this when we have da
std::iter::empty::<std::slice::Iter<'a, &'a [u8]>>().map(|inner| inner.copied())
}

/// Parses envelope from the given transaction. Currently, the only envelope recognizable is
Expand Down
2 changes: 1 addition & 1 deletion crates/l1tx/src/filter/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait OpsVisitor {
fn visit_deposit_request(&mut self, _d: DepositRequestInfo) {}

// Do stuffs with DA.
fn visit_da<'a>(&mut self, _d: &'a [&'a [u8]]) {}
fn visit_da<'a>(&mut self, _d: impl Iterator<Item = &'a [u8]>) {}

fn collect(self) -> Vec<ProtocolOperation>;
}
Expand Down
9 changes: 5 additions & 4 deletions crates/proof-impl/btc-blockspace/src/ops_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use strata_state::{
tx::{DepositInfo, ProtocolOperation},
};

/// Ops visitor for Prover.
/// Ops visitor for Prover. Basically this efficiently gets da commitment from chunks without doing
/// anything else with the chunks.
#[derive(Debug, Clone)]
pub(crate) struct ProverOpsVisitor {
ops: Vec<ProtocolOperation>,
Expand All @@ -23,10 +24,10 @@ impl OpsVisitor for ProverOpsVisitor {
self.ops
}

fn visit_da<'a>(&mut self, data: &'a [&'a [u8]]) {
fn visit_da<'a>(&mut self, chunks: impl Iterator<Item = &'a [u8]>) {
let mut hasher = Sha256::new();
for d in data {
hasher.update(d);
for chunk in chunks {
hasher.update(chunk);
}
let hash: [u8; 32] = hasher.finalize().into();
self.ops.push(ProtocolOperation::DaCommitment(hash.into()));
Expand Down

0 comments on commit 451fa5a

Please sign in to comment.