Skip to content

Commit

Permalink
replace Celestia*Blob nomenclature by Submitted*
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed May 8, 2024
1 parent d913803 commit 50ffab0
Show file tree
Hide file tree
Showing 13 changed files with 886 additions and 872 deletions.
4 changes: 2 additions & 2 deletions crates/astria-conductor/src/block_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use astria_core::sequencerblock::v1alpha1::{
block::FilteredSequencerBlock,
CelestiaHeader,
SubmittedMetadata,
};
use pin_project_lite::pin_project;
use sequencer_client::tendermint::block::Height;
Expand All @@ -21,7 +21,7 @@ impl GetSequencerHeight for FilteredSequencerBlock {
}
}

impl GetSequencerHeight for CelestiaHeader {
impl GetSequencerHeight for SubmittedMetadata {
fn get_height(&self) -> Height {
self.height()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-conductor/src/celestia/block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod test {
primitive::v1::RollupId,
sequencerblock::v1alpha1::{
block::SequencerBlockHeader,
celestia::UncheckedCelestiaSequencerBlob,
celestia::UncheckedSubmittedMetadata,
},
};
use prost::Message as _;
Expand Down Expand Up @@ -343,7 +343,7 @@ mod test {
};
let header = SequencerBlockHeader::try_from_raw(header).unwrap();

let sequencer_blob = UncheckedCelestiaSequencerBlob {
let sequencer_blob = UncheckedSubmittedMetadata {
block_hash: [0u8; 32],
header,
rollup_ids: vec![],
Expand Down Expand Up @@ -388,7 +388,7 @@ mod test {
};
let header = SequencerBlockHeader::try_from_raw(header).unwrap();

let sequencer_blob = UncheckedCelestiaSequencerBlob {
let sequencer_blob = UncheckedSubmittedMetadata {
block_hash: [0u8; 32],
header,
rollup_ids: vec![rollup_id],
Expand Down
76 changes: 38 additions & 38 deletions crates/astria-conductor/src/celestia/convert.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use astria_core::{
brotli::decompress_bytes,
generated::sequencerblock::v1alpha1::{
CelestiaHeaderList,
CelestiaRollupDataList,
SubmittedMetadataList,
SubmittedRollupDataList,
},
sequencerblock::v1alpha1::{
celestia::{
CelestiaRollupBlobError,
CelestiaSequencerBlobError,
SubmittedMetadataError,
SubmittedRollupDataError,
},
CelestiaHeader,
CelestiaRollupData,
SubmittedMetadata,
SubmittedRollupData,
},
};
use celestia_types::{
Expand Down Expand Up @@ -69,76 +69,76 @@ pub(super) fn decode_raw_blobs(
converted_blobs
}

/// An unsorted [`CelestiaSequencerBlob`] and [`CelestiaRollupBlob`].
/// An unsorted [`SubmittedMetadata`] and [`SubmittedRollupData`].
pub(super) struct ConvertedBlobs {
celestia_height: u64,
headers: Vec<CelestiaHeader>,
rollup_data_entries: Vec<CelestiaRollupData>,
metadata: Vec<SubmittedMetadata>,
rollup_data: Vec<SubmittedRollupData>,
}

impl ConvertedBlobs {
pub(super) fn len_headers(&self) -> usize {
self.headers.len()
self.metadata.len()
}

pub(super) fn len_rollup_data_entries(&self) -> usize {
self.rollup_data_entries.len()
self.rollup_data.len()
}

pub(super) fn into_parts(self) -> (u64, Vec<CelestiaHeader>, Vec<CelestiaRollupData>) {
(self.celestia_height, self.headers, self.rollup_data_entries)
pub(super) fn into_parts(self) -> (u64, Vec<SubmittedMetadata>, Vec<SubmittedRollupData>) {
(self.celestia_height, self.metadata, self.rollup_data)
}

fn new(celestia_height: u64) -> Self {
Self {
celestia_height,
headers: Vec::new(),
rollup_data_entries: Vec::new(),
metadata: Vec::new(),
rollup_data: Vec::new(),
}
}

fn push_header(&mut self, header: CelestiaHeader) {
self.headers.push(header);
fn push_header(&mut self, header: SubmittedMetadata) {
self.metadata.push(header);
}

fn push_rollup_data(&mut self, rollup: CelestiaRollupData) {
self.rollup_data_entries.push(rollup);
fn push_rollup_data(&mut self, rollup: SubmittedRollupData) {
self.rollup_data.push(rollup);
}

fn extend_from_header_list_if_well_formed(&mut self, list: CelestiaHeaderList) {
let initial_len = self.headers.len();
if let Err(err) = list.headers.into_iter().try_for_each(|raw| {
let header = CelestiaHeader::try_from_raw(raw)?;
fn extend_from_header_list_if_well_formed(&mut self, list: SubmittedMetadataList) {
let initial_len = self.metadata.len();
if let Err(err) = list.entries.into_iter().try_for_each(|raw| {
let header = SubmittedMetadata::try_from_raw(raw)?;
self.push_header(header);
Ok::<(), CelestiaSequencerBlobError>(())
Ok::<(), SubmittedMetadataError>(())
}) {
info!(
error = &err as &StdError,
"one header in {} was not well-formed; dropping all",
CelestiaHeaderList::full_name(),
SubmittedMetadataList::full_name(),
);
self.headers.truncate(initial_len);
self.metadata.truncate(initial_len);
}
}

fn extend_from_rollup_data_list_if_well_formed(&mut self, list: CelestiaRollupDataList) {
let initial_len = self.rollup_data_entries.len();
fn extend_from_rollup_data_list_if_well_formed(&mut self, list: SubmittedRollupDataList) {
let initial_len = self.rollup_data.len();
if let Err(err) = list.entries.into_iter().try_for_each(|raw| {
let entry = CelestiaRollupData::try_from_raw(raw)?;
let entry = SubmittedRollupData::try_from_raw(raw)?;
self.push_rollup_data(entry);
Ok::<(), CelestiaRollupBlobError>(())
Ok::<(), SubmittedRollupDataError>(())
}) {
info!(
error = &err as &StdError,
"one entry in {} was not well-formed; dropping all",
CelestiaRollupDataList::full_name(),
SubmittedRollupDataList::full_name(),
);
self.rollup_data_entries.truncate(initial_len);
self.rollup_data.truncate(initial_len);
}
}
}

fn convert_blob_to_header_list(blob: &Blob) -> Option<CelestiaHeaderList> {
fn convert_blob_to_header_list(blob: &Blob) -> Option<SubmittedMetadataList> {
let data = decompress_bytes(&blob.data)
.inspect_err(|err| {
info!(
Expand All @@ -147,19 +147,19 @@ fn convert_blob_to_header_list(blob: &Blob) -> Option<CelestiaHeaderList> {
);
})
.ok()?;
let raw = CelestiaHeaderList::decode(&*data)
let raw = SubmittedMetadataList::decode(&*data)
.inspect_err(|err| {
info!(
error = err as &StdError,
target = CelestiaHeaderList::full_name(),
target = SubmittedMetadataList::full_name(),
"failed decoding blob bytes; dropping the blob",
);
})
.ok()?;
Some(raw)
}

fn convert_blob_to_rollup_data_list(blob: &Blob) -> Option<CelestiaRollupDataList> {
fn convert_blob_to_rollup_data_list(blob: &Blob) -> Option<SubmittedRollupDataList> {
let data = decompress_bytes(&blob.data)
.inspect_err(|err| {
info!(
Expand All @@ -168,11 +168,11 @@ fn convert_blob_to_rollup_data_list(blob: &Blob) -> Option<CelestiaRollupDataLis
);
})
.ok()?;
let raw = CelestiaRollupDataList::decode(&*data)
let raw = SubmittedRollupDataList::decode(&*data)
.inspect_err(|err| {
info!(
error = err as &StdError,
target = CelestiaRollupDataList::full_name(),
target = SubmittedRollupDataList::full_name(),
"failed decoding blob bytes; dropping the blob",
);
})
Expand Down
14 changes: 7 additions & 7 deletions crates/astria-conductor/src/celestia/reconstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use astria_core::{
primitive::v1::RollupId,
sequencerblock::v1alpha1::{
CelestiaHeader,
CelestiaRollupData,
SubmittedMetadata,
SubmittedRollupData,
},
};
use telemetry::display::base64;
Expand Down Expand Up @@ -93,9 +93,9 @@ pub(super) fn reconstruct_blocks_from_verified_blobs(
}

fn remove_header_blob_matching_rollup_blob(
headers: &mut HashMap<[u8; 32], CelestiaHeader>,
rollup: &CelestiaRollupData,
) -> Option<CelestiaHeader> {
headers: &mut HashMap<[u8; 32], SubmittedMetadata>,
rollup: &SubmittedRollupData,
) -> Option<SubmittedMetadata> {
// chaining methods and returning () to use the ? operator and to not bind the value
headers
.get(&rollup.sequencer_block_hash())
Expand All @@ -106,8 +106,8 @@ fn remove_header_blob_matching_rollup_blob(
}

fn verify_rollup_blob_against_sequencer_blob(
rollup_blob: &CelestiaRollupData,
sequencer_blob: &CelestiaHeader,
rollup_blob: &SubmittedRollupData,
sequencer_blob: &SubmittedMetadata,
) -> bool {
rollup_blob
.proof()
Expand Down
16 changes: 8 additions & 8 deletions crates/astria-conductor/src/celestia/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{
};

use astria_core::sequencerblock::v1alpha1::{
CelestiaHeader,
CelestiaRollupData,
SubmittedMetadata,
SubmittedRollupData,
};
use astria_eyre::{
eyre,
Expand Down Expand Up @@ -48,8 +48,8 @@ use crate::utils::flatten;

pub(super) struct VerifiedBlobs {
celestia_height: u64,
header_blobs: HashMap<[u8; 32], CelestiaHeader>,
rollup_blobs: Vec<CelestiaRollupData>,
header_blobs: HashMap<[u8; 32], SubmittedMetadata>,
rollup_blobs: Vec<SubmittedRollupData>,
}

impl VerifiedBlobs {
Expand All @@ -65,8 +65,8 @@ impl VerifiedBlobs {
self,
) -> (
u64,
HashMap<[u8; 32], CelestiaHeader>,
Vec<CelestiaRollupData>,
HashMap<[u8; 32], SubmittedMetadata>,
Vec<SubmittedRollupData>,
) {
(self.celestia_height, self.header_blobs, self.rollup_blobs)
}
Expand Down Expand Up @@ -231,8 +231,8 @@ impl BlobVerifier {

async fn verify_header(
self: Arc<Self>,
header: CelestiaHeader,
) -> eyre::Result<CelestiaHeader> {
header: SubmittedMetadata,
) -> eyre::Result<SubmittedMetadata> {
use base64::prelude::*;
let height = header.height();
let meta = self
Expand Down
20 changes: 10 additions & 10 deletions crates/astria-conductor/tests/blackbox/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,26 +477,26 @@ pub struct Blobs {
#[must_use]
pub fn make_blobs(heights: &[u32]) -> Blobs {
use astria_core::generated::sequencerblock::v1alpha1::{
CelestiaHeaderList,
CelestiaRollupDataList,
SubmittedMetadataList,
SubmittedRollupDataList,
};
let mut headers = Vec::new();
let mut entries = Vec::new();
let mut metadata = Vec::new();
let mut rollup_data = Vec::new();
for &height in heights {
let (head, mut tail) = make_sequencer_block(height).split_for_celestia();
headers.push(head.into_raw());
metadata.push(head.into_raw());
assert_eq!(
1,
tail.len(),
"this test logic assumes that there is only one rollup in the mocked block"
);
entries.push(tail.swap_remove(0).into_raw());
rollup_data.push(tail.swap_remove(0).into_raw());
}
let header_list = CelestiaHeaderList {
headers,
let header_list = SubmittedMetadataList {
entries: metadata,
};
let rollup_data_list = CelestiaRollupDataList {
entries,
let rollup_data_list = SubmittedRollupDataList {
entries: rollup_data,
};

let raw_header_list = ::prost::Message::encode_to_vec(&header_list);
Expand Down
Loading

0 comments on commit 50ffab0

Please sign in to comment.