From 476651912dca80193486b1b43e4a12e385f51430 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 28 Nov 2024 10:56:50 +0200 Subject: [PATCH] fix: handle output spending fee --- .../src/main/java/com/reactnativeldk/LdkModule.kt | 4 ++-- .../com/reactnativeldk/classes/LdkFeeEstimator.kt | 9 ++++----- lib/ios/Classes/LdkFeeEstimator.swift | 15 ++++++++------- lib/ios/Ldk.swift | 5 +++-- lib/src/ldk.ts | 2 ++ lib/src/lightning-manager.ts | 1 + lib/src/utils/types.ts | 1 + 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt index 51dcc560..a74c47ea 100644 --- a/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt +++ b/lib/android/src/main/java/com/reactnativeldk/LdkModule.kt @@ -592,8 +592,8 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod //MARK: Update methods @ReactMethod - fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, promise: Promise) { - feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt()) + fun updateFees(anchorChannelFee: Double, nonAnchorChannelFee: Double, channelCloseMinimum: Double, minAllowedAnchorChannelRemoteFee: Double, onChainSweep: Double, minAllowedNonAnchorChannelRemoteFee: Double, outputSpendingFee: Double, promise: Promise) { + feeEstimator.update(anchorChannelFee.toInt(), nonAnchorChannelFee.toInt(), channelCloseMinimum.toInt(), minAllowedAnchorChannelRemoteFee.toInt(), onChainSweep.toInt(), minAllowedNonAnchorChannelRemoteFee.toInt(), outputSpendingFee.toInt()) handleResolve(promise, LdkCallbackResponses.fees_updated) } diff --git a/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt b/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt index 9c7b1f98..e68245eb 100644 --- a/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt +++ b/lib/android/src/main/java/com/reactnativeldk/classes/LdkFeeEstimator.kt @@ -11,14 +11,16 @@ class LdkFeeEstimator { var minAllowedAnchorChannelRemoteFee: Int = 0 var onChainSweep: Int = 0 var minAllowedNonAnchorChannelRemoteFee: Int = 0 + var outputSpendingFee: Int = 0 - fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int) { + fun update(anchorChannelFee: Int, nonAnchorChannelFee: Int, channelCloseMinimum: Int, minAllowedAnchorChannelRemoteFee: Int, onChainSweep: Int, minAllowedNonAnchorChannelRemoteFee: Int, outputSpendingFee: Int) { this.anchorChannelFee = anchorChannelFee this.nonAnchorChannelFee = nonAnchorChannelFee this.channelCloseMinimum = channelCloseMinimum this.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee this.onChainSweep = onChainSweep this.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee + this.outputSpendingFee = outputSpendingFee LdkEventEmitter.send(EventTypes.native_log, "Fee estimator updated") } @@ -31,10 +33,7 @@ class LdkFeeEstimator { ConfirmationTarget.LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee -> minAllowedAnchorChannelRemoteFee ConfirmationTarget.LDKConfirmationTarget_OnChainSweep -> onChainSweep ConfirmationTarget.LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee -> minAllowedNonAnchorChannelRemoteFee - else -> { - LdkEventEmitter.send(EventTypes.native_log, "ERROR: New ConfirmationTarget added. Update LdkFeeEstimator.") - return@new_impl 0 - } + ConfirmationTarget.LDKConfirmationTarget_OutputSpendingFee -> outputSpendingFee } } } diff --git a/lib/ios/Classes/LdkFeeEstimator.swift b/lib/ios/Classes/LdkFeeEstimator.swift index c19cad67..2e8c0f23 100644 --- a/lib/ios/Classes/LdkFeeEstimator.swift +++ b/lib/ios/Classes/LdkFeeEstimator.swift @@ -15,21 +15,23 @@ class LdkFeeEstimator: FeeEstimator { private var minAllowedAnchorChannelRemoteFee: UInt32 = 0 private var onChainSweep: UInt32 = 0 private var minAllowedNonAnchorChannelRemoteFee: UInt32 = 0 - - func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32) { + private var outputSpendingFee: UInt32 = 0 + + func update(anchorChannelFee: UInt32, nonAnchorChannelFee: UInt32, channelCloseMinimum: UInt32, minAllowedAnchorChannelRemoteFee: UInt32, onChainSweep: UInt32, minAllowedNonAnchorChannelRemoteFee: UInt32, outputSpendingFee: UInt32) { self.anchorChannelFee = anchorChannelFee self.nonAnchorChannelFee = nonAnchorChannelFee self.channelCloseMinimum = channelCloseMinimum self.minAllowedAnchorChannelRemoteFee = minAllowedAnchorChannelRemoteFee self.onChainSweep = onChainSweep self.minAllowedNonAnchorChannelRemoteFee = minAllowedNonAnchorChannelRemoteFee + self.outputSpendingFee = outputSpendingFee LdkEventEmitter.shared.send(withEvent: .native_log, body: "Fee estimator updated") } - + override func getEstSatPer1000Weight(confirmationTarget: Bindings.ConfirmationTarget) -> UInt32 { let target = confirmationTarget - + switch target { case .AnchorChannelFee: return anchorChannelFee @@ -43,9 +45,8 @@ class LdkFeeEstimator: FeeEstimator { return onChainSweep case .MinAllowedNonAnchorChannelRemoteFee: return minAllowedNonAnchorChannelRemoteFee - @unknown default: - LdkEventEmitter.shared.send(withEvent: .native_log, body: "ERROR: New ConfirmationTarget added. Update LdkFeeEstimator.") - return 0 + case .OutputSpendingFee: + return outputSpendingFee } } } diff --git a/lib/ios/Ldk.swift b/lib/ios/Ldk.swift index 7cb441c1..da5e7fda 100644 --- a/lib/ios/Ldk.swift +++ b/lib/ios/Ldk.swift @@ -618,14 +618,15 @@ class Ldk: NSObject { // MARK: Update methods @objc - func updateFees(_ anchorChannelFee: NSInteger, nonAnchorChannelFee: NSInteger, channelCloseMinimum: NSInteger, minAllowedAnchorChannelRemoteFee: NSInteger, onChainSweep: NSInteger, minAllowedNonAnchorChannelRemoteFee: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func updateFees(_ anchorChannelFee: NSInteger, nonAnchorChannelFee: NSInteger, channelCloseMinimum: NSInteger, minAllowedAnchorChannelRemoteFee: NSInteger, onChainSweep: NSInteger, minAllowedNonAnchorChannelRemoteFee: NSInteger, outputSpendingFee: NSInteger, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { feeEstimator.update( anchorChannelFee: UInt32(anchorChannelFee), nonAnchorChannelFee: UInt32(nonAnchorChannelFee), channelCloseMinimum: UInt32(channelCloseMinimum), minAllowedAnchorChannelRemoteFee: UInt32(minAllowedAnchorChannelRemoteFee), onChainSweep: UInt32(onChainSweep), - minAllowedNonAnchorChannelRemoteFee: UInt32(minAllowedNonAnchorChannelRemoteFee) + minAllowedNonAnchorChannelRemoteFee: UInt32(minAllowedNonAnchorChannelRemoteFee), + outputSpendingFee: UInt32(outputSpendingFee) ) return handleResolve(resolve, .fees_updated) } diff --git a/lib/src/ldk.ts b/lib/src/ldk.ts index 62d408cd..6fae8efa 100644 --- a/lib/src/ldk.ts +++ b/lib/src/ldk.ts @@ -346,6 +346,7 @@ class LDK { minAllowedAnchorChannelRemoteFee, onChainSweep, minAllowedNonAnchorChannelRemoteFee, + outputSpendingFee, } = fees; try { const satsPerKw = 250; @@ -356,6 +357,7 @@ class LDK { minAllowedAnchorChannelRemoteFee * satsPerKw, onChainSweep * satsPerKw, minAllowedNonAnchorChannelRemoteFee * satsPerKw, + outputSpendingFee * satsPerKw, ); this.writeDebugToLog('updateFees', fees); return ok(res); diff --git a/lib/src/lightning-manager.ts b/lib/src/lightning-manager.ts index cbc1a80f..564718c8 100644 --- a/lib/src/lightning-manager.ts +++ b/lib/src/lightning-manager.ts @@ -140,6 +140,7 @@ class LightningManager { minAllowedAnchorChannelRemoteFee: 5, minAllowedNonAnchorChannelRemoteFee: 5, onChainSweep: 5, + outputSpendingFee: 5, }); broadcastTransaction: TBroadcastTransaction = async (): Promise => {}; lspLogEvent: TLspLogEvent | undefined; diff --git a/lib/src/utils/types.ts b/lib/src/utils/types.ts index c43dae07..43be0b68 100644 --- a/lib/src/utils/types.ts +++ b/lib/src/utils/types.ts @@ -252,6 +252,7 @@ export type TFeeUpdateReq = { minAllowedAnchorChannelRemoteFee: number; onChainSweep: number; minAllowedNonAnchorChannelRemoteFee: number; + outputSpendingFee: number; }; export type TPeer = {