Skip to content

Commit

Permalink
Merge pull request #275 from synonymdev/new-fee
Browse files Browse the repository at this point in the history
fix: handle output spending fee
  • Loading branch information
Jasonvdb authored Nov 28, 2024
2 parents 452c098 + 4201c97 commit 7c5bad8
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ PODS:
- React-jsinspector (0.72.4)
- React-logger (0.72.4):
- glog
- react-native-ldk (0.0.151):
- react-native-ldk (0.0.152):
- React
- react-native-randombytes (3.6.1):
- React-Core
Expand Down Expand Up @@ -621,7 +621,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
react-native-ldk: a7e71785237dd3d12dc52b4287abd88c865f5262
react-native-ldk: 1d25080cfadac349eab355725da66de140fbc7a8
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f
Expand Down Expand Up @@ -650,4 +650,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 940323d07de591a59a2ab39fc0ef7b7d6dc89c0d

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
1 change: 1 addition & 0 deletions example/ldk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const setupLdk = async (
maxAllowedNonAnchorChannelRemoteFee: 10,
onChainSweep: 10,
minAllowedNonAnchorChannelRemoteFee: 10,
outputSpendingFee: 10,
}),
getTransactionData,
getTransactionPosition,
Expand Down
1 change: 1 addition & 0 deletions example/tests/eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('Eclair', function () {
anchorChannelFee: 10,
nonAnchorChannelFee: 20,
channelCloseMinimum: 5,
outputSpendingFee: 10,
});
},
});
Expand Down
2 changes: 2 additions & 0 deletions example/tests/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('Unit', function () {
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
},
getTransactionData: async () => ({
Expand Down Expand Up @@ -214,6 +215,7 @@ describe('Unit', function () {
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
},
getTransactionData: async () => ({
Expand Down
1 change: 1 addition & 0 deletions example/tests/utils/test-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default class TestProfile {
anchorChannelFee: 2,
nonAnchorChannelFee: 3,
channelCloseMinimum: 1,
outputSpendingFee: 5,
}),
getTransactionData: this.getTransactionData,
getTransactionPosition: this.getTransactionPosition,
Expand Down
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
}
}
}
1 change: 1 addition & 0 deletions lib/ios/Ldk.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ @interface RCT_EXTERN_MODULE(Ldk, NSObject)
minAllowedAnchorChannelRemoteFee:(NSInteger *)minAllowedAnchorChannelRemoteFee
onChainSweep:(NSInteger *)onChainSweep
minAllowedNonAnchorChannelRemoteFee:(NSInteger *)minAllowedNonAnchorChannelRemoteFee
outputSpendingFee:(NSInteger *)outputSpendingFee
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(setLogLevel:(NSString *)level
Expand Down
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
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -2465,7 +2466,6 @@ class LightningManager {
EEventTypes.channel_manager_channel_closed,
(eventRes: TChannelManagerChannelClosed) => {
if (eventRes.channel_id === res.value) {

clearTimeout(timeout);
if (eventRes.peer_message) {
resolve(err(eventRes.peer_message));
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 7c5bad8

Please sign in to comment.