Skip to content

Commit 27a0520

Browse files
authored
Merge pull request #103 from TheBlueMatt/main
Update to LDK 0.0.115
2 parents 5905577 + 55dc8c9 commit 27a0520

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+13526
-7211
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
git clone https://github.com/rust-bitcoin/rust-lightning
3939
cd rust-lightning
40-
git checkout 0.0.114-bindings
40+
git checkout 0.0.115-bindings
4141
- name: Fix Github Actions to not be broken
4242
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
4343
- name: Rebuild bindings without std, and check the sample app builds + links
@@ -90,7 +90,7 @@ jobs:
9090
run: |
9191
git clone https://github.com/rust-bitcoin/rust-lightning
9292
cd rust-lightning
93-
git checkout 0.0.114-bindings
93+
git checkout 0.0.115-bindings
9494
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
9595
run: ./genbindings.sh ./rust-lightning true
9696
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
442442
match token_iter.next().unwrap() {
443443
TokenTree::Literal(lit) => {
444444
// Drop the first and last chars from lit as they are always "
445-
let doc = format!("{}", lit);
445+
let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}//!", prefix));
446446
writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap();
447447
},
448448
_ => unimplemented!(),
@@ -452,7 +452,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
452452
match token_iter.next().unwrap() {
453453
TokenTree::Literal(lit) => {
454454
// Drop the first and last chars from lit as they are always "
455-
let doc = format!("{}", lit);
455+
let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}///", prefix));
456456
writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap();
457457
},
458458
_ => unimplemented!(),

c-bindings-gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
12891289

