Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ members = [
"crates/astria-sequencer",
"crates/astria-sequencer-client",
"crates/astria-sequencer-relayer",
"crates/astria-sequencer-types",
"crates/astria-sequencer-utils",
"crates/astria-telemetry",
"crates/astria-test-utils",
Expand Down
4 changes: 0 additions & 4 deletions crates/astria-composer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ package = "astria-sequencer-client"
path = "../astria-sequencer-client"
features = ["http"]

[dependencies.sequencer-types]
package = "astria-sequencer-types"
path = "../astria-sequencer-types"

[dev-dependencies]
config = { package = "astria-config", path = "../astria-config", features = [
"tests",
Expand Down
46 changes: 24 additions & 22 deletions crates/astria-composer/src/searcher/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
use astria_core::sequencer::v1alpha1::{
asset::default_native_asset_id,
transaction::Action,
AbciErrorCode,
SignedTransaction,
UnsignedTransaction,
};
Expand Down Expand Up @@ -42,7 +43,6 @@ use sequencer_client::{
Address,
SequencerClientExt as _,
};
use sequencer_types::abci_code::AbciCode;
use tokio::{
select,
sync::{
Expand Down Expand Up @@ -341,30 +341,32 @@ impl Future for SubmitFut {
SubmitStateProj::WaitingForSend {
fut,
} => match ready!(fut.poll(cx)) {
Ok(rsp) => match AbciCode::from_cometbft(rsp.code) {
Some(AbciCode::OK) => {
info!("sequencer responded with AbciCode zero; submission successful");
Ok(rsp) => {
let tendermint::abci::Code::Err(code) = rsp.code else {
info!("sequencer responded with ok; submission successful");
return Poll::Ready(Ok(*this.nonce + 1));
}
Some(AbciCode::INVALID_NONCE) => {
info!(
"sequencer responded with `invalid nonce` abci code; fetching new \
nonce"
);
SubmitState::WaitingForNonce {
fut: get_latest_nonce(this.client.clone(), *this.address).boxed(),
};
match AbciErrorCode::from(code) {
AbciErrorCode::INVALID_NONCE => {
info!(
"sequencer rejected transaction due to invalid nonce; \
fetching new nonce"
);
SubmitState::WaitingForNonce {
fut: get_latest_nonce(this.client.clone(), *this.address)
.boxed(),
}
}
_other => {
warn!(
abci.code = rsp.code.value(),
abci.log = rsp.log,
"sequencer rejected the transaction; the bundle is likely lost",
);
return Poll::Ready(Ok(*this.nonce));
}
}
_other => {
warn!(
abci.code = rsp.code.value(),
abci.log = rsp.log,
"sequencer responded with non-zero abci code; the bundle is \
likely lost",
);
return Poll::Ready(Ok(*this.nonce));
}
},
}
Err(e) => {
let error: &(dyn std::error::Error + 'static) = e.as_ref();
error!(error, "failed sending transaction to sequencer");
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-composer/tests/blackbox/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::time::Duration;
use astria_core::{
generated::sequencer::v1alpha1::NonceResponse,
sequencer::v1alpha1::{
AbciErrorCode,
RollupId,
SignedTransaction,
},
};
use ethers::types::Transaction;
use sequencer_types::AbciCode;
use tendermint_rpc::{
endpoint::broadcast::tx_sync,
request,
Expand Down Expand Up @@ -232,7 +232,7 @@ async fn mount_broadcast_tx_sync_invalid_nonce_mock(
let jsonrpc_rsp = response::Wrapper::new_with_id(
Id::Num(1),
Some(tx_sync::Response {
code: AbciCode::INVALID_NONCE.into(),
code: AbciErrorCode::INVALID_NONCE.into(),
data: vec![].into(),
log: String::new(),
hash: tendermint::Hash::Sha256([0; 32]),
Expand Down
1 change: 0 additions & 1 deletion crates/astria-conductor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ tryhard = { workspace = true }

astria-core = { path = "../astria-core", features = ["client"] }
celestia-client = { package = "astria-celestia-client", path = "../astria-celestia-client" }
sequencer-types = { package = "astria-sequencer-types", path = "../astria-sequencer-types" }
optimism = { package = "astria-optimism", path = "../astria-optimism" }
config = { package = "astria-config", path = "../astria-config" }
merkle = { package = "astria-merkle", path = "../astria-merkle" }
Expand Down
27 changes: 19 additions & 8 deletions crates/astria-conductor/src/data_availability/block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ mod test {

use super::*;

/// Constructs a `[merkle::Tree]` from an iterator yielding byte slices.
///
/// This hashes each item before pushing it into the Merkle Tree, which
/// effectively causes a double hashing. The leaf hash of an item `d_i`
/// is then `MTH(d_i) = SHA256(0x00 || SHA256(d_i))`.
fn merkle_tree_from_transactions<I, B>(iter: I) -> merkle::Tree
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no code changes here. Just moved this out of the sequencer-types crate as this was only used in conductor.

where
I: IntoIterator<Item = B>,
B: AsRef<[u8]>,
{
use sha2::{
Digest as _,
Sha256,
};
merkle::Tree::from_leaves(iter.into_iter().map(|item| Sha256::digest(&item)))
}

fn make_test_validator_set_and_commit(
height: u32,
chain_id: tendermint::chain::Id,
Expand Down Expand Up @@ -357,10 +374,7 @@ mod test {
let rollup_transactions_root = merkle::Tree::from_leaves([[1, 2, 3], [4, 5, 6]]).root();
let chain_ids_commitment = merkle::Tree::new().root();

let tree = sequencer_types::cometbft::merkle_tree_from_transactions([
rollup_transactions_root,
chain_ids_commitment,
]);
let tree = merkle_tree_from_transactions([rollup_transactions_root, chain_ids_commitment]);
let data_hash = tree.root();
let rollup_transactions_proof = tree.construct_proof(0).unwrap();
let rollup_ids_proof = tree.construct_proof(1).unwrap();
Expand Down Expand Up @@ -395,10 +409,7 @@ mod test {
let rollup_transactions_root = rollup_transactions_tree.root();
let rollup_ids_root = merkle::Tree::from_leaves(std::iter::once(rollup_id)).root();

let tree = sequencer_types::cometbft::merkle_tree_from_transactions([
rollup_transactions_root,
rollup_ids_root,
]);
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();
Expand Down
38 changes: 38 additions & 0 deletions crates/astria-core/src/generated/astria.sequencer.v1alpha1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum AbciErrorCode {
Unspecified = 0,
UnknownPath = 1,
InvalidParameter = 2,
InternalError = 3,
InvalidNonce = 4,
TransactionTooLarge = 5,
}
impl AbciErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
AbciErrorCode::Unspecified => "ABCI_ERROR_CODE_UNSPECIFIED",
AbciErrorCode::UnknownPath => "ABCI_ERROR_CODE_UNKNOWN_PATH",
AbciErrorCode::InvalidParameter => "ABCI_ERROR_CODE_INVALID_PARAMETER",
AbciErrorCode::InternalError => "ABCI_ERROR_CODE_INTERNAL_ERROR",
AbciErrorCode::InvalidNonce => "ABCI_ERROR_CODE_INVALID_NONCE",
AbciErrorCode::TransactionTooLarge => "ABCI_ERROR_CODE_TRANSACTION_TOO_LARGE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"ABCI_ERROR_CODE_UNSPECIFIED" => Some(Self::Unspecified),
"ABCI_ERROR_CODE_UNKNOWN_PATH" => Some(Self::UnknownPath),
"ABCI_ERROR_CODE_INVALID_PARAMETER" => Some(Self::InvalidParameter),
"ABCI_ERROR_CODE_INTERNAL_ERROR" => Some(Self::InternalError),
"ABCI_ERROR_CODE_INVALID_NONCE" => Some(Self::InvalidNonce),
"ABCI_ERROR_CODE_TRANSACTION_TOO_LARGE" => Some(Self::TransactionTooLarge),
_ => None,
}
}
}
/// A response containing the balance of an account.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
77 changes: 77 additions & 0 deletions crates/astria-core/src/sequencer/v1alpha1/abci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use std::{
borrow::Cow,
num::NonZeroU32,
};

use super::raw;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(clippy::module_name_repetitions)]
pub struct AbciErrorCode(u32);

#[rustfmt::skip]
impl AbciErrorCode {
pub const UNSPECIFIED: Self = Self(0);
pub const UNKNOWN_PATH: Self = Self(1);
pub const INVALID_PARAMETER: Self = Self(2);
pub const INTERNAL_ERROR: Self = Self(3);
pub const INVALID_NONCE: Self = Self(4);
pub const TRANSACTION_TOO_LARGE: Self = Self(5);
}

impl AbciErrorCode {
#[must_use]
pub fn info(self) -> Cow<'static, str> {
match self.0 {
0 => "unspecified".into(),
1 => "provided path is unknown".into(),
2 => "one or more path parameters were invalid".into(),
3 => "an internal server error occured".into(),
4 => "the provided nonce was invalid".into(),
5 => "the provided transaction was too large".into(),
other => format!("unknown non-zero abci error code: {other}").into(),
}
}

/// Converts from the rust representation of the abci error code.
///
/// Note that by convention unknown protobuf enum variants are mapped to
/// the default enum variant with value 0.
#[must_use]
pub fn from_raw(raw: raw::AbciErrorCode) -> Option<Self> {
let code = match raw {
raw::AbciErrorCode::Unspecified => Self::UNSPECIFIED,
raw::AbciErrorCode::UnknownPath => Self::UNKNOWN_PATH,
raw::AbciErrorCode::InvalidParameter => Self::INVALID_PARAMETER,
raw::AbciErrorCode::InternalError => Self::INTERNAL_ERROR,
raw::AbciErrorCode::InvalidNonce => Self::INVALID_NONCE,
raw::AbciErrorCode::TransactionTooLarge => Self::TRANSACTION_TOO_LARGE,
};
Some(code)
}
}

impl std::fmt::Display for AbciErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.info())
}
}

impl From<AbciErrorCode> for tendermint::abci::Code {
fn from(value: AbciErrorCode) -> Self {
value.0.into()
}
}

impl From<NonZeroU32> for AbciErrorCode {
fn from(value: NonZeroU32) -> Self {
match value.get() {
1 => Self::UNKNOWN_PATH,
2 => Self::INVALID_PARAMETER,
3 => Self::INTERNAL_ERROR,
4 => Self::INVALID_NONCE,
5 => Self::TRANSACTION_TOO_LARGE,
other => Self(other),
}
}
}
2 changes: 2 additions & 0 deletions crates/astria-core/src/sequencer/v1alpha1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
Protobuf,
};

pub mod abci;
pub mod account;
pub mod asset;
pub mod block;
Expand All @@ -18,6 +19,7 @@ pub mod celestia;
pub mod test_utils;
pub mod transaction;

pub use abci::AbciErrorCode;
pub use account::{
BalanceResponse,
NonceResponse,
Expand Down
18 changes: 0 additions & 18 deletions crates/astria-sequencer-types/Cargo.toml

This file was deleted.

Loading