Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bridge-withdrawer): add ics20 withdrawal timeout duration option to withdrawer #1719

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion charts/evm-bridge-withdrawer/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: 1.0.0-rc.2
version: 1.0.0-rc.3

# 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
1 change: 1 addition & 0 deletions charts/evm-bridge-withdrawer/templates/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data:
{{- if not .Values.global.dev }}
{{- else }}
ASTRIA_BRIDGE_WITHDRAWER_USE_COMPAT_ADDRESS: "{{ .Values.config.useCompatAddress }}"
ASTRIA_BRIDGE_WITHDRAWER_ICS20_WITHDRAWAL_TIMEOUT_DURATION: "{{ .Values.config.ics20WithdrawalTimeoutDuration }}"
{{- end }}
---
{{- if not .Values.secretProvider.enabled }}
Expand Down
1 change: 1 addition & 0 deletions charts/evm-bridge-withdrawer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config:
sequencerChainId: ""
sequencerAddressPrefix: "astria"
sequencerBridgeAddress: ""
ics20WithdrawalTimeoutDuration: "300"
useCompatAddress: "false"
feeAssetDenom: ""
minExpectedFeeAssetBalance: "1000000"
Expand Down
6 changes: 3 additions & 3 deletions charts/evm-stack/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ dependencies:
version: 0.1.2
- name: evm-bridge-withdrawer
repository: file://../evm-bridge-withdrawer
version: 1.0.0-rc.2
version: 1.0.0-rc.3
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 15.2.4
- name: blockscout-stack
repository: https://blockscout.github.io/helm-charts
version: 1.6.2
digest: sha256:bbb5436bef71e57402482f74e2d2deabec5e4d957845bcb743b710ca49e2dc78
generated: "2024-10-22T10:51:25.483623794-04:00"
digest: sha256:420ca23dfb51268f78881086b018d875c72047a61bf1a82613cc4a92729f6580
generated: "2024-10-22T19:25:34.641345415-04:00"
4 changes: 2 additions & 2 deletions charts/evm-stack/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.7.2
version: 0.7.3

dependencies:
- name: celestia-node
Expand All @@ -34,7 +34,7 @@ dependencies:
repository: "file://../evm-faucet"
condition: evm-faucet.enabled
- name: evm-bridge-withdrawer
version: 1.0.0-rc.2
version: 1.0.0-rc.3
repository: "file://../evm-bridge-withdrawer"
condition: evm-bridge-withdrawer.enabled
- name: postgresql
Expand Down
35 changes: 30 additions & 5 deletions crates/astria-bridge-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod generated;
use std::{
borrow::Cow,
sync::Arc,
time::Duration,
};

use astria_core::{
Expand Down Expand Up @@ -37,6 +38,9 @@ use ethers::{
};
pub use generated::*;

// Default duration of the Ics20Withdrawal timeout from when it's created (5 minutes).
const DEFAULT_TIMEOUT_DURATION: Duration = Duration::from_secs(300);

#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct BuildError(BuildErrorKind);
Expand Down Expand Up @@ -120,6 +124,7 @@ pub struct GetWithdrawalActionsBuilder<TProvider = NoProvider> {
fee_asset: Option<asset::Denom>,
sequencer_asset_to_withdraw: Option<asset::Denom>,
ics20_asset_to_withdraw: Option<asset::TracePrefixed>,
timeout_duration: Option<Duration>,
use_compat_address: bool,
}

Expand All @@ -139,6 +144,7 @@ impl GetWithdrawalActionsBuilder {
fee_asset: None,
sequencer_asset_to_withdraw: None,
ics20_asset_to_withdraw: None,
timeout_duration: None,
use_compat_address: false,
}
}
Expand All @@ -153,6 +159,7 @@ impl<P> GetWithdrawalActionsBuilder<P> {
fee_asset,
sequencer_asset_to_withdraw,
ics20_asset_to_withdraw,
timeout_duration,
use_compat_address,
..
} = self;
Expand All @@ -163,6 +170,7 @@ impl<P> GetWithdrawalActionsBuilder<P> {
fee_asset,
sequencer_asset_to_withdraw,
ics20_asset_to_withdraw,
timeout_duration,
use_compat_address,
}
}
Expand Down Expand Up @@ -223,6 +231,19 @@ impl<P> GetWithdrawalActionsBuilder<P> {
}
}

#[must_use]
pub fn timeout_duration(self, timeout_duration: Duration) -> Self {
self.set_timeout_duration(Some(timeout_duration))
}

#[must_use]
pub fn set_timeout_duration(self, timeout_duration: Option<Duration>) -> Self {
Self {
timeout_duration,
..self
}
}

#[must_use]
pub fn use_compat_address(self, use_compat_address: bool) -> Self {
Self {
Expand Down Expand Up @@ -258,6 +279,7 @@ where
fee_asset,
sequencer_asset_to_withdraw,
ics20_asset_to_withdraw,
timeout_duration,
use_compat_address,
} = self;

Expand Down Expand Up @@ -301,6 +323,8 @@ where

let asset_withdrawal_divisor = 10u128.pow(exponent);

let timeout_duration = timeout_duration.unwrap_or(DEFAULT_TIMEOUT_DURATION);

Ok(GetWithdrawalActions {
provider,
contract_address,
Expand All @@ -310,6 +334,7 @@ where
sequencer_asset_to_withdraw,
ics20_asset_to_withdraw,
ics20_source_channel,
timeout_duration,
use_compat_address,
})
}
Expand All @@ -324,6 +349,7 @@ pub struct GetWithdrawalActions<P> {
sequencer_asset_to_withdraw: Option<asset::Denom>,
ics20_asset_to_withdraw: Option<asset::TracePrefixed>,
ics20_source_channel: Option<ibc_types::core::channel::ChannelId>,
timeout_duration: Duration,
use_compat_address: bool,
}

