Skip to content

Commit

Permalink
feat(sequencer)!: Add IBC sudo change action (#1509)
Browse files Browse the repository at this point in the history
## Summary
Added an action for changing the IBC sudo address.

## Background
IBC sudo address wasn't able to be changed before.

## Changes
- Added IBC sudo change action to proto, core, and sequencer.

## Testing
Added two new unit tests to ensure the new action works and errs as
expected.

## Breaking Changelist
- Added test of new action to
`app_execute_transaction_with_every_action_snapshot()`, breaking app
hash.

## Related Issues
closes #1480
  • Loading branch information
ethanoroshiba authored Sep 25, 2024
1 parent 4478cb6 commit e945677
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 31 deletions.

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

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

85 changes: 85 additions & 0 deletions crates/astria-core/src/protocol/transaction/v1alpha1/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum Action {
ValidatorUpdate(ValidatorUpdate),
SudoAddressChange(SudoAddressChangeAction),
Ibc(IbcRelay),
IbcSudoChange(IbcSudoChangeAction),
Ics20Withdrawal(Ics20Withdrawal),
IbcRelayerChange(IbcRelayerChangeAction),
FeeAssetChange(FeeAssetChangeAction),
Expand All @@ -60,6 +61,7 @@ impl Protobuf for Action {
Value::SudoAddressChangeAction(act.clone().into_raw())
}
Action::Ibc(act) => Value::IbcAction(act.clone().into()),
Action::IbcSudoChange(act) => Value::IbcSudoChangeAction(act.clone().into_raw()),
Action::Ics20Withdrawal(act) => Value::Ics20Withdrawal(act.to_raw()),
Action::IbcRelayerChange(act) => Value::IbcRelayerChangeAction(act.to_raw()),
Action::FeeAssetChange(act) => Value::FeeAssetChangeAction(act.to_raw()),
Expand Down Expand Up @@ -112,6 +114,9 @@ impl Protobuf for Action {
SudoAddressChangeAction::try_from_raw(act)
.map_err(ActionError::sudo_address_change)?,
),
Value::IbcSudoChangeAction(act) => Self::IbcSudoChange(
IbcSudoChangeAction::try_from_raw(act).map_err(ActionError::ibc_sudo_change)?,
),
Value::IbcAction(act) => {
Self::Ibc(IbcRelay::try_from(act).map_err(|e| ActionError::ibc(e.into()))?)
}
Expand Down Expand Up @@ -184,6 +189,12 @@ impl From<SudoAddressChangeAction> for Action {
}
}

impl From<IbcSudoChangeAction> for Action {
fn from(value: IbcSudoChangeAction) -> Self {
Self::IbcSudoChange(value)
}
}

impl From<IbcRelay> for Action {
fn from(value: IbcRelay) -> Self {
Self::Ibc(value)
Expand Down Expand Up @@ -278,6 +289,10 @@ impl ActionError {
Self(ActionErrorKind::SudoAddressChange(inner))
}

fn ibc_sudo_change(inner: IbcSudoChangeActionError) -> Self {
Self(ActionErrorKind::IbcSudoChange(inner))
}

fn ibc(inner: Box<dyn std::error::Error + Send + Sync>) -> Self {
Self(ActionErrorKind::Ibc(inner))
}
Expand Down Expand Up @@ -327,6 +342,8 @@ enum ActionErrorKind {
ValidatorUpdate(#[source] ValidatorUpdateError),
#[error("sudo address change action was not valid")]
SudoAddressChange(#[source] SudoAddressChangeActionError),
#[error("ibc sudo address change action was not valid")]
IbcSudoChange(#[source] IbcSudoChangeActionError),
#[error("ibc action was not valid")]
Ibc(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("ics20 withdrawal action was not valid")]
Expand Down Expand Up @@ -747,6 +764,74 @@ enum SudoAddressChangeActionErrorKind {
Address { source: AddressError },
}

#[derive(Debug, Clone)]
#[allow(clippy::module_name_repetitions)]
pub struct IbcSudoChangeAction {
pub new_address: Address,
}

impl Protobuf for IbcSudoChangeAction {
type Error = IbcSudoChangeActionError;
type Raw = raw::IbcSudoChangeAction;

fn into_raw(self) -> raw::IbcSudoChangeAction {
raw::IbcSudoChangeAction {
new_address: Some(self.new_address.into_raw()),
}
}

#[must_use]
fn to_raw(&self) -> raw::IbcSudoChangeAction {
raw::IbcSudoChangeAction {
new_address: Some(self.new_address.to_raw()),
}
}

/// Convert from a reference to a raw, unchecked protobuf [`raw::IbcSudoChangeAction`].
///
/// # Errors
///
/// Returns an error if the raw action's `new_address` did not have the expected
/// length or if the field was not set.
fn try_from_raw_ref(proto: &Self::Raw) -> Result<Self, IbcSudoChangeActionError> {
let raw::IbcSudoChangeAction {
new_address,
} = proto;
let Some(new_address) = new_address else {
return Err(IbcSudoChangeActionError::field_not_set("new_address"));
};
let new_address =
Address::try_from_raw(new_address).map_err(IbcSudoChangeActionError::address)?;
Ok(Self {
new_address,
})
}
}

#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct IbcSudoChangeActionError(IbcSudoChangeActionErrorKind);

impl IbcSudoChangeActionError {
fn field_not_set(field: &'static str) -> Self {
Self(IbcSudoChangeActionErrorKind::FieldNotSet(field))
}

fn address(source: AddressError) -> Self {
Self(IbcSudoChangeActionErrorKind::Address {
source,
})
}
}

#[derive(Debug, thiserror::Error)]
enum IbcSudoChangeActionErrorKind {
#[error("the expected field in the raw source type was not set: `{0}`")]
FieldNotSet(&'static str),
#[error("`new_sudo` field did not contain a valid address")]
Address { source: AddressError },
}

/// Represents an IBC withdrawal of an asset from a source chain to a destination chain.
///
/// The parameters match the arguments to the `sendFungibleTokens` function in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ expression: app.app_hash.as_bytes()
---
[
18,
206,
200,
101,
160,
129,
124,
188,
249,
181,
44,
218,
209,
251,
208,
119,
122,
211,
105,
201,
75,
118,
214,
56,
145,
239,
132,
48,
0,
79,
13,
53,
156
229,
224,
128,
108,
100,
143,
199,
228,
141,
70,
32,
39,
170,
128,
217,
96,
15,
242,
158,
56,
94,
214,
169,
160,
229,
120,
46,
163
]
Loading

0 comments on commit e945677

Please sign in to comment.