diff --git a/crates/btcio/src/writer/bundler.rs b/crates/btcio/src/writer/bundler.rs index 73e07f173..9fc17d849 100644 --- a/crates/btcio/src/writer/bundler.rs +++ b/crates/btcio/src/writer/bundler.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use strata_db::types::{IntentEntry, IntentStatus, PayloadEntry}; +use strata_db::types::{BundledPayloadEntry, IntentEntry, IntentStatus}; use strata_storage::ops::writer::EnvelopeDataOps; use tokio::time::sleep; use tracing::*; @@ -30,7 +30,7 @@ async fn process_unbundled_entries( for mut entry in unbundled { // NOTE: In future, the logic to create payload will be different. We need to group // intents and create payload entries accordingly - let payload_entry = PayloadEntry::new_unsigned(vec![entry.payload().clone()]); + let payload_entry = BundledPayloadEntry::new_unsigned(vec![entry.payload().clone()]); // TODO: the following block till "Atomic Ends" should be atomic. let idx = ops.get_next_payload_idx_async().await?; diff --git a/crates/btcio/src/writer/signer.rs b/crates/btcio/src/writer/signer.rs index 081318a45..a606b28b4 100644 --- a/crates/btcio/src/writer/signer.rs +++ b/crates/btcio/src/writer/signer.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use bitcoin::{consensus, Transaction}; -use strata_db::types::{L1TxEntry, PayloadEntry}; +use strata_db::types::{BundledPayloadEntry, L1TxEntry}; use strata_primitives::buf::Buf32; use tracing::*; @@ -20,7 +20,7 @@ type BlobIdx = u64; /// 2. A signed intent needs to be resigned because somehow its inputs were spent/missing /// 3. A confirmed block that includes the tx gets reorged pub async fn create_and_sign_payload_envelopes( - payloadentry: &PayloadEntry, + payloadentry: &BundledPayloadEntry, broadcast_handle: &L1BroadcastHandle, ctx: Arc>, ) -> Result<(Buf32, Buf32), EnvelopeError> { @@ -59,7 +59,7 @@ pub async fn create_and_sign_payload_envelopes( #[cfg(test)] mod test { - use strata_db::types::{PayloadEntry, PayloadL1Status}; + use strata_db::types::{BundledPayloadEntry, L1BundleStatus}; use strata_primitives::l1::payload::L1Payload; use super::*; @@ -76,9 +76,9 @@ mod test { // First insert an unsigned blob let payload = L1Payload::new_da([1; 100].to_vec()); - let entry = PayloadEntry::new_unsigned(vec![payload]); + let entry = BundledPayloadEntry::new_unsigned(vec![payload]); - assert_eq!(entry.status, PayloadL1Status::Unsigned); + assert_eq!(entry.status, L1BundleStatus::Unsigned); assert_eq!(entry.commit_txid, Buf32::zero()); assert_eq!(entry.reveal_txid, Buf32::zero()); diff --git a/crates/btcio/src/writer/task.rs b/crates/btcio/src/writer/task.rs index ab5a63135..f71272f9d 100644 --- a/crates/btcio/src/writer/task.rs +++ b/crates/btcio/src/writer/task.rs @@ -4,7 +4,7 @@ use bitcoin::Address; use strata_config::btcio::WriterConfig; use strata_db::{ traits::L1WriterDatabase, - types::{IntentEntry, L1TxStatus, PayloadEntry, PayloadL1Status}, + types::{BundledPayloadEntry, IntentEntry, L1BundleStatus, L1TxStatus}, }; use strata_primitives::{ l1::payload::{PayloadDest, PayloadIntent}, @@ -137,7 +137,7 @@ fn get_next_payloadidx_to_watch(insc_ops: &EnvelopeDataOps) -> anyhow::Result( match payloadentry.status { // If unsigned or needs resign, create new signed commit/reveal txs and update the // entry - PayloadL1Status::Unsigned | PayloadL1Status::NeedsResign => { + L1BundleStatus::Unsigned | L1BundleStatus::NeedsResign => { debug!(?payloadentry.status, %curr_payloadidx, "Processing unsigned payloadentry"); match create_and_sign_payload_envelopes( &payloadentry, @@ -185,7 +185,7 @@ pub async fn watcher_task( { Ok((cid, rid)) => { let mut updated_entry = payloadentry.clone(); - updated_entry.status = PayloadL1Status::Unpublished; + updated_entry.status = L1BundleStatus::Unpublished; updated_entry.commit_txid = cid; updated_entry.reveal_txid = rid; insc_ops @@ -206,13 +206,13 @@ pub async fn watcher_task( } } // If finalized, nothing to do, move on to process next entry - PayloadL1Status::Finalized => { + L1BundleStatus::Finalized => { curr_payloadidx += 1; } // If entry is signed but not finalized or excluded yet, check broadcast txs status - PayloadL1Status::Published - | PayloadL1Status::Confirmed - | PayloadL1Status::Unpublished => { + L1BundleStatus::Published + | L1BundleStatus::Confirmed + | L1BundleStatus::Unpublished => { debug!(%curr_payloadidx, "Checking payloadentry's broadcast status"); let commit_tx = broadcast_handle .get_tx_entry_by_id_async(payloadentry.commit_txid) @@ -237,14 +237,14 @@ pub async fn watcher_task( .put_payload_entry_async(curr_payloadidx, updated_entry) .await?; - if new_status == PayloadL1Status::Finalized { + if new_status == L1BundleStatus::Finalized { curr_payloadidx += 1; } } _ => { warn!(%curr_payloadidx, "Corresponding commit/reveal entry for payloadentry not found in broadcast db. Sign and create transactions again."); let mut updated_entry = payloadentry.clone(); - updated_entry.status = PayloadL1Status::Unsigned; + updated_entry.status = L1BundleStatus::Unsigned; insc_ops .put_payload_entry_async(curr_payloadidx, updated_entry) .await?; @@ -260,15 +260,15 @@ pub async fn watcher_task( } async fn update_l1_status( - payloadentry: &PayloadEntry, - new_status: &PayloadL1Status, + payloadentry: &BundledPayloadEntry, + new_status: &L1BundleStatus, status_channel: &StatusChannel, ) { // Update L1 status. Since we are processing one payloadentry at a time, if the entry is // finalized/confirmed, then it means it is published as well - if *new_status == PayloadL1Status::Published - || *new_status == PayloadL1Status::Confirmed - || *new_status == PayloadL1Status::Finalized + if *new_status == L1BundleStatus::Published + || *new_status == L1BundleStatus::Confirmed + || *new_status == L1BundleStatus::Finalized { let status_updates = [ L1StatusUpdate::LastPublishedTxid(payloadentry.reveal_txid.into()), @@ -283,23 +283,23 @@ async fn update_l1_status( fn determine_payload_next_status( commit_status: &L1TxStatus, reveal_status: &L1TxStatus, -) -> PayloadL1Status { +) -> L1BundleStatus { match (&commit_status, &reveal_status) { // If reveal is finalized, both are finalized - (_, L1TxStatus::Finalized { .. }) => PayloadL1Status::Finalized, + (_, L1TxStatus::Finalized { .. }) => L1BundleStatus::Finalized, // If reveal is confirmed, both are confirmed - (_, L1TxStatus::Confirmed { .. }) => PayloadL1Status::Confirmed, + (_, L1TxStatus::Confirmed { .. }) => L1BundleStatus::Confirmed, // If reveal is published regardless of commit, the payload is published - (_, L1TxStatus::Published) => PayloadL1Status::Published, + (_, L1TxStatus::Published) => L1BundleStatus::Published, // if commit has invalid inputs, needs resign - (L1TxStatus::InvalidInputs, _) => PayloadL1Status::NeedsResign, + (L1TxStatus::InvalidInputs, _) => L1BundleStatus::NeedsResign, // If commit is unpublished, both are upublished - (L1TxStatus::Unpublished, _) => PayloadL1Status::Unpublished, + (L1TxStatus::Unpublished, _) => L1BundleStatus::Unpublished, // If commit is published but not reveal, the payload is unpublished - (_, L1TxStatus::Unpublished) => PayloadL1Status::Unpublished, + (_, L1TxStatus::Unpublished) => L1BundleStatus::Unpublished, // If reveal has invalid inputs, these need resign because we can do nothing with just // commit tx confirmed. This should not occur in practice - (_, L1TxStatus::InvalidInputs) => PayloadL1Status::NeedsResign, + (_, L1TxStatus::InvalidInputs) => L1BundleStatus::NeedsResign, } } @@ -326,21 +326,21 @@ mod test { fn test_initialize_writer_state_with_existing_payloads() { let iops = get_envelope_ops(); - let mut e1: PayloadEntry = ArbitraryGenerator::new().generate(); - e1.status = PayloadL1Status::Finalized; + let mut e1: BundledPayloadEntry = ArbitraryGenerator::new().generate(); + e1.status = L1BundleStatus::Finalized; iops.put_payload_entry_blocking(0, e1).unwrap(); - let mut e2: PayloadEntry = ArbitraryGenerator::new().generate(); - e2.status = PayloadL1Status::Published; + let mut e2: BundledPayloadEntry = ArbitraryGenerator::new().generate(); + e2.status = L1BundleStatus::Published; iops.put_payload_entry_blocking(1, e2).unwrap(); let expected_idx = 1; // All entries before this do not need to be watched. - let mut e3: PayloadEntry = ArbitraryGenerator::new().generate(); - e3.status = PayloadL1Status::Unsigned; + let mut e3: BundledPayloadEntry = ArbitraryGenerator::new().generate(); + e3.status = L1BundleStatus::Unsigned; iops.put_payload_entry_blocking(2, e3).unwrap(); - let mut e4: PayloadEntry = ArbitraryGenerator::new().generate(); - e4.status = PayloadL1Status::Unsigned; + let mut e4: BundledPayloadEntry = ArbitraryGenerator::new().generate(); + e4.status = L1BundleStatus::Unsigned; iops.put_payload_entry_blocking(3, e4).unwrap(); let idx = get_next_payloadidx_to_watch(&iops).unwrap(); @@ -353,30 +353,30 @@ mod test { // When both are unpublished let (commit_status, reveal_status) = (L1TxStatus::Unpublished, L1TxStatus::Unpublished); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::Unpublished); + assert_eq!(next, L1BundleStatus::Unpublished); // When both are Finalized let fin = L1TxStatus::Finalized { confirmations: 5 }; let (commit_status, reveal_status) = (fin.clone(), fin); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::Finalized); + assert_eq!(next, L1BundleStatus::Finalized); // When both are Confirmed let conf = L1TxStatus::Confirmed { confirmations: 5 }; let (commit_status, reveal_status) = (conf.clone(), conf.clone()); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::Confirmed); + assert_eq!(next, L1BundleStatus::Confirmed); // When both are Published let publ = L1TxStatus::Published; let (commit_status, reveal_status) = (publ.clone(), publ.clone()); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::Published); + assert_eq!(next, L1BundleStatus::Published); // When both have invalid let (commit_status, reveal_status) = (L1TxStatus::InvalidInputs, L1TxStatus::InvalidInputs); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::NeedsResign); + assert_eq!(next, L1BundleStatus::NeedsResign); // When reveal has invalid inputs but commit is confirmed. I doubt this would happen in // practice for our case. @@ -384,6 +384,6 @@ mod test { // published. let (commit_status, reveal_status) = (conf.clone(), L1TxStatus::InvalidInputs); let next = determine_payload_next_status(&commit_status, &reveal_status); - assert_eq!(next, PayloadL1Status::NeedsResign); + assert_eq!(next, L1BundleStatus::NeedsResign); } } diff --git a/crates/consensus-logic/src/duty/worker.rs b/crates/consensus-logic/src/duty/worker.rs index 4b567bbc3..0f85cdd3b 100644 --- a/crates/consensus-logic/src/duty/worker.rs +++ b/crates/consensus-logic/src/duty/worker.rs @@ -410,7 +410,7 @@ fn perform_duty( Ok(()) } Duty::CommitBatch(data) => { - info!(data = ?data, "commit batch duty"); + info!(epoch_idx = ?data.idx(), "commit batch duty"); let checkpoint = check_and_get_batch_checkpoint(data, checkpoint_handle, pool, params.as_ref())?; diff --git a/crates/db/src/traits.rs b/crates/db/src/traits.rs index d31ca6465..e48dee61a 100644 --- a/crates/db/src/traits.rs +++ b/crates/db/src/traits.rs @@ -19,7 +19,7 @@ use strata_zkvm::ProofReceipt; use crate::{ entities::bridge_tx_state::BridgeTxState, - types::{CheckpointEntry, IntentEntry, L1TxEntry, PayloadEntry}, + types::{BundledPayloadEntry, CheckpointEntry, IntentEntry, L1TxEntry}, DbResult, }; @@ -244,14 +244,14 @@ pub trait CheckpointDatabase { fn put_batch_checkpoint(&self, batchidx: u64, entry: CheckpointEntry) -> DbResult<()>; } -/// A trait encapsulating provider and store traits to create/update [`PayloadEntry`] in the -/// database and to fetch [`PayloadEntry`] and indices from the database +/// A trait encapsulating provider and store traits to create/update [`BundledPayloadEntry`] in the +/// database and to fetch [`BundledPayloadEntry`] and indices from the database pub trait L1WriterDatabase { - /// Store the [`PayloadEntry`]. - fn put_payload_entry(&self, idx: u64, payloadentry: PayloadEntry) -> DbResult<()>; + /// Store the [`BundledPayloadEntry`]. + fn put_payload_entry(&self, idx: u64, payloadentry: BundledPayloadEntry) -> DbResult<()>; - /// Get a [`PayloadEntry`] by its index. - fn get_payload_entry_by_idx(&self, idx: u64) -> DbResult>; + /// Get a [`BundledPayloadEntry`] by its index. + fn get_payload_entry_by_idx(&self, idx: u64) -> DbResult>; /// Get the next payload index fn get_next_payload_idx(&self) -> DbResult; diff --git a/crates/db/src/types.rs b/crates/db/src/types.rs index 6f83b8102..6b1942029 100644 --- a/crates/db/src/types.rs +++ b/crates/db/src/types.rs @@ -42,30 +42,30 @@ impl IntentEntry { } /// Status of Intent indicating various stages of being bundled to L1 transaction. -/// Unbundled Intents are collected and bundled to create [`PayloadEntry]. +/// Unbundled Intents are collected and bundled to create [`BundledPayloadEntry]. #[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)] pub enum IntentStatus { // It is not bundled yet, and thus will be collected and processed by bundler. Unbundled, - // It has been bundled to [`PayloadEntry`] with given bundle idx. + // It has been bundled to [`BundledPayloadEntry`] with given bundle idx. Bundled(u64), } /// Represents data for a payload we're still planning to post to L1. #[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)] -pub struct PayloadEntry { +pub struct BundledPayloadEntry { pub payloads: Vec, pub commit_txid: Buf32, pub reveal_txid: Buf32, - pub status: PayloadL1Status, + pub status: L1BundleStatus, } -impl PayloadEntry { +impl BundledPayloadEntry { pub fn new( payloads: Vec, commit_txid: Buf32, reveal_txid: Buf32, - status: PayloadL1Status, + status: L1BundleStatus, ) -> Self { Self { payloads, @@ -75,7 +75,7 @@ impl PayloadEntry { } } - /// Create new unsigned [`PayloadEntry`]. + /// Create new unsigned [`BundledPayloadEntry`]. /// /// NOTE: This won't have commit - reveal pairs associated with it. /// Because it is better to defer gathering utxos as late as possible to prevent being spent @@ -83,13 +83,13 @@ impl PayloadEntry { pub fn new_unsigned(payloads: Vec) -> Self { let cid = Buf32::zero(); let rid = Buf32::zero(); - Self::new(payloads, cid, rid, PayloadL1Status::Unsigned) + Self::new(payloads, cid, rid, L1BundleStatus::Unsigned) } } /// Various status that transactions corresponding to a payload can be in L1 #[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)] -pub enum PayloadL1Status { +pub enum L1BundleStatus { /// The payload has not been signed yet, i.e commit-reveal transactions have not been created /// yet. Unsigned, diff --git a/crates/l1tx/src/envelope/builder.rs b/crates/l1tx/src/envelope/builder.rs index ef8fe7b6b..914469b46 100644 --- a/crates/l1tx/src/envelope/builder.rs +++ b/crates/l1tx/src/envelope/builder.rs @@ -11,7 +11,6 @@ use strata_primitives::{ l1::payload::{L1Payload, L1PayloadType}, params::Params, }; -use tracing::*; // Generates a [`ScriptBuf`] that consists of `OP_IF .. OP_ENDIF` block pub fn build_envelope_script( @@ -45,9 +44,7 @@ fn build_payload_envelope( )); // Insert actual data - trace!(batchdata_size = %payload.data().len(), "Inserting batch data"); for chunk in payload.data().chunks(520) { - trace!(size=%chunk.len(), "inserting chunk"); builder = builder.push_slice(PushBytesBuf::try_from(chunk.to_vec())?); } builder = builder.push_opcode(OP_ENDIF); diff --git a/crates/l1tx/src/envelope/parser.rs b/crates/l1tx/src/envelope/parser.rs index 5812d28e2..afaf72b53 100644 --- a/crates/l1tx/src/envelope/parser.rs +++ b/crates/l1tx/src/envelope/parser.rs @@ -1,5 +1,3 @@ -use std::str::from_utf8; - use bitcoin::{ opcodes::all::OP_IF, script::{Instruction, Instructions}, @@ -84,11 +82,10 @@ fn parse_l1_payload( Ok(L1Payload::new(payload, ptype)) } -fn parse_payload_type(bytes: &[u8], params: &RollupParams) -> Option { - let str = from_utf8(bytes).ok()?; - if params.checkpoint_tag == str { +fn parse_payload_type(tag_bytes: &[u8], params: &RollupParams) -> Option { + if params.checkpoint_tag.as_bytes() == tag_bytes { Some(L1PayloadType::Checkpoint) - } else if params.da_tag == str { + } else if params.da_tag.as_bytes() == tag_bytes { Some(L1PayloadType::Da) } else { None diff --git a/crates/rocksdb-store/src/writer/db.rs b/crates/rocksdb-store/src/writer/db.rs index aa714cf77..94e7a3505 100644 --- a/crates/rocksdb-store/src/writer/db.rs +++ b/crates/rocksdb-store/src/writer/db.rs @@ -4,7 +4,7 @@ use rockbound::{utils::get_last, OptimisticTransactionDB as DB, SchemaDBOperatio use strata_db::{ errors::DbError, traits::L1WriterDatabase, - types::{IntentEntry, PayloadEntry}, + types::{BundledPayloadEntry, IntentEntry}, DbResult, }; use strata_primitives::buf::Buf32; @@ -28,7 +28,7 @@ impl RBL1WriterDb { } impl L1WriterDatabase for RBL1WriterDb { - fn put_payload_entry(&self, idx: u64, entry: PayloadEntry) -> DbResult<()> { + fn put_payload_entry(&self, idx: u64, entry: BundledPayloadEntry) -> DbResult<()> { self.db .with_optimistic_txn( rockbound::TransactionRetry::Count(self.ops.retry_count), @@ -40,7 +40,7 @@ impl L1WriterDatabase for RBL1WriterDb { .map_err(|e| DbError::TransactionError(e.to_string())) } - fn get_payload_entry_by_idx(&self, idx: u64) -> DbResult> { + fn get_payload_entry_by_idx(&self, idx: u64) -> DbResult> { Ok(self.db.get::(&idx)?) } @@ -113,7 +113,7 @@ mod tests { let (db, db_ops) = get_rocksdb_tmp_instance().unwrap(); let seq_db = RBL1WriterDb::new(db, db_ops); - let blob: PayloadEntry = ArbitraryGenerator::new().generate(); + let blob: BundledPayloadEntry = ArbitraryGenerator::new().generate(); seq_db.put_payload_entry(0, blob.clone()).unwrap(); @@ -125,7 +125,7 @@ mod tests { fn test_put_blob_existing_entry() { let (db, db_ops) = get_rocksdb_tmp_instance().unwrap(); let seq_db = RBL1WriterDb::new(db, db_ops); - let blob: PayloadEntry = ArbitraryGenerator::new().generate(); + let blob: BundledPayloadEntry = ArbitraryGenerator::new().generate(); seq_db.put_payload_entry(0, blob.clone()).unwrap(); @@ -140,12 +140,12 @@ mod tests { let (db, db_ops) = get_rocksdb_tmp_instance().unwrap(); let seq_db = RBL1WriterDb::new(db, db_ops); - let entry: PayloadEntry = ArbitraryGenerator::new().generate(); + let entry: BundledPayloadEntry = ArbitraryGenerator::new().generate(); // Insert seq_db.put_payload_entry(0, entry.clone()).unwrap(); - let updated_entry: PayloadEntry = ArbitraryGenerator::new().generate(); + let updated_entry: BundledPayloadEntry = ArbitraryGenerator::new().generate(); // Update existing idx seq_db.put_payload_entry(0, updated_entry.clone()).unwrap(); @@ -158,7 +158,7 @@ mod tests { let (db, db_ops) = get_rocksdb_tmp_instance().unwrap(); let seq_db = RBL1WriterDb::new(db, db_ops); - let blob: PayloadEntry = ArbitraryGenerator::new().generate(); + let blob: BundledPayloadEntry = ArbitraryGenerator::new().generate(); let next_blob_idx = seq_db.get_next_payload_idx().unwrap(); assert_eq!( @@ -171,7 +171,7 @@ mod tests { .unwrap(); // Now the next idx is 1 - let blob: PayloadEntry = ArbitraryGenerator::new().generate(); + let blob: BundledPayloadEntry = ArbitraryGenerator::new().generate(); seq_db.put_payload_entry(1, blob.clone()).unwrap(); let next_blob_idx = seq_db.get_next_payload_idx().unwrap(); diff --git a/crates/rocksdb-store/src/writer/schemas.rs b/crates/rocksdb-store/src/writer/schemas.rs index c3000ecd1..02a5d05d5 100644 --- a/crates/rocksdb-store/src/writer/schemas.rs +++ b/crates/rocksdb-store/src/writer/schemas.rs @@ -1,4 +1,4 @@ -use strata_db::types::{IntentEntry, PayloadEntry}; +use strata_db::types::{BundledPayloadEntry, IntentEntry}; use strata_primitives::buf::Buf32; use crate::{ @@ -8,7 +8,7 @@ use crate::{ define_table_with_seek_key_codec!( /// A table to store idx-> payload entry mapping - (PayloadSchema) u64 => PayloadEntry + (PayloadSchema) u64 => BundledPayloadEntry ); define_table_with_default_codec!( diff --git a/crates/storage/src/ops/writer.rs b/crates/storage/src/ops/writer.rs index 70febaca4..0b49e01a4 100644 --- a/crates/storage/src/ops/writer.rs +++ b/crates/storage/src/ops/writer.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use strata_db::{ traits::L1WriterDatabase, - types::{IntentEntry, PayloadEntry}, + types::{BundledPayloadEntry, IntentEntry}, DbResult, }; use strata_primitives::buf::Buf32; @@ -13,8 +13,8 @@ use crate::exec::*; inst_ops_simple! { ( => EnvelopeDataOps) { - put_payload_entry(idx: u64, payloadentry: PayloadEntry) => (); - get_payload_entry_by_idx(idx: u64) => Option; + put_payload_entry(idx: u64, payloadentry: BundledPayloadEntry) => (); + get_payload_entry_by_idx(idx: u64) => Option; get_next_payload_idx() => u64; put_intent_entry(id: Buf32, entry: IntentEntry) => (); get_intent_by_id(id: Buf32) => Option;