Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle output spending fee #275

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
},
getTransactionData: async () => ({
Expand Down Expand Up @@ -193,19 +194,19 @@
}

const startParams = {
getBestBlock: async () => ({

Check warning on line 197 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
hash: '6993d7c36204c9f369a7d9d80590c4e2a86b9641c327fbc276a534797ca50a2f',
height: 1,
hex: '000000205d1f3ece3bcb0a3530adaae2e4aa47f8aad434db95c6cb6d09d5ac99e3f6df4f0a19fe968830a06dcc49c9cca4acc532226e4c30b741802420e0fdd2b092eccdbf95cb64ffff7f2000000000',
}),
account,
getAddress: async () => ({

Check warning on line 203 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
address: 'bcrt1qtk89me2ae95dmlp3yfl4q9ynpux8mxjus4s872',
publicKey:
'0298720ece754e377af1b2716256e63c2e2427ff6ebdc66c2071c43ae80132ca32',
}),
getScriptPubKeyHistory: async () => [],

Check warning on line 208 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
getFees: () => {

Check warning on line 209 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
return Promise.resolve({
nonAnchorChannelFee: 5,
anchorChannelFee: 5,
Expand All @@ -214,16 +215,17 @@
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
},
getTransactionData: async () => ({

Check warning on line 221 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
header: '',
height: 0,
transaction: '',
vout: [],
}),
getTransactionPosition: async () => -1,

Check warning on line 227 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
broadcastTransaction: async () => '',

Check warning on line 228 in example/tests/unit.ts

View workflow job for this annotation

GitHub Actions / Run lint check

Missing return type on function
network: ENetworks.regtest,
skipRemoteBackups: true,
};
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 @@ -55,7 +55,7 @@
TCreatePaymentReq,
TBackupServerDetails,
IAddress,
TLspLogPayload,

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'TLspLogPayload' is defined but never used

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'TLspLogPayload' is defined but never used

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'TLspLogPayload' is defined but never used
TLspLogEvent,
TChannelMonitor,
TCreateChannelReq,
Expand Down Expand Up @@ -140,6 +140,7 @@
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: 5,
onChainSweep: 5,
outputSpendingFee: 5,
});
broadcastTransaction: TBroadcastTransaction = async (): Promise<any> => {};
lspLogEvent: TLspLogEvent | undefined;
Expand Down Expand Up @@ -2183,7 +2184,7 @@
}

private onChannelManagerPendingHtlcsForwardable(
res: TChannelManagerPendingHtlcsForwardable,

Check warning on line 2187 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'res' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2187 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'res' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2187 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'res' is defined but never used. Allowed unused args must match /^_/u
): void {
ldk.processPendingHtlcForwards().catch(console.error);
}
Expand Down Expand Up @@ -2446,7 +2447,7 @@
return err(res.error);
}

return new Promise((resolve, reject) => {

Check warning on line 2450 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'reject' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2450 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'reject' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2450 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'reject' is defined but never used. Allowed unused args must match /^_/u
// Channel funding ready event should be instant but if it fails and we don't get the event, we should reject.
const timeout = setTimeout(() => {
resolve(err(new Error('Event not triggered within 5 seconds')));
Expand All @@ -2465,7 +2466,6 @@
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
Loading