Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
voidash committed Dec 19, 2024
1 parent 12d1ad7 commit 34a37c9
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 102 deletions.
41 changes: 14 additions & 27 deletions bin/strata-client/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ use strata_primitives::{
use strata_rpc_api::{StrataAdminApiServer, StrataApiServer, StrataSequencerApiServer};
use strata_rpc_types::{
errors::RpcServerError as Error, DaBlob, HexBytes, HexBytes32, L2BlockStatus, RpcBlockHeader,
RpcBridgeDuties, RpcCheckpointInfo, RpcClientStatus, RpcDepositEntry, RpcExecUpdate,
RpcL1Status, RpcSyncStatus,
RpcBridgeDuties, RpcCheckpointInfo, RpcClientStatus, RpcDepositEntry, RpcEnvelopePayload,
RpcExecUpdate, RpcL1Status, RpcSyncStatus,
};
use strata_rpc_utils::to_jsonrpsee_error;
use strata_state::{
batch::BatchCheckpoint,
block::L2BlockBundle,
bridge_duties::BridgeDuty,
bridge_ops::WithdrawalIntent,
da_blob::{BundledCommitment, BundledPayloadIntent, DataBundleDest},
header::L2Header,
id::L2BlockId,
l1::L1BlockId,
operation::ClientUpdateOutput,
da_blob::{BundleCommitment, BundlePayloadIntent, DataBundleDest},
sync_event::SyncEvent,
tx::{EnvelopePayload, PayloadTypeTag},
tx::EnvelopePayload,
};
use strata_status::StatusChannel;
use strata_storage::L2BlockManager;
Expand Down Expand Up @@ -656,12 +656,17 @@ impl SequencerServerImpl {
checkpoint_handle,
}
}
}

