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

Split transition information from BatchInfo to BatchTransition #637

Merged
merged 9 commits into from
Feb 6, 2025
41 changes: 25 additions & 16 deletions bin/prover-client/src/operators/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use jsonrpsee::http_client::HttpClient;
use strata_db::traits::ProofDatabase;
use strata_primitives::{
buf::Buf32,
l1::L1BlockCommitment,
l2::L2BlockCommitment,
params::RollupParams,
proof::{ProofContext, ProofKey},
};
Expand Down Expand Up @@ -80,19 +82,13 @@ impl CheckpointOperator {
// Doing the manual block idx to id transformation. Will be removed once checkpoint_info
// include the range in terms of block_id.
// https://alpenlabs.atlassian.net/browse/STR-756
let start_l1_block_id = self
.l1_batch_operator
.get_block_at(checkpoint_info.l1_range.0)
.await?;
let end_l1_block_id = self
.l1_batch_operator
.get_block_at(checkpoint_info.l1_range.1)
.await?;
let start_l1_block_id = checkpoint_info.l1_range.0.blkid();
let end_l1_block_id = checkpoint_info.l1_range.1.blkid();

let l1_batch_keys = self
.l1_batch_operator
.create_task(
(start_l1_block_id, end_l1_block_id),
(*start_l1_block_id, *end_l1_block_id),
task_tracker.clone(),
db,
)
Expand All @@ -102,9 +98,9 @@ impl CheckpointOperator {
// Doing the manual block idx to id transformation. Will be removed once checkpoint_info
// include the range in terms of block_id.
// https://alpenlabs.atlassian.net/browse/STR-756
let start_l2_idx = self.get_l2id(checkpoint_info.l2_range.0).await?;
let end_l2_idx = self.get_l2id(checkpoint_info.l2_range.1).await?;
let l2_range = vec![(start_l2_idx, end_l2_idx)];
let start_l2_idx = checkpoint_info.l2_range.0.blkid();
let end_l2_idx = checkpoint_info.l2_range.1.blkid();
let l2_range = vec![(*start_l2_idx, *end_l2_idx)];

let l2_batch_keys = self
.l2_batch_operator
Expand Down Expand Up @@ -145,12 +141,25 @@ impl CheckpointOperator {
task_tracker: Arc<Mutex<TaskTracker>>,
db: &ProofDb,
) -> Result<Vec<ProofKey>, ProvingTaskError> {
let (start_l1_height, end_l1_height) = l1_range;
let (start_l2_height, end_l2_height) = l2_range;

let start_l1_block_id = self.l1_batch_operator.get_block_at(start_l1_height).await?;
let start_l1_commitment = L1BlockCommitment::new(start_l1_height, start_l1_block_id);

let end_l1_block_id = self.l1_batch_operator.get_block_at(end_l1_height).await?;
let end_l1_commitment = L1BlockCommitment::new(end_l1_height, end_l1_block_id);

let start_l2_block_id = self.get_l2id(start_l2_height).await?;
let start_l2_commitment = L2BlockCommitment::new(start_l2_height, start_l2_block_id);

let end_l2_block_id = self.get_l2id(end_l2_height).await?;
let end_l2_commitment = L2BlockCommitment::new(end_l2_height, end_l2_block_id);

let checkpoint_info = RpcCheckpointInfo {
idx: checkpoint_idx,
l1_range,
l2_range,
// TODO: likely unused and should be removed.
l2_blockid: Buf32::default().into(),
l1_range: (start_l1_commitment, end_l1_commitment),
l2_range: (start_l2_commitment, end_l2_commitment),
commitment: None,
confirmation_status: None,
};
Expand Down
10 changes: 5 additions & 5 deletions bin/strata-client/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl StrataRpcImpl {
};

// in current implementation, chainstate idx == l2 block idx
let (_, end_slot) = last_checkpoint.batch_info.l2_range;
let (_, end_commitment) = last_checkpoint.batch_info.l2_range;

Ok(self
.storage
.chainstate()
.get_toplevel_chainstate_async(end_slot)
.get_toplevel_chainstate_async(end_commitment.slot())
.await?
.map(Arc::new))
}
Expand Down Expand Up @@ -552,7 +552,7 @@ impl StrataApiServer for StrataRpcImpl {
Ok(client_state
.l1_view()
.last_finalized_checkpoint()
.map(|checkpoint| checkpoint.batch_info.idx()))
.map(|checkpoint| checkpoint.batch_info.epoch()))
} else {
// get latest checkpoint index from db
let idx = self
Expand Down Expand Up @@ -741,10 +741,10 @@ impl StrataSequencerApiServer for SequencerServerImpl {
verify_proof(&checkpoint, &proof_receipt, self.params.rollup())
.map_err(|e| Error::InvalidProof(idx, e.to_string()))?;

entry.proof = proof_receipt;
entry.checkpoint.update_proof(proof_receipt.proof().clone());
entry.proving_status = CheckpointProvingStatus::ProofReady;

debug!(%idx, "Proof is pending, setting proof reaedy");
debug!(%idx, "Proof is pending, setting proof ready");

self.checkpoint_handle
.put_checkpoint(idx, entry)
Expand Down
4 changes: 2 additions & 2 deletions bin/strata-sequencer-client/src/duty_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ async fn handle_commit_batch_duty<R>(
where
R: StrataSequencerApiClient + Send + Sync,
{
let sig = sign_checkpoint(duty.checkpoint(), &idata.key);
let sig = sign_checkpoint(duty.inner(), &idata.key);

rpc.complete_checkpoint_signature(duty.checkpoint().batch_info().idx(), HexBytes64(sig.0))
rpc.complete_checkpoint_signature(duty.inner().batch_info().epoch(), HexBytes64(sig.0))
.await
.map_err(DutyExecError::CompleteCheckpoint)?;

Expand Down
26 changes: 16 additions & 10 deletions crates/consensus-logic/src/csm/client_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ pub fn process_event(
&batch_checkpoint_with_commitment.batch_checkpoint;
L1Checkpoint::new(
batch_checkpoint.batch_info().clone(),
batch_checkpoint.bootstrap_state().clone(),
batch_checkpoint.batch_transition().clone(),
batch_checkpoint.base_state_commitment().clone(),
!batch_checkpoint.proof().is_empty(),
*height,
)
Expand Down Expand Up @@ -311,7 +312,7 @@ fn handle_mature_l1_height(
// If l2 blocks is not in db then finalization will happen when
// l2Block is fetched from the network and the corresponding
//checkpoint is already finalized.
let blkid = checkpt.batch_info.l2_blockid;
let blkid = *checkpt.batch_info.final_l2_blockid();

match context.get_l2_block_data(&blkid) {
Ok(_) => {
Expand Down Expand Up @@ -402,7 +403,12 @@ fn find_l1_height_for_l2_blockid(
target_l2_blockid: &L2BlockId,
) -> Option<u64> {
checkpoints
.binary_search_by(|checkpoint| checkpoint.batch_info.l2_blockid.cmp(target_l2_blockid))
.binary_search_by(|checkpoint| {
checkpoint
.batch_info
.final_l2_blockid()
.cmp(target_l2_blockid)
})
.ok()
.map(|index| checkpoints[index].height)
}
Expand Down Expand Up @@ -437,14 +443,14 @@ pub fn filter_verified_checkpoints(
} else {
last_finalized
}
.map(|x| (x.batch_info.idx() + 1, Some(&x.batch_info)))
.map(|x| (x.batch_info.epoch() + 1, Some(&x.batch_transition)))
.unwrap_or((0, None)); // expect the first checkpoint

let mut result_checkpoints = Vec::new();

for checkpoint in checkpoints {
let curr_idx = checkpoint.batch_checkpoint.batch_info().idx;
let proof_receipt: ProofReceipt = checkpoint.batch_checkpoint.clone().into_proof_receipt();
let curr_idx = checkpoint.batch_checkpoint.batch_info().epoch;
let proof_receipt: ProofReceipt = checkpoint.batch_checkpoint.get_proof_receipt();
if curr_idx != expected_idx {
warn!(%expected_idx, %curr_idx, "Received invalid checkpoint idx, ignoring.");
continue;
Expand All @@ -453,7 +459,7 @@ pub fn filter_verified_checkpoints(
&& verify_proof(&checkpoint.batch_checkpoint, &proof_receipt, params).is_ok()
{
result_checkpoints.push(checkpoint.clone());
last_valid_checkpoint = Some(checkpoint.batch_checkpoint.batch_info());
last_valid_checkpoint = Some(checkpoint.batch_checkpoint.batch_transition());
} else if expected_idx == 0 {
warn!(%expected_idx, "Received invalid checkpoint proof, ignoring.");
} else {
Expand All @@ -463,8 +469,8 @@ pub fn filter_verified_checkpoints(
let last_l2_tsn = last_valid_checkpoint
.expect("There should be a last_valid_checkpoint")
.l2_transition;
let l1_tsn = checkpoint.batch_checkpoint.batch_info().l1_transition;
let l2_tsn = checkpoint.batch_checkpoint.batch_info().l2_transition;
let l1_tsn = checkpoint.batch_checkpoint.batch_transition().l1_transition;
let l2_tsn = checkpoint.batch_checkpoint.batch_transition().l2_transition;

if l1_tsn.0 != last_l1_tsn.1 {
warn!(obtained = ?l1_tsn.0, expected = ?last_l1_tsn.1, "Received invalid checkpoint l1 transition, ignoring.");
Expand All @@ -476,7 +482,7 @@ pub fn filter_verified_checkpoints(
}
if verify_proof(&checkpoint.batch_checkpoint, &proof_receipt, params).is_ok() {
result_checkpoints.push(checkpoint.clone());
last_valid_checkpoint = Some(checkpoint.batch_checkpoint.batch_info());
last_valid_checkpoint = Some(checkpoint.batch_checkpoint.batch_transition());
} else {
warn!(%expected_idx, "Received invalid checkpoint proof, ignoring.");
continue;
Expand Down
12 changes: 4 additions & 8 deletions crates/consensus-logic/src/csm/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,11 @@ fn apply_action(
SyncAction::WriteCheckpoints(_height, checkpoints) => {
for c in checkpoints.iter() {
let batch_ckp = &c.batch_checkpoint;
let idx = batch_ckp.batch_info().idx();
let idx = batch_ckp.batch_info().epoch();
let pstatus = CheckpointProvingStatus::ProofReady;
let cstatus = CheckpointConfStatus::Confirmed;
let entry = CheckpointEntry::new(
batch_ckp.batch_info().clone(),
batch_ckp.bootstrap_state().clone(),
batch_ckp.clone().into_proof_receipt(),
batch_ckp.clone(),
pstatus,
cstatus,
Some(c.commitment.clone().into()),
Expand All @@ -380,13 +378,11 @@ fn apply_action(
SyncAction::FinalizeCheckpoints(_height, checkpoints) => {
for c in checkpoints.iter() {
let batch_ckp = &c.batch_checkpoint;
let idx = batch_ckp.batch_info().idx();
let idx = batch_ckp.batch_info().epoch();
let pstatus = CheckpointProvingStatus::ProofReady;
let cstatus = CheckpointConfStatus::Finalized;
let entry = CheckpointEntry::new(
batch_ckp.batch_info().clone(),
batch_ckp.bootstrap_state().clone(),
batch_ckp.clone().into_proof_receipt(),
batch_ckp.clone(),
pstatus,
cstatus,
Some(c.commitment.clone().into()),
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus-logic/src/duty/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn update_tracker(
let latest_finalized_batch = state
.l1_view()
.last_finalized_checkpoint()
.map(|x| x.batch_info.idx());
.map(|x| x.batch_info.epoch());

let tracker_update = types::StateUpdate::new(
block_idx,
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus-logic/src/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn verify_proof(
rollup_params: &RollupParams,
) -> ZkVmResult<()> {
let rollup_vk = rollup_params.rollup_vk;
let checkpoint_idx = checkpoint.batch_info().idx();
let checkpoint_idx = checkpoint.batch_info().epoch();
info!(%checkpoint_idx, "verifying proof");

// FIXME: we are accepting empty proofs for now (devnet) to reduce dependency on the prover
Expand All @@ -197,7 +197,7 @@ pub fn verify_proof(
return Ok(());
}

let expected_public_output = checkpoint.proof_output();
let expected_public_output = checkpoint.get_proof_output();
let actual_public_output: CheckpointProofOutput =
borsh::from_slice(proof_receipt.public_values().as_bytes())
.map_err(|e| ZkVmError::OutputExtractionError { source: e.into() })?;
Expand Down
40 changes: 18 additions & 22 deletions crates/db/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use strata_primitives::{
buf::Buf32,
l1::payload::{L1Payload, PayloadIntent},
};
use strata_state::batch::{BatchCheckpoint, BatchInfo, BootstrapState, CommitmentInfo};
use zkaleido::ProofReceipt;
use strata_state::batch::{
BaseStateCommitment, BatchCheckpoint, BatchInfo, BatchTransition, CommitmentInfo,
};
use zkaleido::Proof;

/// Represents an intent to publish to some DA, which will be bundled for efficiency.
#[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)]
Expand Down Expand Up @@ -184,15 +186,8 @@ pub enum L1TxStatus {
/// Entry corresponding to a BatchCommitment
#[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)]
pub struct CheckpointEntry {
/// Info related to the batch
pub batch_info: BatchInfo,

/// Includes the initial and final hashed state of both the `L1StateTransition` and
/// `L2StateTransition` that happened in this batch
pub bootstrap: BootstrapState,

/// Proof with public values
pub proof: ProofReceipt,
/// The batch checkpoint containing metadata, state transitions, and proof data.
pub checkpoint: BatchCheckpoint,

/// Proving Status
pub proving_status: CheckpointProvingStatus,
Expand All @@ -206,33 +201,33 @@ pub struct CheckpointEntry {

impl CheckpointEntry {
pub fn new(
batch_info: BatchInfo,
bootstrap: BootstrapState,
proof: ProofReceipt,
checkpoint: BatchCheckpoint,
proving_status: CheckpointProvingStatus,
confirmation_status: CheckpointConfStatus,
commitment: Option<CheckpointCommitment>,
) -> Self {
Self {
batch_info,
bootstrap,
proof,
checkpoint,
proving_status,
confirmation_status,
commitment,
}
}

pub fn into_batch_checkpoint(self) -> BatchCheckpoint {
BatchCheckpoint::new(self.batch_info, self.bootstrap, self.proof.proof().clone())
self.checkpoint
}

/// Creates a new instance for a freshly defined checkpoint.
pub fn new_pending_proof(info: BatchInfo, bootstrap: BootstrapState) -> Self {
pub fn new_pending_proof(
info: BatchInfo,
transition: BatchTransition,
base_state_commitment: BaseStateCommitment,
) -> Self {
let checkpoint =
BatchCheckpoint::new(info, transition, base_state_commitment, Proof::default());
Self::new(
info,
bootstrap,
ProofReceipt::default(),
checkpoint,
CheckpointProvingStatus::PendingProof,
CheckpointConfStatus::Pending,
None,
Expand Down Expand Up @@ -269,6 +264,7 @@ pub enum CheckpointConfStatus {
Finalized,
}

// TODO: why is this needed? can this information be part of `L1Checkpoint`?
#[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Arbitrary)]
pub struct CheckpointCommitment {
pub blockhash: Buf32,
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/l1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl From<L1BlockId> for BlockHash {
}

#[derive(
Debug,
Copy,
Clone,
Eq,
Expand Down
Loading
Loading