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

Fix channel amount and fee issues #69

Merged
merged 35 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dec5fb8
add defaut config amounts for channel
chenyukang Jun 14, 2024
85e9089
add min_fee_rate
chenyukang Jun 12, 2024
afc2e12
fix minimal UDT amount
chenyukang Jun 14, 2024
e26cddd
change ckb and fee amount from u128 to u64
chenyukang Jun 14, 2024
a24c696
verify shutdown fee for shutdown command
chenyukang Jun 14, 2024
76590bf
add check_add_tlc_amount for tlc
chenyukang Jun 14, 2024
35f7f9b
rename ckb amounts
chenyukang Jun 19, 2024
b4a7e32
add minimal reserve ckb amount
chenyukang Jun 19, 2024
160f0c1
refactor funding request for minimal reserve ckb amount
chenyukang Jun 19, 2024
65951c8
fix check for add tlc
chenyukang Jun 19, 2024
ae7d11c
fix unit tests
chenyukang Jun 19, 2024
81f29ef
auto accept channel for UDT right now
chenyukang Jun 19, 2024
2ffa512
fix test
chenyukang Jun 19, 2024
597a104
use moleculec 8.0
chenyukang Jun 19, 2024
78d1bee
use fee rate instead of fee in shutdown command
chenyukang Jun 20, 2024
7a76f94
enable debug assertion for tlcs amount
chenyukang Jun 20, 2024
9b35102
add more tests for tlc amounts
chenyukang Jun 20, 2024
1f9ff3f
add funding fee rate
chenyukang Jun 24, 2024
e1d74a6
set placeholder witness for shutdown tx
chenyukang Jun 24, 2024
4b6c905
fix conflicts with main
chenyukang Jun 24, 2024
3a59939
fix comments
chenyukang Jun 24, 2024
d74cb33
code refactor in channel command
chenyukang Jun 24, 2024
4ea392c
add e2e test for UDT cell is not enough
chenyukang Jun 24, 2024
adcd789
add UDT auto_accept option
chenyukang Jun 24, 2024
3ca56d1
code refactor
chenyukang Jun 24, 2024
c256cb2
add amounts check for channel
chenyukang Jun 25, 2024
f278ccb
add check for reserved ckb amount
chenyukang Jun 25, 2024
6bacb5f
code refactor for style
chenyukang Jun 25, 2024
58d8807
fix reserved_ckb_amount variable name
chenyukang Jun 25, 2024
14e3a5e
fix is_tx_final coding style
chenyukang Jun 25, 2024
eb43c8b
add calculate_shutdown_fee
chenyukang Jun 25, 2024
e3ce52f
Merge branch 'main' into fix-channel-amount-issues
chenyukang Jun 26, 2024
f9cc31b
Merge branch 'up-main' into fix-channel-amount-issues
chenyukang Jun 26, 2024
8c79575
fix tests for reestablish
chenyukang Jun 26, 2024
53c010a
fix conflicts
chenyukang Jun 26, 2024
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
334 changes: 241 additions & 93 deletions src/ckb/channel.rs

Large diffs are not rendered by default.

47 changes: 34 additions & 13 deletions src/ckb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ use serde::Deserialize;

use crate::Result;

pub const CKB_SHANNONS: u64 = 100_000_000;
pub const DEFAULT_MIN_INBOUND_LIQUIDITY: u64 = 100 * CKB_SHANNONS; // 100 CKB for minimal inbound liquidity
pub const DEFAULT_MIN_SHUTDOWN_FEE: u64 = 1 * CKB_SHANNONS; // 1 CKB prepared for shutdown transaction fee
pub const MIN_OCCUPIED_CAPACITY: u64 = 61 * CKB_SHANNONS; // 61 CKB for occupied capacity
pub const MIN_UDT_OCCUPIED_CAPACITY: u64 = 142 * CKB_SHANNONS; // 142 CKB for UDT occupied capacity

/// 62 CKB minimal channel amount, at any time a partner should keep at least
/// `MIN_OCCUPIED_CAPACITY` CKB in the channel, so that he can build a valid shutdown transaction
/// and pay proper fee.
pub const DEFAULT_CHANNEL_MINIMAL_CKB_AMOUNT: u64 =
MIN_OCCUPIED_CAPACITY + DEFAULT_MIN_SHUTDOWN_FEE;