#[async_trait]
impl StrataSequencerApiServer for SequencerServerImpl {
async fn submit_envelope_payloads(&self, bundle: Vec<RpcEnvelopePayload>) -> RpcResult<()> {
let payload_vec: Vec<EnvelopePayload> =
bundle.into_iter().map(|payload| payload.into()).collect();

/// Submit DA payload entries to be placed in commit reveal Envelope
/// multiple Envelopes can exist in same transaction
async fn submit_blobs(&self, blob_vec: Vec<EnvelopePayload>) -> RpcResult<()> {
let blob_commitment = BundledCommitment::from_payload(&blob_vec);
let blobintent = BundledPayloadIntent::new(DataBundleDest::L1, blob_commitment, blob_vec);
let bundle_commitment = BundleCommitment::from_payload(&payload_vec);
let blobintent =
BundlePayloadIntent::new(DataBundleDest::L1, bundle_commitment, payload_vec);
// 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
Expand All @@ -673,24 +678,6 @@ impl SequencerServerImpl {
}
Ok(())
}
}

#[async_trait]
impl StrataSequencerApiServer for SequencerServerImpl {
async fn submit_da_blobs(&self, blobs: Vec<HexBytes>) -> RpcResult<()> {
let blob_vec: Vec<EnvelopePayload> = blobs
.into_iter()
.map(|blob| EnvelopePayload::new(PayloadTypeTag::DA, blob.into_inner()))
.collect();

self.submit_blobs(blob_vec).await
}

async fn submit_envelope_blob(&self, blob: HexBytes, tag: PayloadTypeTag) -> RpcResult<()> {
let blob = vec![EnvelopePayload::new(tag, blob.into_inner())];

self.submit_blobs(blob).await
}

async fn broadcast_raw_tx(&self, rawtx: HexBytes) -> RpcResult<Txid> {
let tx: BTransaction = deserialize(&rawtx.0).map_err(|e| Error::Other(e.to_string()))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/btcio/src/writer/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod test {

use strata_db::types::{BundleL1Status, DataBundleIntentEntry};
use strata_state::{
da_blob::BundledCommitment,
da_blob::BundleCommitment,
tx::{EnvelopePayload, PayloadTypeTag},
};

Expand All @@ -86,7 +86,7 @@ mod test {
assert_eq!(entry.commit_txid, Buf32::zero());
assert_eq!(entry.reveal_txid, Buf32::zero());

let intent_hash = BundledCommitment::from_payload(&entry.envelopes);
let intent_hash = BundleCommitment::from_payload(&entry.envelopes);
// let intent_hash =
iops.put_entry_async(intent_hash.into_inner(), entry.clone())
.await
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::{
};
use strata_primitives::buf::Buf32;
use strata_reveal_tx::builder::CommitRevealTxError;
use strata_state::da_blob::{BundledPayloadIntent, DataBundleDest, PayloadIntent};
use strata_state::da_blob::{BundlePayloadIntent, DataBundleDest, PayloadIntent};
use strata_status::StatusChannel;
use strata_storage::ops::envelope::{Context, EnvelopeDataOps};
use strata_tasks::TaskExecutor;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl EnvelopeHandle {
.await
}

pub fn submit_bundled_intent(&self, intent: BundledPayloadIntent) -> anyhow::Result<()> {
pub fn submit_bundled_intent(&self, intent: BundlePayloadIntent) -> anyhow::Result<()> {
if intent.dest() != DataBundleDest::L1 {
warn!(commitment = ?intent.commitment(), "Received intent not meant for L1");
return Ok(());
Expand All @@ -63,7 +63,7 @@ impl EnvelopeHandle {

pub async fn submit_bundled_intent_async(
&self,
intent: BundledPayloadIntent,
intent: BundlePayloadIntent,
) -> anyhow::Result<()> {
if intent.dest() != DataBundleDest::L1 {
warn!(commitment = ?intent.commitment(), "Received intent not meant for L1");
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus-logic/src/duty/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,17 @@ fn perform_duty<D: Database, E: ExecEngineCtl>(
PayloadTypeTag::Checkpoint,
borsh::to_vec(&signed_checkpoint).map_err(|e| Error::Other(e.to_string()))?,
);
let blob_intent = PayloadIntent::new(
let payload_intent = PayloadIntent::new(
DataBundleDest::L1,
PayloadCommitment::new(&checkpoint_sighash),
payload,
);

info!(signed_checkpoint = ?signed_checkpoint, "signed checkpoint");
info!(blob_intent = ?blob_intent, "sending blob intent");
info!(blob_intent = ?payload_intent, "sending blob intent");

envelope_handle
.submit_intent(blob_intent)
.submit_intent(payload_intent)
// add type for DA related errors ?
.map_err(|err| Error::Other(err.to_string()))?;

Expand Down
14 changes: 4 additions & 10 deletions crates/rpc/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use strata_primitives::bridge::{OperatorIdx, PublickeyTable};
use strata_rpc_types::{
types::{RpcBlockHeader, RpcClientStatus, RpcL1Status},
HexBytes, HexBytes32, L2BlockStatus, RpcBridgeDuties, RpcCheckpointInfo, RpcDepositEntry,
RpcExecUpdate, RpcSyncStatus,
};
use strata_state::{
id::L2BlockId, operation::ClientUpdateOutput, sync_event::SyncEvent, tx::PayloadTypeTag,
RpcEnvelopePayload, RpcExecUpdate, RpcSyncStatus,
};
use strata_state::{id::L2BlockId, operation::ClientUpdateOutput, sync_event::SyncEvent};

#[cfg_attr(not(feature = "client"), rpc(server, namespace = "strata"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "strata"))]
Expand Down Expand Up @@ -136,12 +134,8 @@ pub trait StrataAdminApi {
#[cfg_attr(feature = "client", rpc(server, client))]
pub trait StrataSequencerApi {
/// Adds L1Write sequencer duties which will be executed by sequencer
#[method(name = "strataadmin_submitDABlobs")]
async fn submit_da_blobs(&self, blobs: Vec<HexBytes>) -> RpcResult<()>;

/// Adds L1Write sequencer duty which will be executed by sequencer
#[method(name = "strataadmin_submitEnvelopeBlob")]
async fn submit_envelope_blob(&self, blob: HexBytes, tag: PayloadTypeTag) -> RpcResult<()>;
#[method(name = "strataadmin_submitEnvelopePayloads")]
async fn submit_envelope_payloads(&self, payload: Vec<RpcEnvelopePayload>) -> RpcResult<()>;

/// Verifies and adds the submitted proof to the checkpoint database
#[method(name = "strataadmin_submitCheckpointProof")]
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/btcio-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl fmt::Display for UnexpectedServerVersionError {
}
write!(
f,
"unexpected bitcoind version, got: {} expected one of: {}",
"unexpected bitcoind version, (got: {} expected one of: {})",
self.got, expected
)
}
Expand Down
33 changes: 33 additions & 0 deletions crates/rpc/types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use bitcoin::{Network, Txid};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use strata_primitives::{
bridge::OperatorIdx,
l1::{BitcoinAmount, L1TxRef, OutputRef},
Expand All @@ -17,6 +18,7 @@ use strata_state::{
bridge_ops::WithdrawalIntent,
bridge_state::{DepositEntry, DepositState},
id::L2BlockId,
tx::{EnvelopePayload, PayloadTypeTag},
};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -314,3 +316,34 @@ pub enum L2BlockStatus {
/// Block is now finalized, certain depth has been reached in L1
Finalized(u64),
}

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RpcEnvelopePayload {
/// type of payload
tag: RpcPayloadTypeTag,
/// payload present in envelope
#[serde_as(as = "serde_with::hex::Hex")]
data: Vec<u8>,
}

impl From<RpcEnvelopePayload> for EnvelopePayload {
fn from(value: RpcEnvelopePayload) -> Self {
EnvelopePayload::new(value.tag.into(), value.data)
}
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum RpcPayloadTypeTag {
Checkpoint,
DA,
}

impl From<RpcPayloadTypeTag> for PayloadTypeTag {
fn from(value: RpcPayloadTypeTag) -> Self {
match value {
RpcPayloadTypeTag::Checkpoint => PayloadTypeTag::Checkpoint,
RpcPayloadTypeTag::DA => PayloadTypeTag::DA,
}
}
}
Loading

0 comments on commit 34a37c9

Please sign in to comment.