From 00714ab3afe681f99e61cd78f240c483918b9e8f Mon Sep 17 00:00:00 2001 From: Ethan Oroshiba Date: Mon, 12 Aug 2024 12:45:56 -0500 Subject: [PATCH] chore(core, proto): migrate byte slices from Vec to Bytes (#1319) ## Summary Changed protobuf, astria-core, and dependent code to utilize generic `Bytes` instead of the default `Vec` to utilize zero-copy deserialization from Protobuf and make type conversion cheaper. ## Background Previously, some components were utilizing `Bytes` and some were utilizing `Vec` as the generated Rust types when converting from Protobuf `bytes`. ## Changes - Adjusted Protobuf compiler to use `Bytes` for all Astria paths. - Edited conversions to/from `Raw` in `astria-core` to utilize `prost::bytes::Bytes`. - Adjusted code which relied on `Vec`. ## Testing Passing all tests. ## Related Issues closes #674 --- crates/astria-composer/src/collectors/geth.rs | 2 +- crates/astria-composer/src/executor/tests.rs | 13 ++-- crates/astria-composer/src/test_utils.rs | 2 +- .../tests/blackbox/grpc_collector.rs | 13 ++-- .../src/celestia/block_verifier.rs | 15 ++--- crates/astria-conductor/src/celestia/mod.rs | 3 +- .../astria-conductor/src/executor/client.rs | 4 +- crates/astria-conductor/src/executor/mod.rs | 2 +- .../src/generated/astria.composer.v1alpha1.rs | 8 +-- .../generated/astria.execution.v1alpha1.rs | 20 +++--- .../astria.protocol.bridge.v1alpha1.rs | 4 +- .../astria.protocol.transactions.v1alpha1.rs | 12 ++-- .../astria.sequencerblock.v1alpha1.rs | 42 ++++++------- crates/astria-core/src/primitive/v1/mod.rs | 16 +---- .../src/protocol/bridge/v1alpha1/mod.rs | 15 +++-- crates/astria-core/src/protocol/mod.rs | 7 ++- crates/astria-core/src/protocol/test_utils.rs | 6 +- .../protocol/transaction/v1alpha1/action.rs | 3 +- .../src/protocol/transaction/v1alpha1/mod.rs | 9 +-- .../src/sequencerblock/v1alpha1/block.rs | 62 ++++++++++++------- .../src/sequencerblock/v1alpha1/celestia.rs | 19 +++--- .../astria-sequencer-client/src/tests/http.rs | 3 +- .../blackbox/helpers/mock_sequencer_server.rs | 4 +- .../astria-sequencer-utils/src/blob_parser.rs | 2 +- crates/astria-sequencer/src/api_state_ext.rs | 3 +- crates/astria-sequencer/src/app/test_utils.rs | 3 +- crates/astria-sequencer/src/app/tests_app.rs | 19 +++--- .../src/app/tests_breaking_changes.rs | 9 ++- .../src/app/tests_execute_transaction.rs | 11 ++-- crates/astria-sequencer/src/grpc/sequencer.rs | 8 ++- .../src/mempool/benchmarks.rs | 3 +- .../src/proposal/commitment.rs | 5 +- .../astria-sequencer/src/service/consensus.rs | 2 +- .../src/transaction/checks.rs | 5 +- tools/protobuf-compiler/src/main.rs | 4 +- 35 files changed, 199 insertions(+), 159 deletions(-) diff --git a/crates/astria-composer/src/collectors/geth.rs b/crates/astria-composer/src/collectors/geth.rs index ae9759baa2..5b819de468 100644 --- a/crates/astria-composer/src/collectors/geth.rs +++ b/crates/astria-composer/src/collectors/geth.rs @@ -236,7 +236,7 @@ impl Geth { let data = tx.rlp().to_vec(); let seq_action = SequenceAction { rollup_id, - data, + data: data.into(), fee_asset: fee_asset.clone(), }; diff --git a/crates/astria-composer/src/executor/tests.rs b/crates/astria-composer/src/executor/tests.rs index 463cddfd14..0529fd449f 100644 --- a/crates/astria-composer/src/executor/tests.rs +++ b/crates/astria-composer/src/executor/tests.rs @@ -13,7 +13,10 @@ use astria_core::{ }; use astria_eyre::eyre; use once_cell::sync::Lazy; -use prost::Message; +use prost::{ + bytes::Bytes, + Message as _, +}; use sequencer_client::SignedTransaction; use serde_json::json; use tempfile::NamedTempFile; @@ -81,7 +84,7 @@ static TELEMETRY: Lazy<()> = Lazy::new(|| { fn sequence_action() -> SequenceAction { SequenceAction { rollup_id: RollupId::new([0; ROLLUP_ID_LEN]), - data: vec![], + data: Bytes::new(), fee_asset: "nria".parse().unwrap(), } } @@ -411,7 +414,7 @@ async fn bundle_triggered_by_block_timer() { // send two sequence actions to the executor, both small enough to fit in a single bundle // without filling it let seq0 = SequenceAction { - data: vec![0u8; cfg.max_bytes_per_bundle / 4], + data: vec![0u8; cfg.max_bytes_per_bundle / 4].into(), ..sequence_action() }; @@ -498,13 +501,13 @@ async fn two_seq_actions_single_bundle() { // send two sequence actions to the executor, both small enough to fit in a single bundle // without filling it let seq0 = SequenceAction { - data: vec![0u8; cfg.max_bytes_per_bundle / 4], + data: vec![0u8; cfg.max_bytes_per_bundle / 4].into(), ..sequence_action() }; let seq1 = SequenceAction { rollup_id: RollupId::new([1; ROLLUP_ID_LEN]), - data: vec![1u8; cfg.max_bytes_per_bundle / 4], + data: vec![1u8; cfg.max_bytes_per_bundle / 4].into(), ..sequence_action() }; diff --git a/crates/astria-composer/src/test_utils.rs b/crates/astria-composer/src/test_utils.rs index 830e61b348..0759b81666 100644 --- a/crates/astria-composer/src/test_utils.rs +++ b/crates/astria-composer/src/test_utils.rs @@ -16,7 +16,7 @@ fn encoded_len(action: &SequenceAction) -> usize { pub(crate) fn sequence_action_with_n_bytes(n: usize) -> SequenceAction { SequenceAction { rollup_id: RollupId::new([0; ROLLUP_ID_LEN]), - data: vec![0; n], + data: vec![0; n].into(), fee_asset: "nria" .parse::() .unwrap() diff --git a/crates/astria-composer/tests/blackbox/grpc_collector.rs b/crates/astria-composer/tests/blackbox/grpc_collector.rs index 2080c44635..e1ebfe70b3 100644 --- a/crates/astria-composer/tests/blackbox/grpc_collector.rs +++ b/crates/astria-composer/tests/blackbox/grpc_collector.rs @@ -11,6 +11,7 @@ use astria_core::{ primitive::v1::RollupId, }; use ethers::prelude::Transaction; +use prost::bytes::Bytes; use crate::helper::{ mount_broadcast_tx_sync_invalid_nonce_mock, @@ -45,8 +46,8 @@ async fn tx_from_one_rollup_is_received_by_sequencer() { .unwrap(); composer_client .submit_rollup_transaction(SubmitRollupTransactionRequest { - rollup_id: rollup_id.as_ref().to_vec(), - data: tx.rlp().to_vec(), + rollup_id: Bytes::copy_from_slice(rollup_id.as_ref()), + data: Bytes::copy_from_slice(&tx.rlp()), }) .await .expect("rollup transactions should have been submitted successfully to grpc collector"); @@ -107,8 +108,8 @@ async fn invalid_nonce_causes_resubmission_under_different_nonce() { .unwrap(); composer_client .submit_rollup_transaction(SubmitRollupTransactionRequest { - rollup_id: rollup_id.as_ref().to_vec(), - data: tx.rlp().to_vec(), + rollup_id: Bytes::copy_from_slice(rollup_id.as_ref()), + data: Bytes::copy_from_slice(&tx.rlp()), }) .await .expect("rollup transactions should have been submitted successfully to grpc collector"); @@ -162,8 +163,8 @@ async fn single_rollup_tx_payload_integrity() { .unwrap(); composer_client .submit_rollup_transaction(SubmitRollupTransactionRequest { - rollup_id: rollup_id.as_ref().to_vec(), - data: tx.rlp().to_vec(), + rollup_id: Bytes::copy_from_slice(rollup_id.as_ref()), + data: Bytes::copy_from_slice(&tx.rlp()), }) .await .expect("rollup transactions should have been submitted successfully to grpc collector"); diff --git a/crates/astria-conductor/src/celestia/block_verifier.rs b/crates/astria-conductor/src/celestia/block_verifier.rs index b68178846a..565f284320 100644 --- a/crates/astria-conductor/src/celestia/block_verifier.rs +++ b/crates/astria-conductor/src/celestia/block_verifier.rs @@ -228,6 +228,7 @@ mod test { celestia::UncheckedSubmittedMetadata, }, }; + use bytes::Bytes; use prost::Message as _; use sequencer_client::{ tendermint::{ @@ -337,9 +338,9 @@ mod test { 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(), + data_hash: Bytes::copy_from_slice(&data_hash), + rollup_transactions_root: Bytes::copy_from_slice(&rollup_transactions_root), + proposer_address: Bytes::copy_from_slice(proposer_address.as_bytes()), }; let header = SequencerBlockHeader::try_from_raw(header).unwrap(); @@ -359,7 +360,7 @@ mod test { #[tokio::test] async fn validate_sequencer_blob_with_chain_ids() { - let test_tx = b"test-tx".to_vec(); + let test_tx = Bytes::from_static(b"test-tx"); let rollup_id = RollupId::from_unhashed_bytes(b"test-chain"); let grouped_txs = BTreeMap::from([(rollup_id, vec![test_tx.clone()])]); let rollup_transactions_tree = @@ -382,9 +383,9 @@ mod test { 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(), + data_hash: Bytes::copy_from_slice(&data_hash), + rollup_transactions_root: Bytes::copy_from_slice(&rollup_transactions_root), + proposer_address: Bytes::copy_from_slice(proposer_address.as_bytes()), }; let header = SequencerBlockHeader::try_from_raw(header).unwrap(); diff --git a/crates/astria-conductor/src/celestia/mod.rs b/crates/astria-conductor/src/celestia/mod.rs index 96e57eea20..7c209802e6 100644 --- a/crates/astria-conductor/src/celestia/mod.rs +++ b/crates/astria-conductor/src/celestia/mod.rs @@ -13,6 +13,7 @@ use astria_eyre::eyre::{ bail, WrapErr as _, }; +use bytes::Bytes; use celestia_types::nmt::Namespace; use futures::{ future::{ @@ -101,7 +102,7 @@ pub(crate) struct ReconstructedBlock { pub(crate) celestia_height: u64, pub(crate) block_hash: [u8; 32], pub(crate) header: SequencerBlockHeader, - pub(crate) transactions: Vec>, + pub(crate) transactions: Vec, } impl ReconstructedBlock { diff --git a/crates/astria-conductor/src/executor/client.rs b/crates/astria-conductor/src/executor/client.rs index 8704ee0767..46d784b4a2 100644 --- a/crates/astria-conductor/src/executor/client.rs +++ b/crates/astria-conductor/src/executor/client.rs @@ -117,14 +117,14 @@ impl Client { pub(super) async fn execute_block_with_retry( &mut self, prev_block_hash: Bytes, - transactions: Vec>, + transactions: Vec, timestamp: Timestamp, ) -> eyre::Result { use prost::Message; let transactions = transactions .into_iter() - .map(|tx| RollupData::decode(tx.as_slice())) + .map(RollupData::decode) .collect::>() .wrap_err("failed to decode tx bytes as RollupData")?; diff --git a/crates/astria-conductor/src/executor/mod.rs b/crates/astria-conductor/src/executor/mod.rs index 2d55ce1fd7..2ef56213d9 100644 --- a/crates/astria-conductor/src/executor/mod.rs +++ b/crates/astria-conductor/src/executor/mod.rs @@ -686,7 +686,7 @@ struct ExecutableBlock { hash: [u8; 32], height: SequencerHeight, timestamp: pbjson_types::Timestamp, - transactions: Vec>, + transactions: Vec, } impl ExecutableBlock { diff --git a/crates/astria-core/src/generated/astria.composer.v1alpha1.rs b/crates/astria-core/src/generated/astria.composer.v1alpha1.rs index 7092b8fa51..3a50686cc8 100644 --- a/crates/astria-core/src/generated/astria.composer.v1alpha1.rs +++ b/crates/astria-core/src/generated/astria.composer.v1alpha1.rs @@ -4,11 +4,11 @@ #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubmitRollupTransactionRequest { /// the unhashed rollup id - #[prost(bytes = "vec", tag = "1")] - pub rollup_id: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub rollup_id: ::prost::bytes::Bytes, /// the raw data bytes of the rollup transaction - #[prost(bytes = "vec", tag = "2")] - pub data: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "2")] + pub data: ::prost::bytes::Bytes, } impl ::prost::Name for SubmitRollupTransactionRequest { const NAME: &'static str = "SubmitRollupTransactionRequest"; diff --git a/crates/astria-core/src/generated/astria.execution.v1alpha1.rs b/crates/astria-core/src/generated/astria.execution.v1alpha1.rs index bc1a406985..d9cd0169ad 100644 --- a/crates/astria-core/src/generated/astria.execution.v1alpha1.rs +++ b/crates/astria-core/src/generated/astria.execution.v1alpha1.rs @@ -1,10 +1,10 @@ #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DoBlockRequest { - #[prost(bytes = "vec", tag = "1")] - pub prev_block_hash: ::prost::alloc::vec::Vec, - #[prost(bytes = "vec", repeated, tag = "2")] - pub transactions: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, + #[prost(bytes = "bytes", tag = "1")] + pub prev_block_hash: ::prost::bytes::Bytes, + #[prost(bytes = "bytes", repeated, tag = "2")] + pub transactions: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>, #[prost(message, optional, tag = "3")] pub timestamp: ::core::option::Option<::pbjson_types::Timestamp>, } @@ -18,8 +18,8 @@ impl ::prost::Name for DoBlockRequest { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DoBlockResponse { - #[prost(bytes = "vec", tag = "1")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub block_hash: ::prost::bytes::Bytes, } impl ::prost::Name for DoBlockResponse { const NAME: &'static str = "DoBlockResponse"; @@ -31,8 +31,8 @@ impl ::prost::Name for DoBlockResponse { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct FinalizeBlockRequest { - #[prost(bytes = "vec", tag = "1")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub block_hash: ::prost::bytes::Bytes, } impl ::prost::Name for FinalizeBlockRequest { const NAME: &'static str = "FinalizeBlockRequest"; @@ -64,8 +64,8 @@ impl ::prost::Name for InitStateRequest { #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct InitStateResponse { - #[prost(bytes = "vec", tag = "1")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub block_hash: ::prost::bytes::Bytes, } impl ::prost::Name for InitStateResponse { const NAME: &'static str = "InitStateResponse"; diff --git a/crates/astria-core/src/generated/astria.protocol.bridge.v1alpha1.rs b/crates/astria-core/src/generated/astria.protocol.bridge.v1alpha1.rs index 642d4485eb..64f7511f83 100644 --- a/crates/astria-core/src/generated/astria.protocol.bridge.v1alpha1.rs +++ b/crates/astria-core/src/generated/astria.protocol.bridge.v1alpha1.rs @@ -6,8 +6,8 @@ pub struct BridgeAccountLastTxHashResponse { #[prost(uint64, tag = "2")] pub height: u64, - #[prost(bytes = "vec", optional, tag = "3")] - pub tx_hash: ::core::option::Option<::prost::alloc::vec::Vec>, + #[prost(bytes = "bytes", optional, tag = "3")] + pub tx_hash: ::core::option::Option<::prost::bytes::Bytes>, } impl ::prost::Name for BridgeAccountLastTxHashResponse { const NAME: &'static str = "BridgeAccountLastTxHashResponse"; diff --git a/crates/astria-core/src/generated/astria.protocol.transactions.v1alpha1.rs b/crates/astria-core/src/generated/astria.protocol.transactions.v1alpha1.rs index f9ad97a170..56ecdd511b 100644 --- a/crates/astria-core/src/generated/astria.protocol.transactions.v1alpha1.rs +++ b/crates/astria-core/src/generated/astria.protocol.transactions.v1alpha1.rs @@ -5,10 +5,10 @@ #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SignedTransaction { - #[prost(bytes = "vec", tag = "1")] - pub signature: ::prost::alloc::vec::Vec, - #[prost(bytes = "vec", tag = "2")] - pub public_key: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub signature: ::prost::bytes::Bytes, + #[prost(bytes = "bytes", tag = "2")] + pub public_key: ::prost::bytes::Bytes, #[prost(message, optional, tag = "3")] pub transaction: ::core::option::Option<::pbjson_types::Any>, } @@ -144,8 +144,8 @@ impl ::prost::Name for TransferAction { pub struct SequenceAction { #[prost(message, optional, tag = "1")] pub rollup_id: ::core::option::Option, - #[prost(bytes = "vec", tag = "2")] - pub data: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "2")] + pub data: ::prost::bytes::Bytes, /// the asset used to pay the transaction fee #[prost(string, tag = "3")] pub fee_asset: ::prost::alloc::string::String, diff --git a/crates/astria-core/src/generated/astria.sequencerblock.v1alpha1.rs b/crates/astria-core/src/generated/astria.sequencerblock.v1alpha1.rs index eac5b68d69..725abeac05 100644 --- a/crates/astria-core/src/generated/astria.sequencerblock.v1alpha1.rs +++ b/crates/astria-core/src/generated/astria.sequencerblock.v1alpha1.rs @@ -11,8 +11,8 @@ pub struct RollupTransactions { pub rollup_id: ::core::option::Option, /// The serialized bytes of the rollup data. /// Each entry is a protobuf-encoded `RollupData` message. - #[prost(bytes = "vec", repeated, tag = "2")] - pub transactions: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, + #[prost(bytes = "bytes", repeated, tag = "2")] + pub transactions: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>, /// The proof that these rollup transactions are included in sequencer block. /// `astria.sequencer.v1alpha.SequencerBlock.rollup_transactions_proof`. #[prost(message, optional, tag = "3")] @@ -57,8 +57,8 @@ pub struct SequencerBlock { #[prost(message, optional, tag = "4")] pub rollup_ids_proof: ::core::option::Option, /// / The block hash of the cometbft block that corresponds to this sequencer block. - #[prost(bytes = "vec", tag = "5")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "5")] + pub block_hash: ::prost::bytes::Bytes, } impl ::prost::Name for SequencerBlock { const NAME: &'static str = "SequencerBlock"; @@ -80,15 +80,15 @@ pub struct SequencerBlockHeader { #[prost(message, optional, tag = "3")] pub time: ::core::option::Option<::pbjson_types::Timestamp>, /// the data_hash of the sequencer block (merkle root of all transaction hashes) - #[prost(bytes = "vec", tag = "4")] - pub data_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "4")] + pub data_hash: ::prost::bytes::Bytes, /// the cometbft proposer address of the sequencer block - #[prost(bytes = "vec", tag = "5")] - pub proposer_address: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "5")] + pub proposer_address: ::prost::bytes::Bytes, /// The 32-byte merkle root of all the rollup transactions in the block, /// Corresponds to `MHT(astria.SequencerBlock.rollup_transactions)`, - #[prost(bytes = "vec", tag = "6")] - pub rollup_transactions_root: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "6")] + pub rollup_transactions_root: ::prost::bytes::Bytes, } impl ::prost::Name for SequencerBlockHeader { const NAME: &'static str = "SequencerBlockHeader"; @@ -140,8 +140,8 @@ impl ::prost::Name for Deposit { #[derive(Clone, PartialEq, ::prost::Message)] pub struct FilteredSequencerBlock { /// / The block hash of the cometbft block that corresponds to this sequencer block. - #[prost(bytes = "vec", tag = "1")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub block_hash: ::prost::bytes::Bytes, /// the block header, which contains sequencer-specific commitments. #[prost(message, optional, tag = "2")] pub header: ::core::option::Option, @@ -162,8 +162,8 @@ pub struct FilteredSequencerBlock { /// and is extracted from `astria.SequencerBlock.rollup_transactions`. /// Note that these are all the rollup IDs in the sequencer block, not merely those in /// `rollup_transactions` field. This is necessary to prove that no rollup IDs were omitted. - #[prost(bytes = "vec", repeated, tag = "5")] - pub all_rollup_ids: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, + #[prost(bytes = "bytes", repeated, tag = "5")] + pub all_rollup_ids: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>, /// The proof that the `rollup_ids` are included /// in the CometBFT block this sequencer block is derived form. /// @@ -201,7 +201,7 @@ pub mod rollup_data { #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum Value { #[prost(bytes, tag = "1")] - SequencedData(::prost::alloc::vec::Vec), + SequencedData(::prost::bytes::Bytes), #[prost(message, tag = "2")] Deposit(super::Deposit), } @@ -241,15 +241,15 @@ impl ::prost::Name for SubmittedRollupDataList { #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubmittedRollupData { /// The hash of the sequencer block. Must be 32 bytes. - #[prost(bytes = "vec", tag = "1")] - pub sequencer_block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub sequencer_block_hash: ::prost::bytes::Bytes, /// The 32 bytes identifying the rollup this blob belongs to. Matches /// `astria.sequencer.v1.RollupTransactions.rollup_id` #[prost(message, optional, tag = "2")] pub rollup_id: ::core::option::Option, /// A list of opaque bytes that are serialized rollup transactions. - #[prost(bytes = "vec", repeated, tag = "3")] - pub transactions: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, + #[prost(bytes = "bytes", repeated, tag = "3")] + pub transactions: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>, /// The proof that these rollup transactions are included in sequencer block. /// `astria.sequencer.v1alpha.SequencerBlock.rollup_transactions_proof`. #[prost(message, optional, tag = "4")] @@ -290,8 +290,8 @@ impl ::prost::Name for SubmittedMetadataList { #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubmittedMetadata { /// the 32-byte block hash of the sequencer block. - #[prost(bytes = "vec", tag = "1")] - pub block_hash: ::prost::alloc::vec::Vec, + #[prost(bytes = "bytes", tag = "1")] + pub block_hash: ::prost::bytes::Bytes, /// the block header, which contains sequencer-specific commitments. #[prost(message, optional, tag = "2")] pub header: ::core::option::Option, diff --git a/crates/astria-core/src/primitive/v1/mod.rs b/crates/astria-core/src/primitive/v1/mod.rs index ba7b83762a..bf88007ec9 100644 --- a/crates/astria-core/src/primitive/v1/mod.rs +++ b/crates/astria-core/src/primitive/v1/mod.rs @@ -7,6 +7,7 @@ use base64::{ display::Base64Display, prelude::BASE64_STANDARD, }; +use bytes::Bytes; use sha2::{ Digest as _, Sha256, @@ -171,19 +172,6 @@ impl RollupId { Ok(Self::new(inner)) } - /// Converts a byte vector to a rollup ID. - /// - /// # Errors - /// - /// Returns an error if the byte slice was not 32 bytes long. - pub fn try_from_vec(bytes: Vec) -> Result { - let inner = - <[u8; ROLLUP_ID_LEN]>::try_from(bytes).map_err(|bytes| IncorrectRollupIdLength { - received: bytes.len(), - })?; - Ok(Self::new(inner)) - } - #[must_use] pub fn to_raw(&self) -> raw::RollupId { raw::RollupId { @@ -490,7 +478,7 @@ impl std::fmt::Display for Address { pub fn derive_merkle_tree_from_rollup_txs<'a, T, U>(rollup_ids_to_txs: T) -> merkle::Tree where T: IntoIterator, - U: AsRef<[Vec]> + 'a + ?Sized, + U: AsRef<[Bytes]> + 'a + ?Sized, { let mut tree = merkle::Tree::new(); for (rollup_id, txs) in rollup_ids_to_txs { diff --git a/crates/astria-core/src/protocol/bridge/v1alpha1/mod.rs b/crates/astria-core/src/protocol/bridge/v1alpha1/mod.rs index 8fbcd562c0..651a8f3a8c 100644 --- a/crates/astria-core/src/protocol/bridge/v1alpha1/mod.rs +++ b/crates/astria-core/src/protocol/bridge/v1alpha1/mod.rs @@ -1,3 +1,5 @@ +use bytes::Bytes; + use super::raw; use crate::primitive::v1::{ asset, @@ -28,11 +30,12 @@ impl BridgeAccountLastTxHashResponse { height: raw.height, tx_hash: raw .tx_hash - .map(TryInto::<[u8; 32]>::try_into) - .transpose() - .map_err(|bytes: Vec| { - BridgeAccountLastTxHashResponseError::invalid_tx_hash(bytes.len()) - })?, + .map(|bytes| { + <[u8; 32]>::try_from(bytes.as_ref()).map_err(|_| { + BridgeAccountLastTxHashResponseError::invalid_tx_hash(bytes.len()) + }) + }) + .transpose()?, }) } @@ -40,7 +43,7 @@ impl BridgeAccountLastTxHashResponse { pub fn into_raw(self) -> raw::BridgeAccountLastTxHashResponse { raw::BridgeAccountLastTxHashResponse { height: self.height, - tx_hash: self.tx_hash.map(Into::into), + tx_hash: self.tx_hash.map(|tx_hash| Bytes::copy_from_slice(&tx_hash)), } } } diff --git a/crates/astria-core/src/protocol/mod.rs b/crates/astria-core/src/protocol/mod.rs index e7fea6cbbd..2d30299b22 100644 --- a/crates/astria-core/src/protocol/mod.rs +++ b/crates/astria-core/src/protocol/mod.rs @@ -1,3 +1,4 @@ +use bytes::Bytes; use indexmap::IndexMap; use transaction::v1alpha1::SignedTransaction; @@ -19,7 +20,7 @@ pub mod test_utils; /// TODO: This can all be done in-place once is stabilized. pub fn group_sequence_actions_in_signed_transaction_transactions_by_rollup_id( signed_transactions: &[SignedTransaction], -) -> IndexMap>> { +) -> IndexMap> { use prost::Message as _; use crate::sequencerblock::v1alpha1::block::RollupData; @@ -30,9 +31,9 @@ pub fn group_sequence_actions_in_signed_transaction_transactions_by_rollup_id( .flat_map(SignedTransaction::actions) { if let Some(action) = action.as_sequence() { - let txs_for_rollup: &mut Vec> = map.entry(action.rollup_id).or_insert(vec![]); + let txs_for_rollup: &mut Vec = map.entry(action.rollup_id).or_insert(vec![]); let rollup_data = RollupData::SequencedData(action.data.clone()); - txs_for_rollup.push(rollup_data.into_raw().encode_to_vec()); + txs_for_rollup.push(rollup_data.into_raw().encode_to_vec().into()); } } map.sort_unstable_keys(); diff --git a/crates/astria-core/src/protocol/test_utils.rs b/crates/astria-core/src/protocol/test_utils.rs index ff7f325fd1..1f399a4227 100644 --- a/crates/astria-core/src/protocol/test_utils.rs +++ b/crates/astria-core/src/protocol/test_utils.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; +use bytes::Bytes; use prost::Message as _; use super::{ @@ -94,7 +95,7 @@ impl ConfigureSequencerBlock { .map(|(rollup_id, data)| { SequenceAction { rollup_id, - data, + data: data.into(), fee_asset: "nria".parse().unwrap(), } .into() @@ -132,6 +133,7 @@ impl ConfigureSequencerBlock { RollupData::Deposit(Box::new(deposit)) .into_raw() .encode_to_vec() + .into() })); } rollup_transactions.sort_unstable_keys(); @@ -148,7 +150,7 @@ impl ConfigureSequencerBlock { rollup_ids_root.to_vec(), ]; data.extend(txs.into_iter().map(|tx| tx.into_raw().encode_to_vec())); - + let data = data.into_iter().map(Bytes::from).collect(); SequencerBlock::try_from_block_info_and_data( block_hash, chain_id.try_into().unwrap(), diff --git a/crates/astria-core/src/protocol/transaction/v1alpha1/action.rs b/crates/astria-core/src/protocol/transaction/v1alpha1/action.rs index da22b1039e..3ba5c03050 100644 --- a/crates/astria-core/src/protocol/transaction/v1alpha1/action.rs +++ b/crates/astria-core/src/protocol/transaction/v1alpha1/action.rs @@ -1,3 +1,4 @@ +use bytes::Bytes; use ibc_types::{ core::{ channel::ChannelId, @@ -379,7 +380,7 @@ enum SequenceActionErrorKind { #[allow(clippy::module_name_repetitions)] pub struct SequenceAction { pub rollup_id: RollupId, - pub data: Vec, + pub data: Bytes, /// asset to use for fee payment. pub fee_asset: asset::Denom, } diff --git a/crates/astria-core/src/protocol/transaction/v1alpha1/mod.rs b/crates/astria-core/src/protocol/transaction/v1alpha1/mod.rs index d5e8543001..c7569452f8 100644 --- a/crates/astria-core/src/protocol/transaction/v1alpha1/mod.rs +++ b/crates/astria-core/src/protocol/transaction/v1alpha1/mod.rs @@ -1,3 +1,4 @@ +use bytes::Bytes; use prost::{ Message as _, Name as _, @@ -110,8 +111,8 @@ impl SignedTransaction { .. } = self; raw::SignedTransaction { - signature: signature.to_bytes().to_vec(), - public_key: verification_key.to_bytes().to_vec(), + signature: Bytes::copy_from_slice(&signature.to_bytes()), + public_key: Bytes::copy_from_slice(&verification_key.to_bytes()), transaction: Some(pbjson_types::Any { type_url: raw::UnsignedTransaction::type_url(), value: transaction_bytes, @@ -128,8 +129,8 @@ impl SignedTransaction { .. } = self; raw::SignedTransaction { - signature: signature.to_bytes().to_vec(), - public_key: verification_key.to_bytes().to_vec(), + signature: Bytes::copy_from_slice(&signature.to_bytes()), + public_key: Bytes::copy_from_slice(&verification_key.to_bytes()), transaction: Some(pbjson_types::Any { type_url: raw::UnsignedTransaction::type_url(), value: transaction_bytes.clone(), diff --git a/crates/astria-core/src/sequencerblock/v1alpha1/block.rs b/crates/astria-core/src/sequencerblock/v1alpha1/block.rs index 8653961f16..5777814336 100644 --- a/crates/astria-core/src/sequencerblock/v1alpha1/block.rs +++ b/crates/astria-core/src/sequencerblock/v1alpha1/block.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use bytes::Bytes; use indexmap::IndexMap; use sha2::Sha256; use tendermint::{ @@ -68,7 +69,7 @@ enum RollupTransactionsErrorKind { #[derive(Clone, Debug, PartialEq)] pub struct RollupTransactionsParts { pub rollup_id: RollupId, - pub transactions: Vec>, + pub transactions: Vec, pub proof: merkle::Proof, } @@ -78,7 +79,7 @@ pub struct RollupTransactions { /// The 32 bytes identifying a rollup. Usually the sha256 hash of a plain rollup name. rollup_id: RollupId, /// The block data for this rollup in the form of encoded [`RollupData`]. - transactions: Vec>, + transactions: Vec, /// Proof that this set of transactions belongs in the rollup datas merkle tree proof: merkle::Proof, } @@ -92,7 +93,7 @@ impl RollupTransactions { /// Returns the block data for this rollup. #[must_use] - pub fn transactions(&self) -> &[Vec] { + pub fn transactions(&self) -> &[Bytes] { &self.transactions } @@ -112,6 +113,7 @@ impl RollupTransactions { transactions, proof, } = self; + let transactions = transactions.into_iter().map(Into::into).collect(); raw::RollupTransactions { rollup_id: Some(rollup_id.into_raw()), transactions, @@ -140,6 +142,7 @@ impl RollupTransactions { }; merkle::Proof::try_from_raw(proof).map_err(RollupTransactionsError::proof_invalid) }?; + let transactions = transactions.into_iter().map(Into::into).collect(); Ok(Self { rollup_id, transactions, @@ -408,9 +411,9 @@ impl SequencerBlockHeader { seconds: time.seconds, nanos: time.nanos, }), - rollup_transactions_root: self.rollup_transactions_root.to_vec(), - data_hash: self.data_hash.to_vec(), - proposer_address: self.proposer_address.as_bytes().to_vec(), + rollup_transactions_root: Bytes::copy_from_slice(&self.rollup_transactions_root), + data_hash: Bytes::copy_from_slice(&self.data_hash), + proposer_address: Bytes::copy_from_slice(self.proposer_address.as_bytes()), } } @@ -448,12 +451,14 @@ impl SequencerBlockHeader { .map_err(SequencerBlockHeaderError::time)?; let rollup_transactions_root = - rollup_transactions_root.try_into().map_err(|e: Vec<_>| { - SequencerBlockHeaderError::incorrect_rollup_transactions_root_length(e.len()) + rollup_transactions_root.as_ref().try_into().map_err(|_| { + SequencerBlockHeaderError::incorrect_rollup_transactions_root_length( + rollup_transactions_root.len(), + ) })?; - let data_hash = data_hash.try_into().map_err(|e: Vec<_>| { - SequencerBlockHeaderError::incorrect_rollup_transactions_root_length(e.len()) + let data_hash = data_hash.as_ref().try_into().map_err(|_| { + SequencerBlockHeaderError::incorrect_rollup_transactions_root_length(data_hash.len()) })?; let proposer_address = account::Id::try_from(proposer_address) @@ -621,7 +626,7 @@ impl SequencerBlock { rollup_ids_proof, } = self; raw::SequencerBlock { - block_hash: block_hash.to_vec(), + block_hash: Bytes::copy_from_slice(&block_hash), header: Some(header.into_raw()), rollup_transactions: rollup_transactions .into_values() @@ -698,13 +703,14 @@ impl SequencerBlock { /// # Panics /// /// - if a rollup data merkle proof cannot be constructed. + #[allow(clippy::too_many_lines)] // Temporary fix, should refactor: TODO(https://github.com/astriaorg/astria/issues/1357) pub fn try_from_block_info_and_data( block_hash: [u8; 32], chain_id: tendermint::chain::Id, height: tendermint::block::Height, time: Time, proposer_address: account::Id, - data: Vec>, + data: Vec, deposits: HashMap>, ) -> Result { use prost::Message as _; @@ -716,16 +722,18 @@ impl SequencerBlock { let rollup_transactions_root: [u8; 32] = data_list .next() .ok_or(SequencerBlockError::no_rollup_transactions_root())? + .as_ref() .try_into() - .map_err(|e: Vec<_>| { - SequencerBlockError::incorrect_rollup_transactions_root_length(e.len()) + .map_err(|_| { + SequencerBlockError::incorrect_rollup_transactions_root_length(data_list.len()) })?; let rollup_ids_root: [u8; 32] = data_list .next() .ok_or(SequencerBlockError::no_rollup_ids_root())? + .as_ref() .try_into() - .map_err(|e: Vec<_>| SequencerBlockError::incorrect_rollup_ids_root_length(e.len()))?; + .map_err(|_| SequencerBlockError::incorrect_rollup_ids_root_length(data_list.len()))?; let mut rollup_datas = IndexMap::new(); for elem in data_list { @@ -745,7 +753,10 @@ impl SequencerBlock { }) = action { let elem = rollup_datas.entry(rollup_id).or_insert(vec![]); - let data = RollupData::SequencedData(data).into_raw().encode_to_vec(); + let data = RollupData::SequencedData(data) + .into_raw() + .encode_to_vec() + .into(); elem.push(data); } } @@ -758,6 +769,7 @@ impl SequencerBlock { RollupData::Deposit(Box::new(deposit)) .into_raw() .encode_to_vec() + .into() })); } @@ -844,8 +856,9 @@ impl SequencerBlock { } = raw; let block_hash = block_hash + .as_ref() .try_into() - .map_err(|e: Vec<_>| SequencerBlockError::invalid_block_hash(e.len()))?; + .map_err(|_| SequencerBlockError::invalid_block_hash(block_hash.len()))?; let rollup_transactions_proof = 'proof: { let Some(rollup_transactions_proof) = rollup_transactions_proof else { @@ -1009,14 +1022,18 @@ impl FilteredSequencerBlock { .. } = self; raw::FilteredSequencerBlock { - block_hash: block_hash.to_vec(), + block_hash: Bytes::copy_from_slice(&block_hash), header: Some(header.into_raw()), rollup_transactions: rollup_transactions .into_values() .map(RollupTransactions::into_raw) .collect(), rollup_transactions_proof: Some(rollup_transactions_proof.into_raw()), - all_rollup_ids: self.all_rollup_ids.iter().map(|id| id.to_vec()).collect(), + all_rollup_ids: self + .all_rollup_ids + .iter() + .map(|id| Bytes::copy_from_slice(id.as_ref())) + .collect(), rollup_ids_proof: Some(rollup_ids_proof.into_raw()), } } @@ -1061,8 +1078,9 @@ impl FilteredSequencerBlock { } = raw; let block_hash = block_hash + .as_ref() .try_into() - .map_err(|e: Vec<_>| FilteredSequencerBlockError::invalid_block_hash(e.len()))?; + .map_err(|_| FilteredSequencerBlockError::invalid_block_hash(block_hash.len()))?; let rollup_transactions_proof = { let Some(rollup_transactions_proof) = rollup_transactions_proof else { @@ -1100,7 +1118,7 @@ impl FilteredSequencerBlock { let all_rollup_ids: Vec = all_rollup_ids .into_iter() - .map(RollupId::try_from_vec) + .map(|bytes| RollupId::try_from_slice(&bytes)) .collect::>() .map_err(FilteredSequencerBlockError::invalid_rollup_id)?; @@ -1423,7 +1441,7 @@ enum DepositErrorKind { /// and must decode it accordingly. #[derive(Debug, Clone, PartialEq)] pub enum RollupData { - SequencedData(Vec), + SequencedData(Bytes), Deposit(Box), } diff --git a/crates/astria-core/src/sequencerblock/v1alpha1/celestia.rs b/crates/astria-core/src/sequencerblock/v1alpha1/celestia.rs index a1dfcf8d88..1646e9af3a 100644 --- a/crates/astria-core/src/sequencerblock/v1alpha1/celestia.rs +++ b/crates/astria-core/src/sequencerblock/v1alpha1/celestia.rs @@ -1,3 +1,4 @@ +use bytes::Bytes; use sha2::{ Digest as _, Sha256, @@ -51,6 +52,7 @@ impl PreparedBlock { proof, .. } = rollup_txs.into_parts(); + let transactions = transactions.into_iter().map(Bytes::into).collect(); tail.push(SubmittedRollupData { sequencer_block_hash: block_hash, rollup_id, @@ -138,7 +140,7 @@ pub struct UncheckedSubmittedRollupData { /// `astria.sequencerblock.v1alpha1.RollupTransactions.rollup_id` pub rollup_id: RollupId, /// A list of opaque bytes that are serialized rollup transactions. - pub transactions: Vec>, + pub transactions: Vec, /// The proof that these rollup transactions are included in sequencer block. pub proof: merkle::Proof, } @@ -159,7 +161,7 @@ pub struct SubmittedRollupData { /// `astria.sequencerblock.v1alpha1.RollupTransactions.rollup_id` rollup_id: RollupId, /// A list of opaque bytes that are serialized rollup transactions. - transactions: Vec>, + transactions: Vec, /// The proof that these rollup transactions are included in sequencer block. proof: merkle::Proof, } @@ -171,7 +173,7 @@ impl SubmittedRollupData { } #[must_use] - pub fn transactions(&self) -> &[Vec] { + pub fn transactions(&self) -> &[Bytes] { &self.transactions } @@ -235,7 +237,7 @@ impl SubmittedRollupData { proof, } = self; raw::SubmittedRollupData { - sequencer_block_hash: sequencer_block_hash.to_vec(), + sequencer_block_hash: Bytes::copy_from_slice(&sequencer_block_hash), rollup_id: Some(rollup_id.to_raw()), transactions, proof: Some(proof.into_raw()), @@ -258,8 +260,8 @@ impl SubmittedRollupData { }; let rollup_id = RollupId::try_from_raw(&rollup_id).map_err(SubmittedRollupDataError::rollup_id)?; - let sequencer_block_hash = sequencer_block_hash.try_into().map_err(|bytes: Vec| { - SubmittedRollupDataError::sequencer_block_hash(bytes.len()) + let sequencer_block_hash = sequencer_block_hash.as_ref().try_into().map_err(|_| { + SubmittedRollupDataError::sequencer_block_hash(sequencer_block_hash.len()) })?; let proof = 'proof: { let Some(proof) = proof else { @@ -458,8 +460,9 @@ impl UncheckedSubmittedMetadata { }?; let block_hash = block_hash + .as_ref() .try_into() - .map_err(|bytes: Vec<_>| SubmittedMetadataError::block_hash(bytes.len()))?; + .map_err(|_| SubmittedMetadataError::block_hash(block_hash.len()))?; Ok(Self { block_hash, @@ -618,7 +621,7 @@ impl SubmittedMetadata { .. } = self; raw::SubmittedMetadata { - block_hash: block_hash.to_vec(), + block_hash: Bytes::copy_from_slice(&block_hash), header: Some(header.into_raw()), rollup_ids: rollup_ids.into_iter().map(RollupId::into_raw).collect(), rollup_transactions_proof: Some(rollup_transactions_proof.into_raw()), diff --git a/crates/astria-sequencer-client/src/tests/http.rs b/crates/astria-sequencer-client/src/tests/http.rs index f3036c87cb..a7f40c365f 100644 --- a/crates/astria-sequencer-client/src/tests/http.rs +++ b/crates/astria-sequencer-client/src/tests/http.rs @@ -10,6 +10,7 @@ use astria_core::{ }, }; use hex_literal::hex; +use prost::bytes::Bytes; use serde_json::json; use tendermint::{ block::Height, @@ -295,7 +296,7 @@ async fn get_bridge_account_last_transaction_hash() { let expected_response = BridgeAccountLastTxHashResponse { height: 10, - tx_hash: Some([0; 32].to_vec()), + tx_hash: Some(Bytes::from_static(&[0; 32])), }; let _guard = register_abci_query_response( diff --git a/crates/astria-sequencer-relayer/tests/blackbox/helpers/mock_sequencer_server.rs b/crates/astria-sequencer-relayer/tests/blackbox/helpers/mock_sequencer_server.rs index a1cca888f5..3b7d7c25a3 100644 --- a/crates/astria-sequencer-relayer/tests/blackbox/helpers/mock_sequencer_server.rs +++ b/crates/astria-sequencer-relayer/tests/blackbox/helpers/mock_sequencer_server.rs @@ -160,7 +160,9 @@ fn prepare_sequencer_block_response( let mut block = block.into_raw(); if should_corrupt { let header = block.header.as_mut().unwrap(); - header.data_hash[0] = header.data_hash[0].wrapping_add(1); + let mut data_hash = header.data_hash.to_vec(); + data_hash[0] = data_hash[0].wrapping_add(1); + header.data_hash = data_hash.into(); } Mock::for_rpc_given( diff --git a/crates/astria-sequencer-utils/src/blob_parser.rs b/crates/astria-sequencer-utils/src/blob_parser.rs index a5fdb45118..828a9cefca 100644 --- a/crates/astria-sequencer-utils/src/blob_parser.rs +++ b/crates/astria-sequencer-utils/src/blob_parser.rs @@ -648,7 +648,7 @@ impl VerboseRollupData { let transactions_and_deposits: Vec<_> = rollup_data .transactions .iter() - .map(RollupDataDetails::from) + .map(|bytes| RollupDataDetails::from(&bytes.to_vec())) .collect(); let item_count = transactions_and_deposits.len(); VerboseRollupData { diff --git a/crates/astria-sequencer/src/api_state_ext.rs b/crates/astria-sequencer/src/api_state_ext.rs index 5fd26a8027..d21e7499dd 100644 --- a/crates/astria-sequencer/src/api_state_ext.rs +++ b/crates/astria-sequencer/src/api_state_ext.rs @@ -23,6 +23,7 @@ use borsh::{ BorshDeserialize, BorshSerialize, }; +use bytes::Bytes; use cnidarium::{ StateRead, StateWrite, @@ -242,7 +243,7 @@ pub(crate) trait StateReadExt: StateRead { .context("failed to decode rollup IDs proof from raw bytes")?; let raw = raw::SequencerBlock { - block_hash: hash.to_vec(), + block_hash: Bytes::copy_from_slice(hash), header: header_raw.into(), rollup_transactions, rollup_transactions_proof: rollup_transactions_proof.into(), diff --git a/crates/astria-sequencer/src/app/test_utils.rs b/crates/astria-sequencer/src/app/test_utils.rs index 6ef60fac9c..09b3571a0a 100644 --- a/crates/astria-sequencer/src/app/test_utils.rs +++ b/crates/astria-sequencer/src/app/test_utils.rs @@ -18,6 +18,7 @@ use astria_core::{ UncheckedGenesisState, }, }; +use bytes::Bytes; use cnidarium::Storage; use penumbra_ibc::params::IBCParameters; @@ -146,7 +147,7 @@ pub(crate) fn get_mock_tx(nonce: u32) -> SignedTransaction { actions: vec![ SequenceAction { rollup_id: RollupId::from_unhashed_bytes([0; 32]), - data: vec![0x99], + data: Bytes::from_static(&[0x99]), fee_asset: "astria".parse().unwrap(), } .into(), diff --git a/crates/astria-sequencer/src/app/tests_app.rs b/crates/astria-sequencer/src/app/tests_app.rs index 9389ca19e5..4e6b6dbfe6 100644 --- a/crates/astria-sequencer/src/app/tests_app.rs +++ b/crates/astria-sequencer/src/app/tests_app.rs @@ -18,7 +18,10 @@ use astria_core::{ sequencerblock::v1alpha1::block::Deposit, }; use cnidarium::StateDelta; -use prost::Message as _; +use prost::{ + bytes::Bytes, + Message as _, +}; use tendermint::{ abci::{ self, @@ -310,7 +313,7 @@ async fn app_create_sequencer_block_with_sequenced_data_and_deposits() { }; let sequence_action = SequenceAction { rollup_id, - data: b"hello world".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: nria().into(), }; let tx = UnsignedTransaction { @@ -360,7 +363,7 @@ async fn app_create_sequencer_block_with_sequenced_data_and_deposits() { for (_, rollup_data) in block.rollup_transactions() { for tx in rollup_data.transactions() { let rollup_data = - RollupData::try_from_raw(RawRollupData::decode(tx.as_slice()).unwrap()).unwrap(); + RollupData::try_from_raw(RawRollupData::decode(tx.as_ref()).unwrap()).unwrap(); if let RollupData::Deposit(deposit) = rollup_data { deposits.push(deposit); } @@ -400,7 +403,7 @@ async fn app_execution_results_match_proposal_vs_after_proposal() { }; let sequence_action = SequenceAction { rollup_id, - data: b"hello world".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: nria().into(), }; let tx = UnsignedTransaction { @@ -535,7 +538,7 @@ async fn app_prepare_proposal_cometbft_max_bytes_overflow_ok() { actions: vec![ SequenceAction { rollup_id: RollupId::from([1u8; 32]), - data: vec![1u8; 100_000], + data: Bytes::copy_from_slice(&[1u8; 100_000]), fee_asset: nria().into(), } .into(), @@ -550,7 +553,7 @@ async fn app_prepare_proposal_cometbft_max_bytes_overflow_ok() { actions: vec![ SequenceAction { rollup_id: RollupId::from([1u8; 32]), - data: vec![1u8; 100_000], + data: Bytes::copy_from_slice(&[1u8; 100_000]), fee_asset: nria().into(), } .into(), @@ -608,7 +611,7 @@ async fn app_prepare_proposal_sequencer_max_bytes_overflow_ok() { actions: vec![ SequenceAction { rollup_id: RollupId::from([1u8; 32]), - data: vec![1u8; 200_000], + data: Bytes::copy_from_slice(&[1u8; 200_000]), fee_asset: nria().into(), } .into(), @@ -623,7 +626,7 @@ async fn app_prepare_proposal_sequencer_max_bytes_overflow_ok() { actions: vec![ SequenceAction { rollup_id: RollupId::from([1u8; 32]), - data: vec![1u8; 100_000], + data: Bytes::copy_from_slice(&[1u8; 100_000]), fee_asset: nria().into(), } .into(), diff --git a/crates/astria-sequencer/src/app/tests_breaking_changes.rs b/crates/astria-sequencer/src/app/tests_breaking_changes.rs index a65eafc25a..e135b55f0b 100644 --- a/crates/astria-sequencer/src/app/tests_breaking_changes.rs +++ b/crates/astria-sequencer/src/app/tests_breaking_changes.rs @@ -39,7 +39,10 @@ use astria_core::{ }; use cnidarium::StateDelta; use penumbra_ibc::params::IBCParameters; -use prost::Message as _; +use prost::{ + bytes::Bytes, + Message as _, +}; use tendermint::{ abci, abci::types::CommitInfo, @@ -125,7 +128,7 @@ async fn app_finalize_block_snapshot() { }; let sequence_action = SequenceAction { rollup_id, - data: b"hello world".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: nria().into(), }; let tx = UnsignedTransaction { @@ -226,7 +229,7 @@ async fn app_execute_transaction_with_every_action_snapshot() { .into(), SequenceAction { rollup_id: RollupId::from_unhashed_bytes(b"testchainid"), - data: b"hello world".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: nria().into(), } .into(), diff --git a/crates/astria-sequencer/src/app/tests_execute_transaction.rs b/crates/astria-sequencer/src/app/tests_execute_transaction.rs index a41a60f82f..6a39904305 100644 --- a/crates/astria-sequencer/src/app/tests_execute_transaction.rs +++ b/crates/astria-sequencer/src/app/tests_execute_transaction.rs @@ -27,6 +27,7 @@ use astria_core::{ }, sequencerblock::v1alpha1::block::Deposit, }; +use bytes::Bytes; use cnidarium::StateDelta; use penumbra_ibc::params::IBCParameters; use tendermint::abci::EventAttributeIndexExt as _; @@ -252,7 +253,7 @@ async fn app_execute_transaction_sequence() { let alice = get_alice_signing_key(); let alice_address = astria_address(&alice.address_bytes()); - let data = b"hello world".to_vec(); + let data = Bytes::from_static(b"hello world"); let fee = calculate_fee_from_state(&data, &app.state).await.unwrap(); let tx = UnsignedTransaction { @@ -288,7 +289,7 @@ async fn app_execute_transaction_invalid_fee_asset() { let mut app = initialize_app(None, vec![]).await; let alice = get_alice_signing_key(); - let data = b"hello world".to_vec(); + let data = Bytes::from_static(b"hello world"); let tx = UnsignedTransaction { params: TransactionParams::builder() @@ -791,7 +792,7 @@ async fn app_execute_transaction_invalid_nonce() { let alice_address = astria_address(&alice.address_bytes()); // create tx with invalid nonce 1 - let data = b"hello world".to_vec(); + let data = Bytes::from_static(b"hello world"); let tx = UnsignedTransaction { params: TransactionParams::builder() .nonce(1) @@ -838,7 +839,7 @@ async fn app_execute_transaction_invalid_chain_id() { let alice_address = astria_address(&alice.address_bytes()); // create tx with invalid nonce 1 - let data = b"hello world".to_vec(); + let data = Bytes::from_static(b"hello world"); let tx = UnsignedTransaction { params: TransactionParams::builder() .nonce(0) @@ -890,7 +891,7 @@ async fn app_stateful_check_fails_insufficient_total_balance() { let keypair_address = astria_address(&keypair.verification_key().address_bytes()); // figure out needed fee for a single transfer - let data = b"hello world".to_vec(); + let data = Bytes::from_static(b"hello world"); let fee = calculate_fee_from_state(&data, &app.state.clone()) .await .unwrap(); diff --git a/crates/astria-sequencer/src/grpc/sequencer.rs b/crates/astria-sequencer/src/grpc/sequencer.rs index 97615c8444..edb37042a7 100644 --- a/crates/astria-sequencer/src/grpc/sequencer.rs +++ b/crates/astria-sequencer/src/grpc/sequencer.rs @@ -12,6 +12,7 @@ use astria_core::{ }, primitive::v1::RollupId, }; +use bytes::Bytes; use cnidarium::Storage; use tonic::{ Request, @@ -148,10 +149,13 @@ impl SequencerService for SequencerServer { rollup_transactions.push(rollup_data.into_raw()); } - let all_rollup_ids = all_rollup_ids.into_iter().map(RollupId::to_vec).collect(); + let all_rollup_ids = all_rollup_ids + .into_iter() + .map(|rollup_id| Bytes::copy_from_slice(rollup_id.as_ref())) + .collect(); let block = RawFilteredSequencerBlock { - block_hash: block_hash.to_vec(), + block_hash: Bytes::copy_from_slice(&block_hash), header: Some(header.into_raw()), rollup_transactions, rollup_transactions_proof: rollup_transactions_proof.into(), diff --git a/crates/astria-sequencer/src/mempool/benchmarks.rs b/crates/astria-sequencer/src/mempool/benchmarks.rs index 7c97d278c1..dacf377f00 100644 --- a/crates/astria-sequencer/src/mempool/benchmarks.rs +++ b/crates/astria-sequencer/src/mempool/benchmarks.rs @@ -25,6 +25,7 @@ use astria_core::{ UnsignedTransaction, }, }; +use bytes::Bytes; use sha2::{ Digest as _, Sha256, @@ -75,7 +76,7 @@ fn transactions() -> &'static Vec { .build(); let sequence_action = SequenceAction { rollup_id: RollupId::new([1; 32]), - data: vec![2; 1000], + data: Bytes::from_static(&[2; 1000]), fee_asset: Denom::IbcPrefixed(IbcPrefixed::new([3; 32])), }; UnsignedTransaction { diff --git a/crates/astria-sequencer/src/proposal/commitment.rs b/crates/astria-sequencer/src/proposal/commitment.rs index ed41a2aa9c..1578b47208 100644 --- a/crates/astria-sequencer/src/proposal/commitment.rs +++ b/crates/astria-sequencer/src/proposal/commitment.rs @@ -71,6 +71,7 @@ pub(crate) fn generate_rollup_datas_commitment( RollupData::Deposit(Box::new(deposit)) .into_raw() .encode_to_vec() + .into() })); } @@ -109,7 +110,7 @@ mod test { fn generate_rollup_datas_commitment_should_ignore_transfers() { let sequence_action = SequenceAction { rollup_id: RollupId::from_unhashed_bytes(b"testchainid"), - data: b"helloworld".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: crate::test_utils::nria().into(), }; let transfer_action = TransferAction { @@ -163,7 +164,7 @@ mod test { let sequence_action = SequenceAction { rollup_id: RollupId::from_unhashed_bytes(b"testchainid"), - data: b"helloworld".to_vec(), + data: b"helloworld".to_vec().into(), fee_asset: crate::test_utils::nria().into(), }; let transfer_action = TransferAction { diff --git a/crates/astria-sequencer/src/service/consensus.rs b/crates/astria-sequencer/src/service/consensus.rs index 682b9e2051..dd4f7bbed3 100644 --- a/crates/astria-sequencer/src/service/consensus.rs +++ b/crates/astria-sequencer/src/service/consensus.rs @@ -247,7 +247,7 @@ mod test { actions: vec![ SequenceAction { rollup_id: RollupId::from_unhashed_bytes(b"testchainid"), - data: b"helloworld".to_vec(), + data: Bytes::from_static(b"hello world"), fee_asset: crate::test_utils::nria().into(), } .into(), diff --git a/crates/astria-sequencer/src/transaction/checks.rs b/crates/astria-sequencer/src/transaction/checks.rs index 5e0e31ea65..77aad88236 100644 --- a/crates/astria-sequencer/src/transaction/checks.rs +++ b/crates/astria-sequencer/src/transaction/checks.rs @@ -309,6 +309,7 @@ mod tests { TransactionParams, }, }; + use bytes::Bytes; use cnidarium::StateDelta; use super::*; @@ -345,7 +346,7 @@ mod tests { let alice = get_alice_signing_key(); let amount = 100; - let data = [0; 32].to_vec(); + let data = Bytes::from_static(&[0; 32]); let transfer_fee = state_tx.get_transfer_base_fee().await.unwrap(); state_tx .increase_balance( @@ -422,7 +423,7 @@ mod tests { let alice = get_alice_signing_key(); let amount = 100; - let data = [0; 32].to_vec(); + let data = Bytes::from_static(&[0; 32]); let transfer_fee = state_tx.get_transfer_base_fee().await.unwrap(); state_tx .increase_balance( diff --git a/tools/protobuf-compiler/src/main.rs b/tools/protobuf-compiler/src/main.rs index 1342abb6fe..20700a0d40 100644 --- a/tools/protobuf-compiler/src/main.rs +++ b/tools/protobuf-compiler/src/main.rs @@ -64,12 +64,10 @@ fn main() { .build_server(true) .emit_rerun_if_changed(false) .bytes([ - ".astria.execution.v1alpha2", - ".astria.primitive.v1", + ".astria", ".celestia", ".cosmos", ".tendermint", - ".astria.protocol.asset.v1alpha1.AllowedFeeAssetIdsResponse", ]) .client_mod_attribute(".", "#[cfg(feature=\"client\")]") .server_mod_attribute(".", "#[cfg(feature=\"server\")]")