Skip to content

Commit

Permalink
refactor(proto)!: update SequencerBlockHeader and related proto typ…
Browse files Browse the repository at this point in the history
…es to not use cometbft header (#830)

## Summary
update `SequencerBlockHeader`, `SequencerBlock`,
`FilteredSequencerBlock`, and `CelestiaSequencerBlob` to not contain an
entire cometbft header, but only to contain relevant fields required.

## Background
this is required for the update to ABCI v0.38, as `finalize_block` no
longer passes in the entire block header (like `begin_block` did). we
keep needed fields like height, chain_id, timestamp, proposer_address,
data_hash in the `SequencerBlockHeader`.

## Changes
- update `SequencerBlockHeader` to not contain an entire cometbft header
but have height, chain_id, timestamp, proposer_address, data_hash - all
fields are now explicitly needed by other components of the stack
- update `SequencerBlock`, `FilteredSequencerBlock`, and
`CelestiaSequencerBlob` to have `block_hash` as this can no longer be
calculated from the cometbft header as it doesn't exist anymore
- deprecate `rollup_ids_root` in `SequencerBlockHeader` as it can be
calculated by the list of rollup IDs in a block

## Testing
unit tests

## Breaking Changelist
- the `SequencerBlockHeader`, `SequencerBlock`,
`FilteredSequencerBlock`, and `CelestiaSequencerBlob` are changed.

## Related Issues

 related to  #679
  • Loading branch information
noot authored Apr 17, 2024
1 parent 473041a commit 6665948
Show file tree
Hide file tree
Showing 61 changed files with 3,170 additions and 387 deletions.
2 changes: 1 addition & 1 deletion charts/sequencer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.11.4
version: 0.11.5

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
2 changes: 0 additions & 2 deletions charts/sequencer/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ metadata:
{{- end }}
{{- end }}
{{- else }}
kubernetes.io/ingress.class: nginx
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName $ingress.ingressClassName }}
Expand Down Expand Up @@ -103,7 +102,6 @@ metadata:
{{- end }}
{{- end }}
{{- else }}
kubernetes.io/ingress.class: nginx
{{- end }}
spec:
{{- if and $ingressSupportsIngressClassName $ingress.ingressClassName }}
Expand Down
12 changes: 7 additions & 5 deletions crates/astria-celestia-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use astria_core::sequencer::v1::{
use astria_core::sequencerblock::v1alpha1::{
celestia::CelestiaSequencerBlobError,
CelestiaRollupBlob,
CelestiaSequencerBlob,
Expand Down Expand Up @@ -103,7 +103,7 @@ pub trait CelestiaClientExt: BlobClient {
}
'blob: {
let raw_blob =
match astria_core::generated::sequencer::v1::CelestiaSequencerBlob::decode(
match astria_core::generated::sequencerblock::v1alpha1::CelestiaSequencerBlob::decode(
&*blob.data,
) {
Ok(blob) => blob,
Expand Down Expand Up @@ -254,11 +254,13 @@ fn convert_and_filter_rollup_blobs(
continue;
}
let proto_blob =
match astria_core::generated::sequencer::v1::CelestiaRollupBlob::decode(&*blob.data) {
match astria_core::generated::sequencerblock::v1alpha1::CelestiaRollupBlob::decode(
&*blob.data,
) {
Err(e) => {
debug!(
error = &e as &dyn std::error::Error,
target = "astria.sequencer.v1alpha.CelestiaRollupBlob",
target = "astria.sequencerblock.v1alpha1.CelestiaRollupBlob",
blob.commitment = %Base64Display::new(&blob.commitment.0, &STANDARD),
"failed decoding blob as protobuf; skipping"
);
Expand Down Expand Up @@ -305,7 +307,7 @@ fn does_rollup_blob_verify_against_sequencer_blob(
rollup_blob
.proof()
.audit()
.with_root(sequencer_blob.rollup_transactions_root())
.with_root(sequencer_blob.header().rollup_transactions_root())
.with_leaf_builder()
.write(&rollup_blob.rollup_id().get())
.write(&merkle::Tree::from_leaves(rollup_blob.transactions()).root())
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-celestia-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod client;
pub mod metrics_init;
pub mod submission;

pub use astria_core::sequencer::v1::{
pub use astria_core::sequencerblock::v1alpha1::{
CelestiaRollupBlob,
CelestiaSequencerBlob,
};
Expand Down Expand Up @@ -55,10 +55,10 @@ pub const fn celestia_namespace_v0_from_rollup_id(
}

#[must_use = "a celestia namespace must be used in order to be useful"]
pub fn celestia_namespace_v0_from_cometbft_header(header: &tendermint::block::Header) -> Namespace {
pub fn celestia_namespace_v0_from_str(chain_id: &str) -> Namespace {
use sha2::{
Digest as _,
Sha256,
};
celestia_namespace_v0_from_array(Sha256::digest(header.chain_id.as_bytes()).into())
celestia_namespace_v0_from_array(Sha256::digest(chain_id.as_bytes()).into())
}
8 changes: 4 additions & 4 deletions crates/astria-celestia-client/src/submission.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Logic to convert sequencer blocks to celestia blobs before submission.
use astria_core::sequencer::v1::{
RollupId,
SequencerBlock,
use astria_core::{
sequencer::v1::RollupId,
sequencerblock::v1alpha1::SequencerBlock,
};
use celestia_types::Blob;
use prost::Message as _;
Expand Down Expand Up @@ -67,7 +67,7 @@ fn convert(block: SequencerBlock, blobs: &mut Vec<Blob>) -> Result<(), ToBlobsEr
// the rest for the rollup blobs.
blobs.reserve(rollup_blobs.len() + 1);
let sequencer_namespace =
crate::celestia_namespace_v0_from_cometbft_header(sequencer_blob.header());
crate::celestia_namespace_v0_from_str(sequencer_blob.header().chain_id().as_str());

let header_blob = Blob::new(
sequencer_namespace,
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-cli/src/commands/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub(crate) async fn create_config(args: &ConfigCreateArgs) -> eyre::Result<()> {
.await
.wrap_err("failed to get sequencer block for initial sequencer height")?;

let new_height: u64 = res.header().cometbft_header().height.into();
let new_height: u64 = res.height().into();
conf.sequencer_initial_block_height = Some(new_height);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/astria-cli/src/commands/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub(crate) async fn get_block_height(args: &BlockHeightGetArgs) -> eyre::Result<
.wrap_err("failed to get sequencer block")?;

println!("Block Height:");
println!(" {}", res.header().cometbft_header().height);
println!(" {}", res.height());

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-conductor/src/block_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
future::Future,
};

use astria_core::sequencer::v1::{
use astria_core::sequencerblock::v1alpha1::{
block::FilteredSequencerBlock,
CelestiaSequencerBlob,
};
Expand Down
60 changes: 40 additions & 20 deletions crates/astria-conductor/src/celestia/block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,13 @@ fn verify_vote_signature(
mod test {
use std::collections::BTreeMap;

use astria_core::sequencer::v1::{
celestia::UncheckedCelestiaSequencerBlob,
test_utils::make_cometbft_block,
RollupId,
use astria_core::{
generated::sequencerblock::v1alpha1::SequencerBlockHeader as RawSequencerBlockHeader,
sequencer::v1::RollupId,
sequencerblock::v1alpha1::{
block::SequencerBlockHeader,
celestia::UncheckedCelestiaSequencerBlob,
},
};
use prost::Message as _;
use sequencer_client::{
Expand Down Expand Up @@ -371,24 +374,33 @@ mod test {
#[test]
fn validate_sequencer_blob_last_commit_none_ok() {
let rollup_transactions_root = merkle::Tree::from_leaves([[1, 2, 3], [4, 5, 6]]).root();
let chain_ids_commitment = merkle::Tree::new().root();
let rollup_ids_root = merkle::Tree::new().root();

let tree = merkle_tree_from_transactions([rollup_transactions_root, chain_ids_commitment]);
let tree = merkle_tree_from_transactions([rollup_transactions_root, rollup_ids_root]);
let data_hash = tree.root();
let rollup_transactions_proof = tree.construct_proof(0).unwrap();
let rollup_ids_proof = tree.construct_proof(1).unwrap();

let mut header = make_cometbft_block().header;
let height = header.height.value().try_into().unwrap();
header.data_hash = Some(Hash::try_from(data_hash.to_vec()).unwrap());

let (validator_set, proposer_address, commit) =
make_test_validator_set_and_commit(height, header.chain_id.clone());
header.proposer_address = proposer_address;
make_test_validator_set_and_commit(1, "test-chain".try_into().unwrap());

let header = RawSequencerBlockHeader {
chain_id: "test-chain".to_string(),
height: 1,
time: Some(pbjson_types::Timestamp {
seconds: 1,
nanos: 0,
}),
data_hash: data_hash.to_vec(),
rollup_transactions_root: rollup_transactions_root.to_vec(),
proposer_address: proposer_address.as_bytes().to_vec(),
};
let header = SequencerBlockHeader::try_from_raw(header).unwrap();

let sequencer_blob = UncheckedCelestiaSequencerBlob {
block_hash: [0u8; 32],
header,
rollup_ids: vec![],
rollup_transactions_root,
rollup_transactions_proof,
rollup_ids_proof,
}
Expand All @@ -414,18 +426,26 @@ mod test {
let rollup_transactions_proof = tree.construct_proof(0).unwrap();
let rollup_ids_proof = tree.construct_proof(1).unwrap();

let mut header = make_cometbft_block().header;
let height = header.height.value().try_into().unwrap();
header.data_hash = Some(Hash::try_from(data_hash.to_vec()).unwrap());

let (validator_set, proposer_address, commit) =
make_test_validator_set_and_commit(height, header.chain_id.clone());
header.proposer_address = proposer_address;
make_test_validator_set_and_commit(1, "test-chain".try_into().unwrap());

let header = RawSequencerBlockHeader {
chain_id: "test-chain".to_string(),
height: 1,
time: Some(pbjson_types::Timestamp {
seconds: 1,
nanos: 0,
}),
data_hash: data_hash.to_vec(),
rollup_transactions_root: rollup_transactions_root.to_vec(),
proposer_address: proposer_address.as_bytes().to_vec(),
};
let header = SequencerBlockHeader::try_from_raw(header).unwrap();

let sequencer_blob = UncheckedCelestiaSequencerBlob {
block_hash: [0u8; 32],
header,
rollup_ids: vec![rollup_id],
rollup_transactions_root,
rollup_transactions_proof,
rollup_ids_proof,
}
Expand Down
14 changes: 6 additions & 8 deletions crates/astria-conductor/src/celestia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
time::Duration,
};

use astria_core::sequencerblock::v1alpha1::block::SequencerBlockHeader;
use astria_eyre::eyre::{
self,
bail,
Expand Down Expand Up @@ -35,10 +36,7 @@ use futures::{
use futures_bounded::FuturesMap;
use pin_project_lite::pin_project;
use sequencer_client::{
tendermint::{
self,
block::Height as SequencerHeight,
},
tendermint::block::Height as SequencerHeight,
HttpClient as SequencerClient,
};
use telemetry::display::{
Expand Down Expand Up @@ -97,14 +95,14 @@ struct ReconstructedBlocks {
#[derive(Clone, Debug)]
pub(crate) struct ReconstructedBlock {
pub(crate) block_hash: [u8; 32],
pub(crate) header: tendermint::block::Header,
pub(crate) header: SequencerBlockHeader,
pub(crate) transactions: Vec<Vec<u8>>,
pub(crate) celestia_height: u64,
}

impl ReconstructedBlock {
pub(crate) fn sequencer_height(&self) -> SequencerHeight {
self.header.height
self.header.height()
}
}

Expand Down Expand Up @@ -628,8 +626,8 @@ async fn get_sequencer_namespace(client: SequencerClient) -> eyre::Result<Namesp
.await
.wrap_err("failed to get latest commit from sequencer after 10 attempts")?;

Ok(celestia_client::celestia_namespace_v0_from_cometbft_header(
block.header().cometbft_header(),
Ok(celestia_client::celestia_namespace_v0_from_str(
block.header().chain_id().as_str(),
))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/astria-conductor/src/celestia/reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
{
let mut seq = serializer.serialize_seq(Some(self.0.len()))?;
for elem in self.0 {
seq.serialize_element(&elem.get_height().value())?;
seq.serialize_element(&elem.get_height())?;
}
seq.end()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-conductor/src/executor/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use astria_core::{
},
sequencer::v1::RollupData,
},
Protobuf as _,
sequencerblock::Protobuf as _,
};
use astria_eyre::eyre::{
self,
Expand Down
16 changes: 7 additions & 9 deletions crates/astria-conductor/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use astria_core::{
Block,
CommitmentState,
},
sequencer::v1::{
block::{
FilteredSequencerBlock,
FilteredSequencerBlockParts,
},
RollupId,
sequencer::v1::RollupId,
sequencerblock::v1alpha1::block::{
FilteredSequencerBlock,
FilteredSequencerBlockParts,
},
};
use astria_eyre::eyre::{
Expand Down Expand Up @@ -530,10 +528,10 @@ impl ExecutableBlock {
transactions,
..
} = block;
let timestamp = convert_tendermint_time_to_protobuf_timestamp(header.time);
let timestamp = convert_tendermint_time_to_protobuf_timestamp(header.time());
Self {
hash: block_hash,
height: header.height,
height: header.height(),
timestamp,
transactions,
}
Expand All @@ -542,7 +540,7 @@ impl ExecutableBlock {
fn from_sequencer(block: FilteredSequencerBlock, id: RollupId) -> Self {
let hash = block.block_hash();
let height = block.height();
let timestamp = convert_tendermint_time_to_protobuf_timestamp(block.cometbft_header().time);
let timestamp = convert_tendermint_time_to_protobuf_timestamp(block.header().time());
let FilteredSequencerBlockParts {
mut rollup_transactions,
..
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-conductor/src/executor/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn map_rollup_height_to_sequencer_height(
mod tests {
use astria_core::{
generated::execution::v1alpha2 as raw,
Protobuf as _,
sequencerblock::Protobuf as _,
};
use pbjson_types::Timestamp;

Expand Down
Loading

0 comments on commit 6665948

Please sign in to comment.