Skip to content

Commit

Permalink
fix: handle output spending fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Nov 28, 2024
1 parent 452c098 commit 4766519
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions lib/ios/Classes/LdkFeeEstimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
5 changes: 3 additions & 2 deletions lib/ios/Ldk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/ldk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class LDK {
minAllowedAnchorChannelRemoteFee,
onChainSweep,
minAllowedNonAnchorChannelRemoteFee,
outputSpendingFee,
} = fees;
try {
const satsPerKw = 250;
Expand All @@ -356,6 +357,7 @@ class LDK {
minAllowedAnchorChannelRemoteFee * satsPerKw,
onChainSweep * satsPerKw,
minAllowedNonAnchorChannelRemoteFee * satsPerKw,
outputSpendingFee * satsPerKw,
);
this.writeDebugToLog('updateFees', fees);
return ok(res);
Expand Down
1 change: 1 addition & 0 deletions lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class LightningManager {
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
broadcastTransaction: TBroadcastTransaction = async (): Promise<any> => {};
lspLogEvent: TLspLogEvent | undefined;
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export type TFeeUpdateReq = {
minAllowedAnchorChannelRemoteFee: number;
onChainSweep: number;
minAllowedNonAnchorChannelRemoteFee: number;
outputSpendingFee: number;
};

export type TPeer = {
Expand Down

0 comments on commit 4766519

Please sign in to comment.