From a68728bbb132d845a797535554a38e125570f4ef Mon Sep 17 00:00:00 2001 From: Erik De Smedt Date: Fri, 19 Apr 2024 15:24:54 +0200 Subject: [PATCH] spec update: Use u16 instead of u8 The funding_confirms_within_blocks should be a u8. This implies 0 <= funding_confirms_within_blocks <= 255. The default-value used by the client in balance-of-satoshi is 288 blocks. This means the client gives the server approximately 48 hours to ensure the funding the transaction is confirmed. I've launched a proposal to update the spec but implement it here anyway. - See https://github.com/BitcoinAndLightningLayerSpecs/lsp/issues/112 --- libs/lsp-primitives/src/lsps1/builders.rs | 32 ++++++++++----------- libs/lsp-primitives/src/lsps1/schema.rs | 16 +++++------ plugins/lsps-server/src/channel_open/mod.rs | 2 +- plugins/lsps-server/src/db/schema.rs | 6 ++-- plugins/lsps-server/src/db/sqlite/schema.rs | 6 ++-- plugins/lsps-server/src/lsps1/fee_calc.rs | 2 +- plugins/lsps-server/src/lsps1/state.rs | 12 ++++---- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/libs/lsp-primitives/src/lsps1/builders.rs b/libs/lsp-primitives/src/lsps1/builders.rs index 4853a97..a8db2be 100644 --- a/libs/lsp-primitives/src/lsps1/builders.rs +++ b/libs/lsp-primitives/src/lsps1/builders.rs @@ -48,9 +48,9 @@ impl Lsps1InfoResponseBuilder { #[derive(Default, Debug)] pub struct Lsps1OptionsBuilder { - pub min_required_channel_confirmations: Option, - pub min_funding_confirms_within_blocks: Option, - pub min_onchain_payment_confirmations: Option, + pub min_required_channel_confirmations: Option, + pub min_funding_confirms_within_blocks: Option, + pub min_onchain_payment_confirmations: Option, pub supports_zero_channel_reserve: Option, pub min_onchain_payment_size_sat: Option, pub max_channel_expiry_blocks: Option, @@ -69,7 +69,7 @@ impl Lsps1OptionsBuilder { pub fn min_required_channel_confirmations( mut self, - min_required_channel_confirmations: u8, + min_required_channel_confirmations: u16, ) -> Self { self.min_required_channel_confirmations = Some(min_required_channel_confirmations); self @@ -77,7 +77,7 @@ impl Lsps1OptionsBuilder { pub fn min_funding_confirms_within_blocks( mut self, - min_funding_confirms_within_blocks: u8, + min_funding_confirms_within_blocks: u16, ) -> Self { self.min_funding_confirms_within_blocks = Some(min_funding_confirms_within_blocks); self @@ -85,7 +85,7 @@ impl Lsps1OptionsBuilder { pub fn min_onchain_payment_confirmations( mut self, - min_onchain_payment_confirmations: Option, + min_onchain_payment_confirmations: Option, ) -> Self { self.min_onchain_payment_confirmations = min_onchain_payment_confirmations; self @@ -213,8 +213,8 @@ impl Lsps1OptionsBuilder { pub struct Lsps1CreateOrderRequestBuilder { lsp_balance_sat: Option, client_balance_sat: Option, - funding_confirms_within_blocks: Option, - required_channel_confirmations: Option, + funding_confirms_within_blocks: Option, + required_channel_confirmations: Option, channel_expiry_blocks: Option, token: Option, refund_onchain_address: Option, @@ -241,12 +241,12 @@ impl Lsps1CreateOrderRequestBuilder { self } - pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: Option) -> Self { + pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: Option) -> Self { self.funding_confirms_within_blocks = funding_confirms_within_blocks; self } - pub fn required_channel_confirmations(mut self, required_channel_confirmations: Option) -> Self { + pub fn required_channel_confirmations(mut self, required_channel_confirmations: Option) -> Self { self.required_channel_confirmations = required_channel_confirmations; self } @@ -308,8 +308,8 @@ pub struct Lsps1CreateOrderResponseBuilder { uuid: Option, lsp_balance_sat: Option, client_balance_sat: Option, - funding_confirms_within_blocks: Option, - required_channel_confirmations: Option, + funding_confirms_within_blocks: Option, + required_channel_confirmations: Option, channel_expiry_blocks: Option, token: Option, announce_channel: Option, @@ -349,12 +349,12 @@ impl Lsps1CreateOrderResponseBuilder { self.client_balance_sat = Some(client_balance_sat); self } - pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: u8) -> Self { + pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: u16) -> Self { self.funding_confirms_within_blocks = Some(funding_confirms_within_blocks); self } - pub fn required_channel_confirmations(mut self, required_channel_confirmations: u8) -> Self{ + pub fn required_channel_confirmations(mut self, required_channel_confirmations: u16) -> Self{ self.required_channel_confirmations = Some(required_channel_confirmations); self } @@ -496,7 +496,7 @@ pub struct PaymentBuilder { bolt11_invoice: Option, onchain_address: Option, - required_onchain_block_confirmations: Option, + required_onchain_block_confirmations: Option, minimum_fee_for_0conf: Option, onchain_payment: Option, @@ -558,7 +558,7 @@ impl PaymentBuilder { pub fn required_onchain_block_confirmations( mut self, - required_onchain_block_confirmations: u8, + required_onchain_block_confirmations: u16, ) -> Self { self.required_onchain_block_confirmations = Some(required_onchain_block_confirmations); self diff --git a/libs/lsp-primitives/src/lsps1/schema.rs b/libs/lsp-primitives/src/lsps1/schema.rs index c3b843b..887ac7c 100644 --- a/libs/lsp-primitives/src/lsps1/schema.rs +++ b/libs/lsp-primitives/src/lsps1/schema.rs @@ -15,9 +15,9 @@ pub struct Lsps1GetInfoResponse { /// Options returned when calling lsps1.info #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Lsps1Options { - pub min_required_channel_confirmations: u8, - pub min_funding_confirms_within_blocks: u8, - pub min_onchain_payment_confirmations: Option, + pub min_required_channel_confirmations: u16, + pub min_funding_confirms_within_blocks: u16, + pub min_onchain_payment_confirmations: Option, pub supports_zero_channel_reserve: bool, pub min_onchain_payment_size_sat: Option, pub max_channel_expiry_blocks: u32, @@ -33,8 +33,8 @@ pub struct Lsps1Options { pub struct Lsps1CreateOrderRequest { pub lsp_balance_sat: SatAmount, pub client_balance_sat: SatAmount, - pub funding_confirms_within_blocks: u8, - pub required_channel_confirmations: u8, + pub funding_confirms_within_blocks: u16, + pub required_channel_confirmations: u16, pub channel_expiry_blocks: u32, pub token: Option, pub refund_onchain_address: Option, @@ -61,8 +61,8 @@ pub struct Lsps1CreateOrderResponse { pub order_id: Uuid, pub lsp_balance_sat: SatAmount, pub client_balance_sat: SatAmount, - pub funding_confirms_within_blocks: u8, - pub required_channel_confirmations: u8, + pub funding_confirms_within_blocks: u16, + pub required_channel_confirmations: u16, pub channel_expiry_blocks: u32, pub token: String, pub announce_channel: bool, @@ -111,7 +111,7 @@ pub struct Payment { pub bolt11_invoice: String, pub onchain_address: Option, - pub min_onchain_payment_confirmations: Option, + pub min_onchain_payment_confirmations: Option, pub min_fee_for_0conf: Option, pub onchain_payment: Option, diff --git a/plugins/lsps-server/src/channel_open/mod.rs b/plugins/lsps-server/src/channel_open/mod.rs index bc86ba6..dfcb9b7 100644 --- a/plugins/lsps-server/src/channel_open/mod.rs +++ b/plugins/lsps-server/src/channel_open/mod.rs @@ -21,7 +21,7 @@ pub struct ChannelDetails { pub(crate) announce: Option, pub(crate) close_to: Option, pub(crate) push_msat: Option, - pub(crate) mindepth: Option, + pub(crate) mindepth: Option, pub(crate) reserve: Option, } diff --git a/plugins/lsps-server/src/db/schema.rs b/plugins/lsps-server/src/db/schema.rs index dfd4404..cb4023c 100644 --- a/plugins/lsps-server/src/db/schema.rs +++ b/plugins/lsps-server/src/db/schema.rs @@ -10,8 +10,8 @@ pub struct Lsps1Order { pub(crate) client_node_id: PublicKey, pub(crate) lsp_balance_sat: SatAmount, pub(crate) client_balance_sat: SatAmount, - pub(crate) funding_confirms_within_blocks: u8, - pub(crate) required_channel_confirmations: u8, + pub(crate) funding_confirms_within_blocks: u16, + pub(crate) required_channel_confirmations: u16, pub(crate) channel_expiry_blocks: u32, pub(crate) token: Option, pub(crate) refund_onchain_address: Option, @@ -30,7 +30,7 @@ pub struct Lsps1PaymentDetails { pub(crate) bolt11_invoice: String, pub(crate) bolt11_invoice_label: String, pub(crate) onchain_address: Option, - pub(crate) onchain_block_confirmations_required: Option, + pub(crate) onchain_block_confirmations_required: Option, pub(crate) minimum_fee_for_0conf: Option, pub(crate) state: PaymentState, pub(crate) generation: u64, diff --git a/plugins/lsps-server/src/db/sqlite/schema.rs b/plugins/lsps-server/src/db/sqlite/schema.rs index 71d2f7c..8bab6b7 100644 --- a/plugins/lsps-server/src/db/sqlite/schema.rs +++ b/plugins/lsps-server/src/db/sqlite/schema.rs @@ -87,7 +87,7 @@ impl TryFrom<&Lsps1PaymentDetails> for Lsps1PaymentDetailsBase { fn try_from(payment: &Lsps1PaymentDetails) -> Result { let onchain_block_confirmations_required = payment .onchain_block_confirmations_required - .map(|p| u8::from_sqlite_integer(p)) + .map(|p| u16::from_sqlite_integer(p)) .transpose()?; let minimum_fee_for_0conf = payment @@ -120,8 +120,8 @@ impl TryFrom<&Lsps1Order> for Lsps1OrderBase { client_node_id: PublicKey::from_hex(&order.client_node_id)?, lsp_balance_sat: SatAmount::new(u64::try_from(order.lsp_balance_sat)?), client_balance_sat: SatAmount::new(u64::try_from(order.client_balance_sat)?), - funding_confirms_within_blocks: u8::try_from(order.funding_confirms_within_blocks)?, - required_channel_confirmations: u8::try_from(order.required_channel_confirmations)?, + funding_confirms_within_blocks: u16::try_from(order.funding_confirms_within_blocks)?, + required_channel_confirmations: u16::try_from(order.required_channel_confirmations)?, channel_expiry_blocks: u32::try_from(order.channel_expiry_blocks)?, token: order.token.clone(), refund_onchain_address: order.refund_onchain_address.clone(), diff --git a/plugins/lsps-server/src/lsps1/fee_calc.rs b/plugins/lsps-server/src/lsps1/fee_calc.rs index a6da7a2..8aa207d 100644 --- a/plugins/lsps-server/src/lsps1/fee_calc.rs +++ b/plugins/lsps-server/src/lsps1/fee_calc.rs @@ -85,7 +85,7 @@ impl StandardFeeCalculator { } fn calculate_onchain_feerate( - confirms_within_blocks: u8, + confirms_within_blocks: u16, feerates: &[FeeratesPerkwEstimates], ) -> Option { let max = feerates.iter().filter_map(|x| x.feerate).max(); diff --git a/plugins/lsps-server/src/lsps1/state.rs b/plugins/lsps-server/src/lsps1/state.rs index 49d9107..04d8bb7 100644 --- a/plugins/lsps-server/src/lsps1/state.rs +++ b/plugins/lsps-server/src/lsps1/state.rs @@ -28,19 +28,19 @@ where O: Unpin + 'static, { let opt = options::lsps1_min_required_channel_confirmations(); - let min_required_channel_confirmations: u8 = plugin + let min_required_channel_confirmations: u16 = plugin .option(&opt) .unwrap() .try_into() - .context(format!("Option '{}' should be an u8", opt.name))?; + .context(format!("Option '{}' should be an u16", opt.name))?; let opt = options::lsps1_min_onchain_payment_confirmations(); - let min_onchain_payment_confirmations: Option = plugin + let min_onchain_payment_confirmations: Option = plugin .option(&opt) .unwrap() .map(|x| x.try_into()) .transpose() - .context("min_onchain_payment_confirmations does not fit into u8")?; + .context("min_onchain_payment_confirmations does not fit into u16")?; let opt = options::lsps1_supports_zero_channel_reserve(); let supports_zero_channel_reserve: bool = plugin.option(&opt).unwrap(); @@ -106,11 +106,11 @@ where let max_channel_balance_sat: SatAmount = create_sat_amount(max_channel_balance_sat, opt.name)?; let opt = options::lsps1_min_funding_confirms_within_blocks(); - let min_funding_confirms_within_blocks: u8 = plugin + let min_funding_confirms_within_blocks: u16 = plugin .option(&opt) .unwrap() .try_into() - .context(format!("{} should fit into u8", opt.name))?; + .context(format!("{} should fit into u16", opt.name))?; Lsps1OptionsBuilder { min_funding_confirms_within_blocks: Some(min_funding_confirms_within_blocks),