Expand Down Expand Up @@ -440,7 +466,7 @@ where
// note: this refers to the timeout on the destination chain, which we are unaware of.
// thus, we set it to the maximum possible value.
timeout_height: max_timeout_height(),
timeout_time: timeout_in_5_min(),
timeout_time: calculate_timeout(self.timeout_duration),
source_channel,
bridge_address: Some(self.bridge_address),
use_compat_address: self.use_compat_address,
Expand Down Expand Up @@ -676,11 +702,10 @@ fn parse_destination_chain_as_address(
event.destination_chain_address.parse().map_err(Into::into)
}

fn timeout_in_5_min() -> u64 {
use std::time::Duration;
fn calculate_timeout(duration: Duration) -> u64 {
tendermint::Time::now()
.checked_add(Duration::from_secs(300))
.expect("adding 5 minutes to the current time should never fail")
.checked_add(duration)
.expect("adding a duration to the current time should never fail")
.unix_timestamp_nanos()
.try_into()
.expect("timestamp must be positive, so this conversion would only fail if negative")
Expand Down
3 changes: 3 additions & 0 deletions crates/astria-bridge-withdrawer/local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ ASTRIA_BRIDGE_WITHDRAWER_ROLLUP_ASSET_DENOMINATION="nria"
# Should match the bridge address in the geth rollup's bridge configuration for that asset.
ASTRIA_BRIDGE_WITHDRAWER_SEQUENCER_BRIDGE_ADDRESS=""

# The timeout duration for `Ics20Withdrawal`s in seconds.
ASTRIA_BRIDGE_WITHDRAWER_ICS20_WITHDRAWAL_TIMEOUT_DURATION=300
Copy link
Contributor

Choose a reason for hiding this comment

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

Might make the units more visible if we named this ASTRIA_BRIDGE_WITHDRAWER_ICS20_WITHDRAWAL_TIMEOUT_SECONDS?


# Whether to use compat addresses for `Ics20Withdrawal`s.
ASTRIA_BRIDGE_WITHDRAWER_USE_COMPAT_ADDRESS=false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub(crate) struct Builder {
pub(crate) state: Arc<State>,
pub(crate) rollup_asset_denom: asset::TracePrefixed,
pub(crate) bridge_address: Address,
pub(crate) timeout_duration: Duration,
pub(crate) use_compat_address: bool,
pub(crate) submitter_handle: submitter::Handle,
}
Expand All @@ -75,6 +76,7 @@ impl Builder {
state,
rollup_asset_denom,
bridge_address,
timeout_duration,
use_compat_address,
submitter_handle,
} = self;
Expand All @@ -87,6 +89,7 @@ impl Builder {
ethereum_rpc_endpoint: ethereum_rpc_endpoint.to_string(),
rollup_asset_denom,
bridge_address,
timeout_duration,
use_compat_address,
state,
shutdown_token: shutdown_token.clone(),
Expand All @@ -105,6 +108,7 @@ pub(crate) struct Watcher {
ethereum_rpc_endpoint: String,
rollup_asset_denom: asset::TracePrefixed,
bridge_address: Address,
timeout_duration: Duration,
use_compat_address: bool,
state: Arc<State>,
}
Expand Down Expand Up @@ -149,6 +153,7 @@ impl Watcher {
ethereum_rpc_endpoint,
rollup_asset_denom,
bridge_address,
timeout_duration,
use_compat_address,
state,
} = self;
Expand Down Expand Up @@ -225,6 +230,7 @@ impl Watcher {
.bridge_address(bridge_address)
.sequencer_asset_to_withdraw(rollup_asset_denom.clone().into())
.set_ics20_asset_to_withdraw(ics20_asset_to_withdraw)
.timeout_duration(timeout_duration)
.use_compat_address(use_compat_address)
.try_build()
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl BridgeWithdrawer {
rollup_asset_denomination,
sequencer_bridge_address,
sequencer_grpc_endpoint,
ics20_withdrawal_timeout_duration,
use_compat_address,
..
} = cfg;
Expand Down Expand Up @@ -141,6 +142,7 @@ impl BridgeWithdrawer {
rollup_asset_denom: rollup_asset_denomination,
bridge_address: sequencer_bridge_address,
use_compat_address,
timeout_duration: Duration::from_secs(ics20_withdrawal_timeout_duration),
submitter_handle,
}
.build()
Expand Down
2 changes: 2 additions & 0 deletions crates/astria-bridge-withdrawer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct Config {
pub rollup_asset_denomination: asset::denom::TracePrefixed,
// The bridge address corresponding to the bridged rollup asset on the sequencer.
pub sequencer_bridge_address: String,
// The timeout duration for `Ics20Withdrawal`s in seconds.
pub ics20_withdrawal_timeout_duration: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, since this isn't a Duration yet, renaming to ics20_withdrawal_timeout_seconds might be slightly clearer?

// Whether to use compat addresses for `Ics20Withdrawal`s.
pub use_compat_address: bool,
// The address of the AstriaWithdrawer contract on the evm rollup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl TestBridgeWithdrawerConfig {
fee_asset_denomination: asset_denom.clone(),
rollup_asset_denomination: asset_denom.as_trace_prefixed().unwrap().clone(),
sequencer_bridge_address: default_bridge_address().to_string(),
ics20_withdrawal_timeout_duration: 300,
use_compat_address: false,
ethereum_contract_address: ethereum.contract_address(),
ethereum_rpc_endpoint: ethereum.ws_endpoint(),
Expand Down
Loading