From b93aed963ba9262edb78eaba9169cc1ee7b55a4d Mon Sep 17 00:00:00 2001 From: Trey Del Bonis Date: Wed, 5 Feb 2025 22:58:16 -0500 Subject: [PATCH] l1tx: cleanup --- crates/l1tx/src/filter/indexer.rs | 106 ------------------------------ crates/l1tx/src/messages.rs | 9 +-- 2 files changed, 2 insertions(+), 113 deletions(-) diff --git a/crates/l1tx/src/filter/indexer.rs b/crates/l1tx/src/filter/indexer.rs index 107b053fb4..f7b762e5a0 100644 --- a/crates/l1tx/src/filter/indexer.rs +++ b/crates/l1tx/src/filter/indexer.rs @@ -73,112 +73,6 @@ fn index_tx( visitor.finalize() } -/* -/// Interface to extract relevant information from a block. -pub trait BlockIndexer { - /// Output from the indexing pass. - type Output; - - /// Indexes the block and produces the output. - fn index_block(&self, block: &Block) -> Self::Output; -} - -/// Indexes `ProtocolTxEntry`s, `DepositRequestInfo`s and `DaEntry`s from a bitcoin block. -/// -/// Currently, this is used from two contexts: rollup node and prover node, each of which will have -/// different `TxIndexer`s which determine what and how something is extracted from a transaction. -pub struct TxOpIndexer<'a, T: TxVisitor, F: Fn() -> T> { - /// The actual logic of what and how something is extracted from a transaction. - tx_indexer_fn: F, - - /// The config that's used to filter transactions and extract data. This has a lifetime - /// parameter for two reasons: 1) It is used in prover context so using Arc might incur some - /// overheads, 2) We can be sure that the config won't change during indexing of a l1 block. - filter_config: &'a TxFilterConfig, - - /// `ProtocolTxEntry`s will be accumulated here. - relevant_txs: Vec>, -} - -impl<'a, T: TxVisitor, F: Fn() -> T> TxOpIndexer<'a, T, F> { - pub fn new(tx_indexer_fn: F, filter_config: &'a TxFilterConfig) -> Self { - Self { - tx_indexer_fn, - filter_config, - relevant_txs: Vec::new(), - dep_reqs: Vec::new(), - da_entries: Vec::new(), - } - } - - pub fn tx_entries(&self) -> &[IndexedTxEntry] { - &self.relevant_txs - } - - pub fn deposit_requests(&self) -> &[DepositRequestInfo] { - &self.dep_reqs - } - - pub fn da_entries(&self) -> &[DaEntry] { - &self.da_entries - } -} - -impl T> TxOpIndexer<'_, T, F> { - fn index_tx(&self, txidx: u32, tx: &Transaction) { - let mut tx_visitor = (self.tx_indexer_fn)(); - - for ckpt in parse_checkpoint_envelopes(tx, self.filter_config) { - tx_visitor.visit_checkpoint(ckpt); - } - - for dp in parse_deposits(tx, self.filter_config) { - tx_visitor.visit_deposit(dp); - } - - // TODO: remove this later when we do not require deposit request ops - for dr in parse_deposit_requests(tx, self.filter_config) { - tx_visitor.visit_deposit_request(dr); - } - - for da in parse_da_blobs(tx, self.filter_config) { - tx_visitor.visit_da(da); - } - - // Finalize the visitor. If there's nothing to report then return - // immeditately. - if let Some(summary) = tx_visitor.finalize() { - self.relevant_txs.push(IndexedTxEntry::new(txidx, summary)); - } - - self.dep_reqs.append(&mut deps); - self.da_entries.append(&mut das); - } -} - -impl T> BlockIndexer for TxOpIndexer<'_, T, F> { - type Output = Vec; - - fn index_block(&self, block: &Block) -> Self::Output - where - Self: Sized, - { - let mut op_txs = Vec::new(); - let mut deposit_reqs = Vec::new(); - let mut da_entries = Vec::new(); - - for (i, tx) in block.txdata.iter().enumerate() { - self.index_tx(i as u32, tx); - } - - // TODO - } - - /*fn finalize(self) -> L1BlockExtract { - L1BlockExtract::new(self.tx_entries, self.dep_reqs, self.da_entries) - }*/ -}*/ - /// Generic no-op tx indexer that emits nothing for every tx but could /// substitute for any type of visitor. pub struct NopTxVisitorImpl(::std::marker::PhantomData); diff --git a/crates/l1tx/src/messages.rs b/crates/l1tx/src/messages.rs index 13ec951032..668fe854de 100644 --- a/crates/l1tx/src/messages.rs +++ b/crates/l1tx/src/messages.rs @@ -21,7 +21,7 @@ pub enum L1Event { GenesisVerificationState(u64, HeaderVerificationState), } -/// Indexed transaction entry taken from +/// Indexed transaction entry taken from a block. #[derive(Clone, Debug, BorshDeserialize, BorshSerialize)] pub struct IndexedTxEntry { /// Index of the transaction in the block @@ -55,11 +55,6 @@ impl IndexedTxEntry { } } -/* - * Core protocol specific bitcoin transaction reference. A bitcoin transaction can have multiple - * operations relevant to protocol. This is used in the context of [`BlockData`]. - */ - /// Container for the different kinds of messages that we could extract from a L1 tx. #[derive(Clone, Debug)] pub struct L1TxMessages { @@ -110,7 +105,7 @@ impl L1TxMessages { } } -/// Da data retrieved from L1 transaction. +/// DA commitment and blob retrieved from L1 transaction. #[derive(Clone, Debug)] pub struct DaEntry { #[allow(unused)]