From 9bf4d0467533d5e748fce6de315626aa385b76f3 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Tue, 22 Oct 2024 18:55:13 -0400 Subject: [PATCH 1/3] add ics20 withdrawal timeout duration option to withdrawer --- .../templates/configmaps.yaml | 1 + charts/evm-bridge-withdrawer/values.yaml | 1 + crates/astria-bridge-contracts/src/lib.rs | 35 ++++++++++++++++--- .../local.env.example | 3 ++ .../src/bridge_withdrawer/ethereum/watcher.rs | 6 ++++ .../src/bridge_withdrawer/mod.rs | 2 ++ crates/astria-bridge-withdrawer/src/config.rs | 2 ++ .../helpers/test_bridge_withdrawer.rs | 1 + 8 files changed, 46 insertions(+), 5 deletions(-) diff --git a/charts/evm-bridge-withdrawer/templates/configmaps.yaml b/charts/evm-bridge-withdrawer/templates/configmaps.yaml index f35fc9f73..cdf46715b 100644 --- a/charts/evm-bridge-withdrawer/templates/configmaps.yaml +++ b/charts/evm-bridge-withdrawer/templates/configmaps.yaml @@ -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 }} diff --git a/charts/evm-bridge-withdrawer/values.yaml b/charts/evm-bridge-withdrawer/values.yaml index 049a58ca1..895a53b70 100644 --- a/charts/evm-bridge-withdrawer/values.yaml +++ b/charts/evm-bridge-withdrawer/values.yaml @@ -21,6 +21,7 @@ config: sequencerChainId: "" sequencerAddressPrefix: "astria" sequencerBridgeAddress: "" + ics20WithdrawalTimeoutDuration: "300" useCompatAddress: "false" feeAssetDenom: "" minExpectedFeeAssetBalance: "1000000" diff --git a/crates/astria-bridge-contracts/src/lib.rs b/crates/astria-bridge-contracts/src/lib.rs index 8fe3ff020..c04595a92 100644 --- a/crates/astria-bridge-contracts/src/lib.rs +++ b/crates/astria-bridge-contracts/src/lib.rs @@ -4,6 +4,7 @@ mod generated; use std::{ borrow::Cow, sync::Arc, + time::Duration, }; use astria_core::{ @@ -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); @@ -120,6 +124,7 @@ pub struct GetWithdrawalActionsBuilder { fee_asset: Option, sequencer_asset_to_withdraw: Option, ics20_asset_to_withdraw: Option, + timeout_duration: Option, use_compat_address: bool, } @@ -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, } } @@ -153,6 +159,7 @@ impl

GetWithdrawalActionsBuilder

{ fee_asset, sequencer_asset_to_withdraw, ics20_asset_to_withdraw, + timeout_duration, use_compat_address, .. } = self; @@ -163,6 +170,7 @@ impl

GetWithdrawalActionsBuilder

{ fee_asset, sequencer_asset_to_withdraw, ics20_asset_to_withdraw, + timeout_duration, use_compat_address, } } @@ -223,6 +231,19 @@ impl

GetWithdrawalActionsBuilder

{ } } + #[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) -> Self { + Self { + timeout_duration, + ..self + } + } + #[must_use] pub fn use_compat_address(self, use_compat_address: bool) -> Self { Self { @@ -258,6 +279,7 @@ where fee_asset, sequencer_asset_to_withdraw, ics20_asset_to_withdraw, + timeout_duration, use_compat_address, } = self; @@ -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, @@ -310,6 +334,7 @@ where sequencer_asset_to_withdraw, ics20_asset_to_withdraw, ics20_source_channel, + timeout_duration, use_compat_address, }) } @@ -324,6 +349,7 @@ pub struct GetWithdrawalActions