12901290
writeln!(w, " {{ true }} else {{ false }}\n}}").unwrap();
12911291
} else if path_matches_nongeneric(&trait_path.1, &["core", "hash", "Hash"]) {
1292-
writeln!(w, "/// Checks if two {}s contain equal inner contents.", ident).unwrap();
1292+
writeln!(w, "/// Generates a non-cryptographic 64-bit hash of the {}.", ident).unwrap();
12931293
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_hash(o: &{}) -> u64 {{\n", ident, ident).unwrap();
12941294
if types.c_type_has_inner_from_path(&resolved_path) {
12951295
write!(w, "\tif o.inner.is_null() {{ return 0; }}\n").unwrap();

c-bindings-gen/src/types.rs

Lines changed: 66 additions & 24 deletions
Large diffs are not rendered by default.

lightning-c-bindings/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ std = ["bitcoin/std", "lightning/std", "lightning-invoice/std", "lightning-backg
2222
bitcoin = { version = "0.29", default-features = false }
2323
secp256k1 = { version = "0.24", features = ["global-context", "recovery"] }
2424
# Note that the following line is matched by genbindings to update the path
25-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
26-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
27-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
28-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
29-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
25+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
26+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
27+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
28+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
29+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
3030

3131
core2 = { version = "0.3.0", optional = true, default-features = false }
3232

lightning-c-bindings/demo.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,35 @@ int main() {
686686
std::this_thread::yield();
687687
}
688688

689+
// Note that the channel ID is the same as the channel txid reversed as the output index is 0
690+
uint8_t expected_chan_id[32];
691+
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }
692+
693+
while (true) {
694+
EventQueue queue;
695+
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
696+
ev1.process_pending_events(handler);
697+
if (queue.events.size() == 1) {
698+
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
699+
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
700+
break;
701+
}
702+
std::this_thread::yield();
703+
}
704+
705+
LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
706+
while (true) {
707+
EventQueue queue;
708+
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
709+
ev2.process_pending_events(handler);
710+
if (queue.events.size() == 1) {
711+
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
712+
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
713+
break;
714+
}
715+
std::this_thread::yield();
716+
}
717+
689718
LDK::Listen listener1 = ChannelManager_as_Listen(&cm1);
690719
listener1->block_connected(listener1->this_arg, LDKu8slice { .data = channel_open_block, .datalen = sizeof(channel_open_block) }, 1);
691720

@@ -713,11 +742,6 @@ int main() {
713742
PeerManager_process_events(&net1);
714743
PeerManager_process_events(&net2);
715744

716-
// Note that the channel ID is the same as the channel txid reversed as the output index is 0
717-
uint8_t expected_chan_id[32];
718-
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }
719-
720-
LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
721745
while (true) {
722746
EventQueue queue;
723747
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -794,24 +818,26 @@ int main() {
794818
LDK::RouteParameters route_params = RouteParameters_new(PaymentParameters_new(
795819
ChannelManager_get_our_node_id(&cm2), LDKInvoiceFeatures {
796820
.inner = NULL, .is_owned = false
797-
}, Invoice_route_hints(invoice->contents.result), COption_u64Z_none(), 0xffffffff,
798-
1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
821+
}, Hints_clear(Invoice_route_hints(invoice->contents.result)), COption_u64Z_none(),
822+
0xffffffff, 1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
799823
Invoice_min_final_cltv_expiry_delta(invoice->contents.result)),
800824
5000);
801825
random_bytes = entropy_source1.get_secure_random_bytes();
802826

803827
LDK::CResult_RouteLightningErrorZ route = find_route(ChannelManager_get_our_node_id(&cm1), &route_params, &net_graph2, &outbound_channels, logger1, &chan_scorer, &random_bytes.data);
804828

805829
assert(route->result_ok);
806-
LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result);
830+
LDK::CVec_PathZ paths = Route_get_paths(route->contents.result);
807831
assert(paths->datalen == 1);
808-
assert(paths->data[0].datalen == 1);
809-
assert(!memcmp(RouteHop_get_pubkey(&paths->data[0].data[0]).compressed_form,
832+
LDK::CVec_RouteHopZ hops = Path_get_hops(&paths->data[0]);
833+
assert(hops->datalen == 1);
834+
assert(!memcmp(RouteHop_get_pubkey(&hops->data[0]).compressed_form,
810835
ChannelManager_get_our_node_id(&cm2).compressed_form, 33));
811-
assert(RouteHop_get_short_channel_id(&paths->data[0].data[0]) == channel_scid);
836+
assert(RouteHop_get_short_channel_id(&hops->data[0]) == channel_scid);
812837
LDKThirtyTwoBytes payment_secret;
813838
memcpy(payment_secret.data, Invoice_payment_secret(invoice->contents.result), 32);
814-
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, payment_secret, payment_hash);
839+
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment_with_route(&cm1,
840+
route->contents.result, payment_hash, RecipientOnionFields_secret_only(payment_secret), payment_hash);
815841
assert(send_res->result_ok);
816842
}
817843

@@ -991,6 +1017,7 @@ int main() {
9911017
if (outbound_channels->datalen == 1) {
9921018
break;
9931019
}
1020+
std::this_thread::yield();
9941021
}
9951022

9961023
// Send another payment, this time via the retires path
@@ -1103,5 +1130,5 @@ int main() {
11031130
memset(&sk, 42, 32);
11041131
LDKThirtyTwoBytes kdiv_params;
11051132
memset(&kdiv_params, 43, 32);
1106-
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params);
1133+
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params, kdiv_params);
11071134
}

lightning-c-bindings/include/ldk_rust_types.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#else
1111
#define NONNULL_PTR
1212
#endif
13+
struct nativeRefundOpaque;
14+
typedef struct nativeRefundOpaque LDKnativeRefund;
15+
struct nativeRecipientOnionFieldsOpaque;
16+
typedef struct nativeRecipientOnionFieldsOpaque LDKnativeRecipientOnionFields;
1317
struct nativeCounterpartyCommitmentSecretsOpaque;
1418
typedef struct nativeCounterpartyCommitmentSecretsOpaque LDKnativeCounterpartyCommitmentSecrets;
1519
struct nativeTxCreationKeysOpaque;
@@ -40,10 +44,10 @@ struct nativeShutdownScriptOpaque;
4044
typedef struct nativeShutdownScriptOpaque LDKnativeShutdownScript;
4145
struct nativeInvalidShutdownScriptOpaque;
4246
typedef struct nativeInvalidShutdownScriptOpaque LDKnativeInvalidShutdownScript;
43-
struct nativeBlindedPathOpaque;
44-
typedef struct nativeBlindedPathOpaque LDKnativeBlindedPath;
45-
struct nativeBlindedHopOpaque;
46-
typedef struct nativeBlindedHopOpaque LDKnativeBlindedHop;
47+
struct nativeUnsignedInvoiceOpaque;
48+
typedef struct nativeUnsignedInvoiceOpaque LDKnativeUnsignedInvoice;
49+
struct nativeBlindedPayInfoOpaque;
50+
typedef struct nativeBlindedPayInfoOpaque LDKnativeBlindedPayInfo;
4751
struct nativeBackgroundProcessorOpaque;
4852
typedef struct nativeBackgroundProcessorOpaque LDKnativeBackgroundProcessor;
4953
struct nativeDefaultRouterOpaque;
@@ -54,6 +58,10 @@ struct nativeInFlightHtlcsOpaque;
5458
typedef struct nativeInFlightHtlcsOpaque LDKnativeInFlightHtlcs;
5559
struct nativeRouteHopOpaque;
5660
typedef struct nativeRouteHopOpaque LDKnativeRouteHop;
61+
struct nativeBlindedTailOpaque;
62+
typedef struct nativeBlindedTailOpaque LDKnativeBlindedTail;
63+
struct nativePathOpaque;
64+
typedef struct nativePathOpaque LDKnativePath;
5765
struct nativeRouteOpaque;
5866
typedef struct nativeRouteOpaque LDKnativeRoute;
5967
struct nativeRouteParametersOpaque;
@@ -98,6 +106,12 @@ struct nativeBlindedHopFeaturesOpaque;
98106
typedef struct nativeBlindedHopFeaturesOpaque LDKnativeBlindedHopFeatures;
99107
struct nativeChannelTypeFeaturesOpaque;
100108
typedef struct nativeChannelTypeFeaturesOpaque LDKnativeChannelTypeFeatures;
109+
struct nativeOfferOpaque;
110+
typedef struct nativeOfferOpaque LDKnativeOffer;
111+
struct nativeAmountOpaque;
112+
typedef struct nativeAmountOpaque LDKnativeAmount;
113+
struct nativeQuantityOpaque;
114+
typedef struct nativeQuantityOpaque LDKnativeQuantity;
101115
struct nativeNodeIdOpaque;
102116
typedef struct nativeNodeIdOpaque LDKnativeNodeId;
103117
struct nativeNetworkGraphOpaque;
@@ -159,6 +173,8 @@ struct nativeBigSizeOpaque;
159173
typedef struct nativeBigSizeOpaque LDKnativeBigSize;
160174
struct nativeHostnameOpaque;
161175
typedef struct nativeHostnameOpaque LDKnativeHostname;
176+
struct nativeUntrustedStringOpaque;
177+
typedef struct nativeUntrustedStringOpaque LDKnativeUntrustedString;
162178
struct nativePrintableStringOpaque;
163179
typedef struct nativePrintableStringOpaque LDKnativePrintableString;
164180
struct nativeOutPointOpaque;
@@ -185,6 +201,10 @@ struct nativeUtxoFutureOpaque;
185201
typedef struct nativeUtxoFutureOpaque LDKnativeUtxoFuture;
186202
struct nativeOnionMessengerOpaque;
187203
typedef struct nativeOnionMessengerOpaque LDKnativeOnionMessenger;
204+
struct nativeBlindedPathOpaque;
205+
typedef struct nativeBlindedPathOpaque LDKnativeBlindedPath;
206+
struct nativeBlindedHopOpaque;
207+
typedef struct nativeBlindedHopOpaque LDKnativeBlindedHop;
188208
struct nativeInvoiceOpaque;
189209
typedef struct nativeInvoiceOpaque LDKnativeInvoice;
190210
struct nativeSignedRawInvoiceOpaque;
@@ -209,8 +229,6 @@ struct nativeInvoiceSignatureOpaque;
209229
typedef struct nativeInvoiceSignatureOpaque LDKnativeInvoiceSignature;
210230
struct nativePrivateRouteOpaque;
211231
typedef struct nativePrivateRouteOpaque LDKnativePrivateRoute;
212-
struct nativeRapidGossipSyncOpaque;
213-
typedef struct nativeRapidGossipSyncOpaque LDKnativeRapidGossipSync;
214232
struct nativeInitOpaque;
215233
typedef struct nativeInitOpaque LDKnativeInit;
216234
struct nativeErrorMessageOpaque;
@@ -285,13 +303,21 @@ struct nativeLightningErrorOpaque;
285303
typedef struct nativeLightningErrorOpaque LDKnativeLightningError;
286304
struct nativeCommitmentUpdateOpaque;
287305
typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate;
306+
struct nativeUnsignedInvoiceRequestOpaque;
307+
typedef struct nativeUnsignedInvoiceRequestOpaque LDKnativeUnsignedInvoiceRequest;
308+
struct nativeInvoiceRequestOpaque;
309+
typedef struct nativeInvoiceRequestOpaque LDKnativeInvoiceRequest;
288310
struct nativeRecordOpaque;
289311
typedef struct nativeRecordOpaque LDKnativeRecord;
290312
struct nativeFutureOpaque;
291313
typedef struct nativeFutureOpaque LDKnativeFuture;
314+
struct nativeSleeperOpaque;
315+
typedef struct nativeSleeperOpaque LDKnativeSleeper;
292316
struct nativeMonitorUpdateIdOpaque;
293317
typedef struct nativeMonitorUpdateIdOpaque LDKnativeMonitorUpdateId;
294318
struct nativeLockedChannelMonitorOpaque;
295319
typedef struct nativeLockedChannelMonitorOpaque LDKnativeLockedChannelMonitor;
296320
struct nativeChainMonitorOpaque;
297321
typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;
322+
struct nativeRapidGossipSyncOpaque;
323+
typedef struct nativeRapidGossipSyncOpaque LDKnativeRapidGossipSync;

0 commit comments

Comments
 (0)