Skip to content

Commit

Permalink
Store and retrieve the split mining fees for liquidity
Browse files Browse the repository at this point in the history
With ACINQ/lightning-kmp#709 and
ACINQ/lightning-kmp#710, the mining
fee for liquidity events is split between local and purchase
fee. However, we don't directly store the split fees, for
backward compatibility reasons. Thus, to get the local fee
from the database, we must compute it back.
  • Loading branch information
dpad85 committed Oct 10, 2024
1 parent 74f8b95 commit b4a1eb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class InboundLiquidityQueries(val database: PhoenixDatabase) {
database.transaction {
queries.insert(
id = payment.id.toString(),
// We store the full mining fee in the database, for compatibility reasons. See comment in the mapper below for details.
mining_fees_sat = payment.miningFees.sat,
channel_id = payment.channelId.toByteArray(),
tx_id = payment.txId.value.toByteArray(),
Expand Down Expand Up @@ -89,12 +90,16 @@ class InboundLiquidityQueries(val database: PhoenixDatabase) {
confirmed_at: Long?,
locked_at: Long?
): InboundLiquidityOutgoingPayment {
val purchase = PurchaseData.decodeAsCanonical(lease_type, lease_blob)
return InboundLiquidityOutgoingPayment(
id = UUID.fromString(id),
miningFees = mining_fees_sat.sat,
// Attention! With the new OTF and lightning-kmp#710, the liquidity mining fee is split between `localMiningFee` and `purchase.miningFee`.
// However, for compatibility reasons with legacy lease data, we keep storing the "merged" mining fee in the mining_fee_sat column.
// It means that to retrieve the `localMiningFee`, we must subtract `purchase.miningFee` from the `mining_fee_sat` column.
localMiningFees = mining_fees_sat.sat - purchase.fees.miningFee,
channelId = channel_id.toByteVector32(),
txId = TxId(tx_id),
purchase = PurchaseData.decodeAsCanonical(lease_type, lease_blob),
purchase = purchase,
createdAt = created_at,
confirmedAt = confirmed_at,
lockedAt = locked_at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Stores in a flat row payments standing for an inbound liquidity request (which are done through a splice).
-- The purchase data are stored in a complex column, as a json-encoded blob. See InboundLiquidityLeaseType file.
-- The purchase data are stored in a complex column, as a json-encoded blob.
--
-- Note that these purchase data used to be called "lease" in the old on-the-fly channel mechanism, that's why the
-- colum uses that name, it's a legacy artifact. They now map to a "LiquidityAds.Purchase" object.
Expand Down

0 comments on commit b4a1eb6

Please sign in to comment.