Skip to content

Commit

Permalink
feat: Evaluate jit channels enabled configuration
Browse files Browse the repository at this point in the history
We don't want to open new jit channels during our architecture revamp. We could have used the `max_allowed_tx_fee_rate_when_opening_channel` to achieve the same goal, but as this was also not working and I already had to touch the code, I figured I am adding an evaluation of the `jit_channels_enabled` which better matches our intentions than the other config.
  • Loading branch information
holzeis committed Jan 3, 2024
1 parent c51e007 commit 644f060
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async fn main() -> Result<()> {
WalletSettings {
max_allowed_tx_fee_rate_when_opening_channel: settings
.max_allowed_tx_fee_rate_when_opening_channel,
jit_channels_enabled: settings.jit_channels_enabled,
},
opts.get_oracle_infos()
.into_iter()
Expand Down
3 changes: 3 additions & 0 deletions coordinator/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct NodeSettings {
// scheduled upgrade)
pub allow_opening_positions: bool,
pub max_allowed_tx_fee_rate_when_opening_channel: Option<u32>,
// Defines if we want to open jit channels
pub jit_channels_enabled: bool,
/// Defines the sats/vbyte to be used for all transactions within the sub-channel
pub contract_tx_fee_rate: u64,
}
Expand All @@ -77,6 +79,7 @@ impl NodeSettings {
WalletSettings {
max_allowed_tx_fee_rate_when_opening_channel: self
.max_allowed_tx_fee_rate_when_opening_channel,
jit_channels_enabled: self.jit_channels_enabled,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions coordinator/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl Settings {
max_allowed_tx_fee_rate_when_opening_channel: self
.max_allowed_tx_fee_rate_when_opening_channel,
contract_tx_fee_rate: self.contract_tx_fee_rate,
jit_channels_enabled: self.jit_channels_enabled,
}
}

Expand Down
13 changes: 12 additions & 1 deletion crates/ln-dlc-node/src/ldk_node_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ where
node_storage: Arc<N>,
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct WalletSettings {
pub max_allowed_tx_fee_rate_when_opening_channel: Option<u32>,
pub jit_channels_enabled: bool,
}

impl Default for WalletSettings {
fn default() -> Self {
Self {
max_allowed_tx_fee_rate_when_opening_channel: None,
jit_channels_enabled: true,
}
}
}

impl<D, B, F, N> Wallet<D, B, F, N>
Expand Down Expand Up @@ -400,6 +410,7 @@ mod tests {
test_wallet,
Arc::new(DummyFeeRateEstimator),
Arc::new(DummyNodeStorage),
WalletSettings::default(),
);

let fee_rate = FeeRate::from_sat_per_vb(10.0);
Expand Down
11 changes: 11 additions & 0 deletions crates/ln-dlc-node/src/ln/coordinator_event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::storage::TenTenOneStorage;
use crate::EventHandlerTrait;
use crate::CONFIRMATION_TARGET;
use anyhow::anyhow;
use anyhow::bail;
use anyhow::ensure;
use anyhow::Context;
use anyhow::Result;
Expand Down Expand Up @@ -507,6 +508,16 @@ pub(crate) async fn handle_intercepted_htlc_internal<S: TenTenOneStorage, N: Sto
max_counterparty_fund_amount_msat: {max_counterparty_fund_amount_msat}"
);

if !node
.wallet
.ldk_wallet()
.settings()
.await
.jit_channels_enabled
{
bail!("Opening jit channels is disabled. Rejecting attempt to open a JIT channel.");
}

let opt_max_allowed_fee = node
.wallet
.ldk_wallet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async fn fail_to_open_jit_channel_with_fee_rate_over_max() {
// rate to ensure that opening the JIT channel fails
let settings = WalletSettings {
max_allowed_tx_fee_rate_when_opening_channel: Some(background_fee_rate - 1),
jit_channels_enabled: true,
};

coordinator.ldk_wallet().update_settings(settings).await;
Expand Down

0 comments on commit 644f060

Please sign in to comment.