Skip to content

Commit

Permalink
spec update: Use u16 instead of u8
Browse files Browse the repository at this point in the history
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 BitcoinAndLightningLayerSpecs/lsp#112
  • Loading branch information
ErikDeSmedt committed Apr 19, 2024
1 parent 66875e5 commit a68728b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
32 changes: 16 additions & 16 deletions libs/lsp-primitives/src/lsps1/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl Lsps1InfoResponseBuilder {

#[derive(Default, Debug)]
pub struct Lsps1OptionsBuilder {
pub min_required_channel_confirmations: Option<u8>,
pub min_funding_confirms_within_blocks: Option<u8>,
pub min_onchain_payment_confirmations: Option<u8>,
pub min_required_channel_confirmations: Option<u16>,
pub min_funding_confirms_within_blocks: Option<u16>,
pub min_onchain_payment_confirmations: Option<u16>,
pub supports_zero_channel_reserve: Option<bool>,
pub min_onchain_payment_size_sat: Option<SatAmount>,
pub max_channel_expiry_blocks: Option<u32>,
Expand All @@ -69,23 +69,23 @@ 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
}

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
}

pub fn min_onchain_payment_confirmations(
mut self,
min_onchain_payment_confirmations: Option<u8>,
min_onchain_payment_confirmations: Option<u16>,
) -> Self {
self.min_onchain_payment_confirmations = min_onchain_payment_confirmations;
self
Expand Down Expand Up @@ -213,8 +213,8 @@ impl Lsps1OptionsBuilder {
pub struct Lsps1CreateOrderRequestBuilder {
lsp_balance_sat: Option<SatAmount>,
client_balance_sat: Option<SatAmount>,
funding_confirms_within_blocks: Option<u8>,
required_channel_confirmations: Option<u8>,
funding_confirms_within_blocks: Option<u16>,
required_channel_confirmations: Option<u16>,
channel_expiry_blocks: Option<u32>,
token: Option<String>,
refund_onchain_address: Option<OnchainAddress>,
Expand All @@ -241,12 +241,12 @@ impl Lsps1CreateOrderRequestBuilder {
self
}

pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: Option<u8>) -> Self {
pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: Option<u16>) -> Self {
self.funding_confirms_within_blocks = funding_confirms_within_blocks;
self
}

pub fn required_channel_confirmations(mut self, required_channel_confirmations: Option<u8>) -> Self {
pub fn required_channel_confirmations(mut self, required_channel_confirmations: Option<u16>) -> Self {
self.required_channel_confirmations = required_channel_confirmations;
self
}
Expand Down Expand Up @@ -308,8 +308,8 @@ pub struct Lsps1CreateOrderResponseBuilder {
uuid: Option<Uuid>,
lsp_balance_sat: Option<SatAmount>,
client_balance_sat: Option<SatAmount>,
funding_confirms_within_blocks: Option<u8>,
required_channel_confirmations: Option<u8>,
funding_confirms_within_blocks: Option<u16>,
required_channel_confirmations: Option<u16>,
channel_expiry_blocks: Option<u32>,
token: Option<String>,
announce_channel: Option<bool>,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -496,7 +496,7 @@ pub struct PaymentBuilder {

bolt11_invoice: Option<String>,
onchain_address: Option<OnchainAddress>,
required_onchain_block_confirmations: Option<u8>,
required_onchain_block_confirmations: Option<u16>,

minimum_fee_for_0conf: Option<FeeRate>,
onchain_payment: Option<OnchainPayment>,
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions libs/lsp-primitives/src/lsps1/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
pub min_required_channel_confirmations: u16,
pub min_funding_confirms_within_blocks: u16,
pub min_onchain_payment_confirmations: Option<u16>,
pub supports_zero_channel_reserve: bool,
pub min_onchain_payment_size_sat: Option<SatAmount>,
pub max_channel_expiry_blocks: u32,
Expand All @@ -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<String>,
pub refund_onchain_address: Option<OnchainAddress>,
Expand All @@ -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,
Expand Down Expand Up @@ -111,7 +111,7 @@ pub struct Payment {

pub bolt11_invoice: String,
pub onchain_address: Option<OnchainAddress>,
pub min_onchain_payment_confirmations: Option<u8>,
pub min_onchain_payment_confirmations: Option<u16>,

pub min_fee_for_0conf: Option<FeeRate>,
pub onchain_payment: Option<OnchainPayment>,
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/channel_open/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ChannelDetails {
pub(crate) announce: Option<bool>,
pub(crate) close_to: Option<String>,
pub(crate) push_msat: Option<SatAmount>,
pub(crate) mindepth: Option<u8>,
pub(crate) mindepth: Option<u16>,
pub(crate) reserve: Option<SatAmount>,
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/lsps-server/src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub(crate) refund_onchain_address: Option<String>,
Expand All @@ -30,7 +30,7 @@ pub struct Lsps1PaymentDetails {
pub(crate) bolt11_invoice: String,
pub(crate) bolt11_invoice_label: String,
pub(crate) onchain_address: Option<String>,
pub(crate) onchain_block_confirmations_required: Option<u8>,
pub(crate) onchain_block_confirmations_required: Option<u16>,
pub(crate) minimum_fee_for_0conf: Option<FeeRate>,
pub(crate) state: PaymentState,
pub(crate) generation: u64,
Expand Down
6 changes: 3 additions & 3 deletions plugins/lsps-server/src/db/sqlite/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl TryFrom<&Lsps1PaymentDetails> for Lsps1PaymentDetailsBase {
fn try_from(payment: &Lsps1PaymentDetails) -> Result<Self, Self::Error> {
let onchain_block_confirmations_required = payment
.onchain_block_confirmations_required
.map(|p| u8::from_sqlite_integer(p))
.map(|p| u16::from_sqlite_integer(p))

Check failure on line 90 in plugins/lsps-server/src/db/sqlite/schema.rs

View workflow job for this annotation

GitHub Actions / test

no function or associated item named `from_sqlite_integer` found for type `u16` in the current scope

Check failure on line 90 in plugins/lsps-server/src/db/sqlite/schema.rs

View workflow job for this annotation

GitHub Actions / test

no function or associated item named `from_sqlite_integer` found for type `u16` in the current scope
.transpose()?;

let minimum_fee_for_0conf = payment
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/lsps1/fee_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl StandardFeeCalculator {
}

fn calculate_onchain_feerate(
confirms_within_blocks: u8,
confirms_within_blocks: u16,
feerates: &[FeeratesPerkwEstimates],
) -> Option<u32> {
let max = feerates.iter().filter_map(|x| x.feerate).max();
Expand Down
12 changes: 6 additions & 6 deletions plugins/lsps-server/src/lsps1/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = plugin
let min_onchain_payment_confirmations: Option<u16> = 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();
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit a68728b

Please sign in to comment.