Skip to content

Commit

Permalink
Some more renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibek Pandey committed Jan 14, 2025
1 parent 1c91a81 commit cc85da7
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 51 deletions.
4 changes: 2 additions & 2 deletions bin/strata-client/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use strata_primitives::{
bridge::{OperatorIdx, PublickeyTable},
buf::Buf32,
hash,
l1::payload::{BlobDest, L1Payload, PayloadIntent},
l1::payload::{L1Payload, PayloadDest, PayloadIntent},
params::Params,
};
use strata_rpc_api::{
Expand Down Expand Up @@ -736,7 +736,7 @@ impl StrataSequencerApiServer for SequencerServerImpl {
async fn submit_da_blob(&self, blob: HexBytes) -> RpcResult<()> {
let commitment = hash::raw(&blob.0);
let payload = L1Payload::new_da(blob.0);
let blobintent = PayloadIntent::new(BlobDest::L1, commitment, payload);
let blobintent = PayloadIntent::new(PayloadDest::L1, commitment, payload);

Check warning on line 739 in bin/strata-client/src/rpc_server.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/rpc_server.rs#L738-L739

Added lines #L738 - L739 were not covered by tests
// NOTE: It would be nice to return reveal txid from the submit method. But creation of txs
// is deferred to signer in the writer module
if let Err(e) = self.envelope_handle.submit_intent_async(blobintent).await {

Check warning on line 742 in bin/strata-client/src/rpc_server.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/rpc_server.rs#L742

Added line #L742 was not covered by tests
Expand Down
6 changes: 3 additions & 3 deletions crates/btcio/src/writer/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use strata_db::{
types::{L1TxStatus, PayloadEntry, PayloadL1Status},
};
use strata_primitives::{
l1::payload::{BlobDest, PayloadIntent},
l1::payload::{PayloadDest, PayloadIntent},
params::Params,
};
use strata_status::StatusChannel;
Expand Down Expand Up @@ -35,7 +35,7 @@ impl EnvelopeHandle {
}

pub fn submit_intent(&self, intent: PayloadIntent) -> anyhow::Result<()> {
if intent.dest() != BlobDest::L1 {
if intent.dest() != PayloadDest::L1 {

Check warning on line 38 in crates/btcio/src/writer/task.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/writer/task.rs#L37-L38

Added lines #L37 - L38 were not covered by tests
warn!(commitment = %intent.commitment(), "Received intent not meant for L1");
return Ok(());
}
Expand All @@ -57,7 +57,7 @@ impl EnvelopeHandle {
}

pub async fn submit_intent_async(&self, intent: PayloadIntent) -> anyhow::Result<()> {
if intent.dest() != BlobDest::L1 {
if intent.dest() != PayloadDest::L1 {

Check warning on line 60 in crates/btcio/src/writer/task.rs

View check run for this annotation

Codecov / codecov/patch

crates/btcio/src/writer/task.rs#L59-L60

Added lines #L59 - L60 were not covered by tests
warn!(commitment = %intent.commitment(), "Received intent not meant for L1");
return Ok(());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/btcio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Default for WriterConfig {
impl Default for ReaderConfig {
fn default() -> Self {
Self {
client_poll_dur_ms: 1_000,
client_poll_dur_ms: 200,
}
}
}
8 changes: 6 additions & 2 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ mod test {
rpc_url = "http://localhost:8551"
secret = "1234567890abcdef"
[btcio]
[btcio.reader]
client_poll_dur_ms = 200
[btcio.writer]
write_poll_dur_ms = 200
fee_policy = "smart"
reveal_amount = 100
Expand Down Expand Up @@ -145,8 +147,10 @@ mod test {
client_poll_dur_ms = 200
client_checkpoint_interval = 10
[btcio]
[btcio.reader]
client_poll_dur_ms = 200
[btcio.writer]
write_poll_dur_ms = 200
fee_policy = "smart"
reveal_amount = 100
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus-logic/src/duty/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use strata_db::traits::*;
use strata_eectl::engine::ExecEngineCtl;
use strata_primitives::{
buf::{Buf32, Buf64},
l1::payload::{BlobDest, L1Payload, PayloadIntent},
l1::payload::{L1Payload, PayloadDest, PayloadIntent},
params::Params,
};
use strata_state::{batch::SignedBatchCheckpoint, client_state::ClientState, prelude::*};
Expand Down Expand Up @@ -424,7 +424,7 @@ fn perform_duty<D: Database, E: ExecEngineCtl>(
let payload_data =

Check warning on line 424 in crates/consensus-logic/src/duty/worker.rs

View check run for this annotation

Codecov / codecov/patch

crates/consensus-logic/src/duty/worker.rs#L424

Added line #L424 was not covered by tests
borsh::to_vec(&signed_checkpoint).map_err(|e| Error::Other(e.to_string()))?;
let payload = L1Payload::new_checkpoint(payload_data);
let blob_intent = PayloadIntent::new(BlobDest::L1, checkpoint_hash, payload);
let blob_intent = PayloadIntent::new(PayloadDest::L1, checkpoint_hash, payload);

Check warning on line 427 in crates/consensus-logic/src/duty/worker.rs

View check run for this annotation

Codecov / codecov/patch

crates/consensus-logic/src/duty/worker.rs#L426-L427

Added lines #L426 - L427 were not covered by tests

info!(signed_checkpoint = ?signed_checkpoint, "signed checkpoint");
info!(blob_intent = ?blob_intent, "sending blob intent");
Expand Down
26 changes: 0 additions & 26 deletions crates/primitives/src/l1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,3 @@ impl From<Block> for L1BlockRecord {
}
}

Check warning on line 176 in crates/primitives/src/l1/block.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/block.rs#L164-L176

Added lines #L164 - L176 were not covered by tests
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, Arbitrary)]
pub struct L1Status {
/// If the last time we tried to poll the client (as of `last_update`)
/// we were successful.
pub bitcoin_rpc_connected: bool,

/// The last error message we received when trying to poll the client, if
/// there was one.
pub last_rpc_error: Option<String>,

/// Current block height.
pub cur_height: u64,

/// Current tip block ID as string.
pub cur_tip_blkid: String,

/// Last published txid where L2 blob was present
pub last_published_txid: Option<Buf32>,

/// UNIX millis time of the last time we got a new update from the L1 connector.
pub last_update: u64,

/// Number of published reveal transactions.
pub published_reveal_txs_count: u64,
}
2 changes: 2 additions & 0 deletions crates/primitives/src/l1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ mod block;
mod btc;
pub mod payload;
mod proof;
mod status;

pub use block::*;
pub use btc::*;
pub use proof::*;
pub use status::*;
62 changes: 52 additions & 10 deletions crates/primitives/src/l1/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use num_enum::{IntoPrimitive, TryFromPrimitive};
use serde::{Deserialize, Serialize};

use crate::{buf::Buf32, hash};

/// DA destination identifier. This will eventually be used to enable
/// storing payloads on alternative availability schemes.
#[derive(
Expand All @@ -28,15 +29,15 @@ use crate::{buf::Buf32, hash};
)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum BlobDest {
pub enum PayloadDest {
/// If we expect the DA to be on the L1 chain that we settle to. This is
/// always the strongest DA layer we have access to.
L1 = 0,
}

/// Manual `Arbitrary` impl so that we always generate L1 DA if we add future
/// ones that would work in totally different ways.
impl<'a> Arbitrary<'a> for BlobDest {
impl<'a> Arbitrary<'a> for PayloadDest {
fn arbitrary(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::L1)
}

Check warning on line 43 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L41-L43

Added lines #L41 - L43 were not covered by tests
Expand All @@ -59,7 +60,7 @@ impl<'a> Arbitrary<'a> for BlobDest {
)]
pub struct BlobSpec {
/// Target settlement layer we're expecting the DA on.
dest: BlobDest,
dest: PayloadDest,

/// Commitment to the payload (probably just a hash or a
/// merkle root) that we expect to see committed to DA.
Expand All @@ -68,7 +69,48 @@ pub struct BlobSpec {

impl BlobSpec {
/// The target we expect the DA payload to be stored on.
pub fn dest(&self) -> BlobDest {
pub fn dest(&self) -> PayloadDest {
self.dest
}

Check warning on line 74 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L72-L74

Added lines #L72 - L74 were not covered by tests

/// Commitment to the payload.
pub fn commitment(&self) -> &Buf32 {
&self.commitment
}

Check warning on line 79 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L77-L79

Added lines #L77 - L79 were not covered by tests

#[allow(dead_code)]
fn new(dest: PayloadDest, commitment: Buf32) -> Self {
Self { dest, commitment }
}

Check warning on line 84 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L82-L84

Added lines #L82 - L84 were not covered by tests
}

/// Summary of a DA payload to be included on a DA layer. Specifies the target and
/// a commitment to the payload.
#[derive(
Copy,
Clone,
Debug,
Eq,
PartialEq,
Hash,
Arbitrary,
BorshDeserialize,
BorshSerialize,

Check warning on line 98 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L96-L98

Added lines #L96 - L98 were not covered by tests
Serialize,
Deserialize,
)]
pub struct PayloadSpec {
/// Target settlement layer we're expecting the DA on.
dest: PayloadDest,

/// Commitment to the payload (probably just a hash or a
/// merkle root) that we expect to see committed to DA.
commitment: Buf32,
}

impl PayloadSpec {
/// The target we expect the DA payload to be stored on.
pub fn dest(&self) -> PayloadDest {
self.dest
}

Check warning on line 115 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L113-L115

Added lines #L113 - L115 were not covered by tests

Expand All @@ -77,7 +119,7 @@ impl BlobSpec {
&self.commitment
}

Check warning on line 120 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L118-L120

Added lines #L118 - L120 were not covered by tests

fn new(dest: BlobDest, commitment: Buf32) -> Self {
fn new(dest: PayloadDest, commitment: Buf32) -> Self {
Self { dest, commitment }
}

Check warning on line 124 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L122-L124

Added lines #L122 - L124 were not covered by tests
}
Expand Down Expand Up @@ -131,7 +173,7 @@ pub enum L1PayloadType {
#[derive(Clone, Debug, Eq, PartialEq, Arbitrary, BorshDeserialize, BorshSerialize)]

Check warning on line 173 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L173

Added line #L173 was not covered by tests
pub struct PayloadIntent {
/// The destination for this payload.
dest: BlobDest,
dest: PayloadDest,

/// Commitment to the payload.
commitment: Buf32,
Expand All @@ -141,7 +183,7 @@ pub struct PayloadIntent {
}

impl PayloadIntent {
pub fn new(dest: BlobDest, commitment: Buf32, payload: L1Payload) -> Self {
pub fn new(dest: PayloadDest, commitment: Buf32, payload: L1Payload) -> Self {
Self {
dest,
commitment,
Expand All @@ -150,7 +192,7 @@ impl PayloadIntent {
}

Check warning on line 192 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L186-L192

Added lines #L186 - L192 were not covered by tests

/// The target we expect the DA payload to be stored on.
pub fn dest(&self) -> BlobDest {
pub fn dest(&self) -> PayloadDest {
self.dest
}

Check warning on line 197 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L195-L197

Added lines #L195 - L197 were not covered by tests

Expand All @@ -168,7 +210,7 @@ impl PayloadIntent {

/// Generates the spec from the relevant parts of the payload intent that
/// uniquely refers to the payload data.
pub fn to_spec(&self) -> BlobSpec {
BlobSpec::new(self.dest, self.commitment)
pub fn to_spec(&self) -> PayloadSpec {
PayloadSpec::new(self.dest, self.commitment)
}

Check warning on line 215 in crates/primitives/src/l1/payload.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/payload.rs#L213-L215

Added lines #L213 - L215 were not covered by tests
}
31 changes: 31 additions & 0 deletions crates/primitives/src/l1/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use arbitrary::Arbitrary;
use serde::{Deserialize, Serialize};

use crate::buf::Buf32;

/// Data that reflects what's happening around L1
#[derive(Debug, Clone, Serialize, Deserialize, Default, Arbitrary)]

Check warning on line 7 in crates/primitives/src/l1/status.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/l1/status.rs#L7

Added line #L7 was not covered by tests
pub struct L1Status {
/// If the last time we tried to poll the client (as of `last_update`)
/// we were successful.
pub bitcoin_rpc_connected: bool,

/// The last error message we received when trying to poll the client, if
/// there was one.
pub last_rpc_error: Option<String>,

/// Current block height.
pub cur_height: u64,

/// Current tip block ID as string.
pub cur_tip_blkid: String,

/// Last published txid where L2 blob was present
pub last_published_txid: Option<Buf32>,

/// UNIX millis time of the last time we got a new update from the L1 connector.
pub last_update: u64,

/// Number of published reveal transactions.
pub published_reveal_txs_count: u64,
}
8 changes: 4 additions & 4 deletions crates/rocksdb-store/src/sequencer/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ impl RBSeqBlobDb {
}

impl L1PayloadDatabase for RBSeqBlobDb {
fn put_payload_entry(&self, blob_hash: Buf32, blob: PayloadEntry) -> DbResult<()> {
fn put_payload_entry(&self, payload_id: Buf32, entry: PayloadEntry) -> DbResult<()> {
self.db
.with_optimistic_txn(
rockbound::TransactionRetry::Count(self.ops.retry_count),
|tx| -> Result<(), DbError> {
// If new, increment idx
if tx.get::<SeqBlobSchema>(&blob_hash)?.is_none() {
if tx.get::<SeqBlobSchema>(&payload_id)?.is_none() {
let idx = get_next_id::<SeqBlobIdSchema, OptimisticTransactionDB>(tx)?;

tx.put::<SeqBlobIdSchema>(&idx, &blob_hash)?;
tx.put::<SeqBlobIdSchema>(&idx, &payload_id)?;
}

tx.put::<SeqBlobSchema>(&blob_hash, &blob)?;
tx.put::<SeqBlobSchema>(&payload_id, &entry)?;

Ok(())
},
Expand Down
4 changes: 3 additions & 1 deletion example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ network = "regtest"
l1_follow_distance = 6
client_checkpoint_interval = 10

[btcio]
[btcio.reader]
client_poll_dur_ms = 200

[btcio.writer]
write_poll_dur_ms = 200
fee_policy = "smart"
reveal_amount = 100
Expand Down

0 comments on commit cc85da7

Please sign in to comment.