Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update L1Tx ref types to include multiple proto ops per tx #618

Merged
merged 22 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/datatool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ zeroize.workspace = true
default = []
risc0-builder = ["strata-risc0-guest-builder", "bytemuck"]
sp1-builder = ["strata-sp1-guest-builder/sp1-dev"]
sp1-mock-builder = ["sp1-builder", "strata-sp1-guest-builder/mock"]
sp1-docker-builder = ["sp1-builder", "strata-sp1-guest-builder/docker-build"]
sp1-mock-builder = ["sp1-builder", "strata-sp1-guest-builder/mock"]
2 changes: 1 addition & 1 deletion bin/prover-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ strata-test-utils.workspace = true
[features]
default = []
sp1 = ["zkaleido-sp1-adapter/prover"]
sp1-mock = ["sp1", "zkaleido-sp1-adapter/mock"]
sp1-builder = ["sp1", "strata-sp1-guest-builder/prover"]
sp1-mock = ["sp1", "zkaleido-sp1-adapter/mock"]
sp1-mock-builder = [
"sp1-builder",
"zkaleido-sp1-adapter/mock",
Expand Down
36 changes: 19 additions & 17 deletions bin/strata-client/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,23 @@
BitcoinAddress::parse(&original_taproot_addr.to_string(), network)
.expect("address generated must be valid for the network");

if let ProtocolOperation::DepositRequest(info) = l1_tx.protocol_operation() {
let el_address = info.address.clone();
let total_amount = Amount::from_sat(info.amt);
let take_back_leaf_hash = TapNodeHash::from_slice(&info.take_back_leaf_hash)
.expect("a 32-byte slice must be a valid hash");

let deposit_info = DepositInfo::new(
deposit_request_outpoint,
el_address,
total_amount,
take_back_leaf_hash,
original_taproot_addr,
);

return Some(deposit_info);
for op in l1_tx.protocol_ops() {
if let ProtocolOperation::DepositRequest(info) = op {
let el_address = info.address.clone();
let total_amount = Amount::from_sat(info.amt);
let take_back_leaf_hash = TapNodeHash::from_slice(&info.take_back_leaf_hash)
.expect("a 32-byte slice must be a valid hash");

let deposit_info = DepositInfo::new(
deposit_request_outpoint,
el_address,
total_amount,
take_back_leaf_hash,
original_taproot_addr,
);

return Some(deposit_info);
}

Check warning on line 130 in bin/strata-client/src/extractor.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/extractor.rs#L130

Added line #L130 was not covered by tests
}

None
Expand Down Expand Up @@ -405,15 +407,15 @@
// need clone here because Rust thinks this will be called twice (and
// the needle would already have been moved in the second call).
num_valid_duties += 1;
return L1Tx::new(proof, needle.0.clone(), needle.1.clone());
return L1Tx::new(proof, needle.0.clone(), vec![needle.1.clone()]);
}
}

let (tx, protocol_op, valid) = generate_mock_tx();
if valid {
num_valid_duties += 1;
}
L1Tx::new(proof, tx, protocol_op)
L1Tx::new(proof, tx, vec![protocol_op])
})
.collect();

Expand Down
2 changes: 2 additions & 0 deletions crates/btcio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async-trait.workspace = true
base64.workspace = true
bitcoin.workspace = true
bytes.workspace = true
digest.workspace = true
hex.workspace = true
musig2 = { workspace = true, features = ["serde"] }
rand.workspace = true
Expand All @@ -33,6 +34,7 @@ tokio.workspace = true
tracing.workspace = true