pub const DEFAULT_UDT_MINIMAL_CKB_AMOUNT: u64 =
MIN_UDT_OCCUPIED_CAPACITY + DEFAULT_MIN_SHUTDOWN_FEE; // 143 CKB for minimal UDT amount

/// 162 CKB to open a channel,
/// 100 CKB for minimal inbound liquidity, 61 CKB for occupied capacity
/// The other party may auto accept the channel if the amount is greater than this.
pub const DEFAULT_CHANNEL_MIN_AUTO_CKB_AMOUNT: u64 =
DEFAULT_MIN_INBOUND_LIQUIDITY + MIN_OCCUPIED_CAPACITY + DEFAULT_MIN_SHUTDOWN_FEE;

// See comment in `LdkConfig` for why do we need to specify both name and long,
// and prefix them with `ckb-`/`CKB_`.
#[derive(ClapSerde, Debug, Clone)]
Expand Down Expand Up @@ -47,33 +68,33 @@ pub struct CkbConfig {
#[arg(name = "CKB_NETWORK", long = "ckb-network", env)]
pub network: Option<CkbNetwork>,

/// minimum ckb funding amount for open channel requests, unit: shannons [default: 16100000000 shannons]
/// minimum ckb funding amount for auto accepting an open channel requests, aunit: shannons [default: 16200000000 shannons]
#[arg(
name = "CKB_OPEN_CHANNEL_MIN_CKB_FUNDING_AMOUNT",
long = "ckb-open-channel-min-ckb-funding-amount",
name = "CKB_OPEN_CHANNEL_AUTO_ACCEPT_MIN_CKB_FUNDING_AMOUNT",
long = "ckb-open-channel-auto-accept-min-ckb-funding-amount",
env,
help = "minimum ckb funding amount for open channel requests, unit: shannons [default: 16100000000 shannons]"
help = "minimum ckb funding amount for auto accepting an open channel requests, unit: shannons [default: 16200000000 shannons]"
)]
pub open_channel_min_ckb_funding_amount: Option<u128>,
/// whether to accept open channel requests with ckb funding amount automatically, unit: shannons [default: 6100000000 shannons], if this is set to zero, it means to disable auto accept
pub open_channel_auto_accept_min_ckb_funding_amount: Option<u64>,
/// whether to accept open channel requests with ckb funding amount automatically, unit: shannons [default: 6200000000 shannons], if this is set to zero, it means to disable auto accept
#[arg(
name = "CKB_AUTO_ACCEPT_CHANNEL_CKB_FUNDING_AMOUNT",
long = "ckb-auto-accept-channel-ckb-funding-amount",
env,
help = "whether to accept open channel requests with ckb funding amount automatically, unit: shannons [default: 6100000000 shannons], if this is set to zero, it means to disable auto accept"
help = "whether to accept open channel requests with ckb funding amount automatically, unit: shannons [default: 6200000000 shannons], if this is set to zero, it means to disable auto accept"
)]
pub auto_accept_channel_ckb_funding_amount: Option<u128>,
pub auto_accept_channel_ckb_funding_amount: Option<u64>,
}

impl CkbConfig {
pub fn open_channel_min_ckb_funding_amount(&self) -> u128 {
self.open_channel_min_ckb_funding_amount
.unwrap_or(16100000000)
pub fn open_channel_auto_accept_min_ckb_funding_amount(&self) -> u64 {
self.open_channel_auto_accept_min_ckb_funding_amount
.unwrap_or(DEFAULT_CHANNEL_MIN_AUTO_CKB_AMOUNT)
}

pub fn auto_accept_channel_ckb_funding_amount(&self) -> u128 {
pub fn auto_accept_channel_ckb_funding_amount(&self) -> u64 {
self.auto_accept_channel_ckb_funding_amount
.unwrap_or(6100000000)
.unwrap_or(DEFAULT_CHANNEL_MINIMAL_CKB_AMOUNT)
}
}

Expand Down
336 changes: 204 additions & 132 deletions src/ckb/gen/cfn.rs

Large diffs are not rendered by default.

Loading
Loading