{ sequencer_asset_to_withdraw: Option, ics20_asset_to_withdraw: Option, ics20_source_channel: Option, + timeout_duration: Duration, use_compat_address: bool, } @@ -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, @@ -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") diff --git a/crates/astria-bridge-withdrawer/local.env.example b/crates/astria-bridge-withdrawer/local.env.example index 3cd1747f4..d5ef52f81 100644 --- a/crates/astria-bridge-withdrawer/local.env.example +++ b/crates/astria-bridge-withdrawer/local.env.example @@ -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 + # Whether to use compat addresses for `Ics20Withdrawal`s. ASTRIA_BRIDGE_WITHDRAWER_USE_COMPAT_ADDRESS=false diff --git a/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs index f757fb0f0..de67ff044 100644 --- a/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/ethereum/watcher.rs @@ -61,6 +61,7 @@ pub(crate) struct Builder { pub(crate) state: Arc, 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, } @@ -75,6 +76,7 @@ impl Builder { state, rollup_asset_denom, bridge_address, + timeout_duration, use_compat_address, submitter_handle, } = self; @@ -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(), @@ -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, } @@ -149,6 +153,7 @@ impl Watcher { ethereum_rpc_endpoint, rollup_asset_denom, bridge_address, + timeout_duration, use_compat_address, state, } = self; @@ -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 diff --git a/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs index b1aa923f7..3e4f5a935 100644 --- a/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs +++ b/crates/astria-bridge-withdrawer/src/bridge_withdrawer/mod.rs @@ -85,6 +85,7 @@ impl BridgeWithdrawer { rollup_asset_denomination, sequencer_bridge_address, sequencer_grpc_endpoint, + ics20_withdrawal_timeout_duration, use_compat_address, .. } = cfg; @@ -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() diff --git a/crates/astria-bridge-withdrawer/src/config.rs b/crates/astria-bridge-withdrawer/src/config.rs index b01ea609b..14fe21318 100644 --- a/crates/astria-bridge-withdrawer/src/config.rs +++ b/crates/astria-bridge-withdrawer/src/config.rs @@ -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, // Whether to use compat addresses for `Ics20Withdrawal`s. pub use_compat_address: bool, // The address of the AstriaWithdrawer contract on the evm rollup. diff --git a/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs b/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs index 19bb7e581..4615840b6 100644 --- a/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs +++ b/crates/astria-bridge-withdrawer/tests/blackbox/helpers/test_bridge_withdrawer.rs @@ -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(), From 5c69fc8d585a8d132b94034185c90b9a2b79939b Mon Sep 17 00:00:00 2001 From: elizabeth Date: Tue, 22 Oct 2024 19:26:02 -0400 Subject: [PATCH 2/3] bump chart version --- charts/evm-bridge-withdrawer/Chart.yaml | 2 +- charts/evm-stack/Chart.lock | 6 +++--- charts/evm-stack/Chart.yaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/evm-bridge-withdrawer/Chart.yaml b/charts/evm-bridge-withdrawer/Chart.yaml index c4ed50643..488b7d8fb 100644 --- a/charts/evm-bridge-withdrawer/Chart.yaml +++ b/charts/evm-bridge-withdrawer/Chart.yaml @@ -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 diff --git a/charts/evm-stack/Chart.lock b/charts/evm-stack/Chart.lock index f4789a8b1..2c6c152e3 100644 --- a/charts/evm-stack/Chart.lock +++ b/charts/evm-stack/Chart.lock @@ -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" diff --git a/charts/evm-stack/Chart.yaml b/charts/evm-stack/Chart.yaml index 1df4d02cc..13b0e9f3b 100644 --- a/charts/evm-stack/Chart.yaml +++ b/charts/evm-stack/Chart.yaml @@ -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 From 73d8653bc8baadc92ee492687aa1441b550a76c1 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Tue, 22 Oct 2024 19:29:27 -0400 Subject: [PATCH 3/3] bump chart version --- charts/evm-stack/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/evm-stack/Chart.yaml b/charts/evm-stack/Chart.yaml index 13b0e9f3b..06c73c95b 100644 --- a/charts/evm-stack/Chart.yaml +++ b/charts/evm-stack/Chart.yaml @@ -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