[dev-dependencies]
borsh.workspace = true
strata-common.workspace = true
strata-rocksdb = { workspace = true, features = ["test_utils"] }
strata-state = { workspace = true, features = ["test_utils"] }
Expand Down
1 change: 1 addition & 0 deletions crates/btcio/src/reader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod query;
mod state;
mod tx_indexer;
39 changes: 26 additions & 13 deletions crates/btcio/src/reader/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use bitcoin::{Block, BlockHash};
use strata_config::btcio::ReaderConfig;
use strata_l1tx::{
filter::filter_protocol_op_tx_refs,
filter_types::TxFilterConfig,
messages::{BlockData, L1Event},
filter::{indexer::index_block, TxFilterConfig},
messages::{BlockData, L1Event, RelevantTxEntry},
};
use strata_primitives::params::Params;
use strata_state::l1::{
Expand All @@ -22,7 +21,7 @@
use tracing::*;

use crate::{
reader::state::ReaderState,
reader::{state::ReaderState, tx_indexer::ReaderTxVisitorImpl},
rpc::traits::ReaderRpc,
status::{apply_status_updates, L1StatusUpdate},
};
Expand All @@ -31,12 +30,16 @@
struct ReaderContext<R: ReaderRpc> {
/// Bitcoin reader client
client: Arc<R>,

/// L1Event sender
event_tx: mpsc::Sender<L1Event>,

/// Config
config: Arc<ReaderConfig>,

/// Params
params: Arc<Params>,

/// Status transmitter
status_channel: StatusChannel,
}
Expand Down Expand Up @@ -139,6 +142,7 @@
if ctx.event_tx.send(revert_ev).await.is_err() {
warn!("unable to submit L1 reorg event, did persistence task exit?");
}

Ok(())
}

Expand All @@ -157,9 +161,9 @@
state.set_epoch(new_epoch);
// TODO: pass in chainstate to `derive_from`
let new_config = TxFilterConfig::derive_from(ctx.params.rollup())?;
let curr_filter_config = state.filter_config().clone();
let curr_filter_config = state.filter_config();

if new_config != curr_filter_config {
if new_config != *curr_filter_config {
state.set_filter_config(new_config.clone());
return Ok(Some(new_config));
}
Expand Down Expand Up @@ -322,11 +326,16 @@
block: Block,
) -> anyhow::Result<(L1Event, BlockHash)> {
let txs = block.txdata.len();

let params = ctx.params.clone();
let filtered_txs =
filter_protocol_op_tx_refs(&block, ctx.params.rollup(), state.filter_config());
let block_data = BlockData::new(height, block, filtered_txs);

// Index all the stuff in the block.
let entries: Vec<RelevantTxEntry> =
index_block(&block, ReaderTxVisitorImpl::new, state.filter_config());

// TODO: do stuffs with dep_reqs and da_entries

let block_data = BlockData::new(height, block, entries);

Check warning on line 338 in crates/btcio/src/reader/query.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/reader/query.rs#L330-L338

Added lines #L330 - L338 were not covered by tests
let l1blkid = block_data.block().block_hash();
trace!(%height, %l1blkid, %txs, "fetched block from client");

Expand Down Expand Up @@ -413,6 +422,7 @@
#[cfg(test)]
mod test {
use bitcoin::{hashes::Hash, Network};
use strata_l1tx::filter::types::EnvelopeTags;
use strata_primitives::{
buf::Buf32,
l1::{BitcoinAddress, L1Status},
Expand Down Expand Up @@ -453,9 +463,12 @@
}
}

fn get_filter_config(name: &str) -> TxFilterConfig {
fn get_filter_config() -> TxFilterConfig {
TxFilterConfig {
rollup_name: name.to_string(),
envelope_tags: EnvelopeTags {
checkpoint_tag: "test-checkpt".to_string(),
da_tag: "test-da".to_string(),
},
expected_addrs: SortedVec::new(),
expected_blobs: SortedVec::new(),
expected_outpoints: SortedVec::new(),
Expand All @@ -474,7 +487,7 @@

// Get reader state with 10 recent blocks
fn get_reader_state(ctx: &ReaderContext<TestBitcoinClient>) -> ReaderState {
let filter_config = get_filter_config("zkzkzk");
let filter_config = get_filter_config();
let recent_blocks: [Buf32; N_RECENT_BLOCKS] = ArbitraryGenerator::new().generate();
let recent_blocks: VecDeque<BlockHash> = recent_blocks
.into_iter()
Expand Down
Loading
Loading