Skip to content

Update to LDK 0.0.115 #103

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

Merged
merged 10 commits into from
Apr 26, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.114-bindings
git checkout 0.0.115-bindings
- name: Fix Github Actions to not be broken
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
- name: Rebuild bindings without std, and check the sample app builds + links
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.114-bindings
git checkout 0.0.115-bindings
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
run: ./genbindings.sh ./rust-lightning true
- name: Rebuild bindings using upstream clang, and check the sample app builds + links
Expand Down
4 changes: 2 additions & 2 deletions c-bindings-gen/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
match token_iter.next().unwrap() {
TokenTree::Literal(lit) => {
// Drop the first and last chars from lit as they are always "
let doc = format!("{}", lit);
let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}//!", prefix));
writeln!(w, "{}//!{}", prefix, &doc[1..doc.len() - 1]).unwrap();
},
_ => unimplemented!(),
Expand All @@ -452,7 +452,7 @@ fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribut
match token_iter.next().unwrap() {
TokenTree::Literal(lit) => {
// Drop the first and last chars from lit as they are always "
let doc = format!("{}", lit);
let doc = format!("{}", lit).trim().replace("\n", &format!("\n{}///", prefix));
writeln!(w, "{}///{}", prefix, &doc[1..doc.len() - 1]).unwrap();
},
_ => unimplemented!(),
Expand Down
2 changes: 1 addition & 1 deletion c-bindings-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa

writeln!(w, " {{ true }} else {{ false }}\n}}").unwrap();
} else if path_matches_nongeneric(&trait_path.1, &["core", "hash", "Hash"]) {
writeln!(w, "/// Checks if two {}s contain equal inner contents.", ident).unwrap();
writeln!(w, "/// Generates a non-cryptographic 64-bit hash of the {}.", ident).unwrap();
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_hash(o: &{}) -> u64 {{\n", ident, ident).unwrap();
if types.c_type_has_inner_from_path(&resolved_path) {
write!(w, "\tif o.inner.is_null() {{ return 0; }}\n").unwrap();
Expand Down
90 changes: 66 additions & 24 deletions c-bindings-gen/src/types.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lightning-c-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ std = ["bitcoin/std", "lightning/std", "lightning-invoice/std", "lightning-backg
bitcoin = { version = "0.29", default-features = false }
secp256k1 = { version = "0.24", features = ["global-context", "recovery"] }
# Note that the following line is matched by genbindings to update the path
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.114-bindings", default-features = false }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.115-bindings", default-features = false }

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

Expand Down
53 changes: 40 additions & 13 deletions lightning-c-bindings/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,35 @@ int main() {
std::this_thread::yield();
}

// Note that the channel ID is the same as the channel txid reversed as the output index is 0
uint8_t expected_chan_id[32];
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }

while (true) {
EventQueue queue;
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
ev1.process_pending_events(handler);
if (queue.events.size() == 1) {
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
break;
}
std::this_thread::yield();
}

LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
while (true) {
EventQueue queue;
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
ev2.process_pending_events(handler);
if (queue.events.size() == 1) {
assert(queue.events[0]->tag == LDKEvent_ChannelPending);
assert(!memcmp(queue.events[0]->channel_pending.channel_id.data, expected_chan_id, 32));
break;
}
std::this_thread::yield();
}

LDK::Listen listener1 = ChannelManager_as_Listen(&cm1);
listener1->block_connected(listener1->this_arg, LDKu8slice { .data = channel_open_block, .datalen = sizeof(channel_open_block) }, 1);

Expand Down Expand Up @@ -713,11 +742,6 @@ int main() {
PeerManager_process_events(&net1);
PeerManager_process_events(&net2);

// Note that the channel ID is the same as the channel txid reversed as the output index is 0
uint8_t expected_chan_id[32];
for (int i = 0; i < 32; i++) { expected_chan_id[i] = channel_open_txid[31-i]; }

LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider(&cm2);
while (true) {
EventQueue queue;
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
Expand Down Expand Up @@ -794,24 +818,26 @@ int main() {
LDK::RouteParameters route_params = RouteParameters_new(PaymentParameters_new(
ChannelManager_get_our_node_id(&cm2), LDKInvoiceFeatures {
.inner = NULL, .is_owned = false
}, Invoice_route_hints(invoice->contents.result), COption_u64Z_none(), 0xffffffff,
1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
}, Hints_clear(Invoice_route_hints(invoice->contents.result)), COption_u64Z_none(),
0xffffffff, 1, 2, LDKCVec_u64Z { .data = NULL, .datalen = 0 },
Invoice_min_final_cltv_expiry_delta(invoice->contents.result)),
5000);
random_bytes = entropy_source1.get_secure_random_bytes();

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

assert(route->result_ok);
LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result);
LDK::CVec_PathZ paths = Route_get_paths(route->contents.result);
assert(paths->datalen == 1);
assert(paths->data[0].datalen == 1);
assert(!memcmp(RouteHop_get_pubkey(&paths->data[0].data[0]).compressed_form,
LDK::CVec_RouteHopZ hops = Path_get_hops(&paths->data[0]);
assert(hops->datalen == 1);
assert(!memcmp(RouteHop_get_pubkey(&hops->data[0]).compressed_form,
ChannelManager_get_our_node_id(&cm2).compressed_form, 33));
assert(RouteHop_get_short_channel_id(&paths->data[0].data[0]) == channel_scid);
assert(RouteHop_get_short_channel_id(&hops->data[0]) == channel_scid);
LDKThirtyTwoBytes payment_secret;
memcpy(payment_secret.data, Invoice_payment_secret(invoice->contents.result), 32);
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment(&cm1, route->contents.result, payment_hash, payment_secret, payment_hash);
LDK::CResult_NonePaymentSendFailureZ send_res = ChannelManager_send_payment_with_route(&cm1,
route->contents.result, payment_hash, RecipientOnionFields_secret_only(payment_secret), payment_hash);
assert(send_res->result_ok);
}

Expand Down Expand Up @@ -991,6 +1017,7 @@ int main() {
if (outbound_channels->datalen == 1) {
break;
}
std::this_thread::yield();
}

// Send another payment, this time via the retires path
Expand Down Expand Up @@ -1103,5 +1130,5 @@ int main() {
memset(&sk, 42, 32);
LDKThirtyTwoBytes kdiv_params;
memset(&kdiv_params, 43, 32);
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params);
LDK::InMemorySigner signer = InMemorySigner_new(sk, sk, sk, sk, sk, random_bytes, 42, kdiv_params, kdiv_params);
}
38 changes: 32 additions & 6 deletions lightning-c-bindings/include/ldk_rust_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#else
#define NONNULL_PTR
#endif
struct nativeRefundOpaque;
typedef struct nativeRefundOpaque LDKnativeRefund;
struct nativeRecipientOnionFieldsOpaque;
typedef struct nativeRecipientOnionFieldsOpaque LDKnativeRecipientOnionFields;
struct nativeCounterpartyCommitmentSecretsOpaque;
typedef struct nativeCounterpartyCommitmentSecretsOpaque LDKnativeCounterpartyCommitmentSecrets;
struct nativeTxCreationKeysOpaque;
Expand Down Expand Up @@ -40,10 +44,10 @@ struct nativeShutdownScriptOpaque;
typedef struct nativeShutdownScriptOpaque LDKnativeShutdownScript;
struct nativeInvalidShutdownScriptOpaque;
typedef struct nativeInvalidShutdownScriptOpaque LDKnativeInvalidShutdownScript;
struct nativeBlindedPathOpaque;
typedef struct nativeBlindedPathOpaque LDKnativeBlindedPath;
struct nativeBlindedHopOpaque;
typedef struct nativeBlindedHopOpaque LDKnativeBlindedHop;
struct nativeUnsignedInvoiceOpaque;
typedef struct nativeUnsignedInvoiceOpaque LDKnativeUnsignedInvoice;
struct nativeBlindedPayInfoOpaque;
typedef struct nativeBlindedPayInfoOpaque LDKnativeBlindedPayInfo;
struct nativeBackgroundProcessorOpaque;
typedef struct nativeBackgroundProcessorOpaque LDKnativeBackgroundProcessor;
struct nativeDefaultRouterOpaque;
Expand All @@ -54,6 +58,10 @@ struct nativeInFlightHtlcsOpaque;
typedef struct nativeInFlightHtlcsOpaque LDKnativeInFlightHtlcs;
struct nativeRouteHopOpaque;
typedef struct nativeRouteHopOpaque LDKnativeRouteHop;
struct nativeBlindedTailOpaque;
typedef struct nativeBlindedTailOpaque LDKnativeBlindedTail;
struct nativePathOpaque;
typedef struct nativePathOpaque LDKnativePath;
struct nativeRouteOpaque;
typedef struct nativeRouteOpaque LDKnativeRoute;
struct nativeRouteParametersOpaque;
Expand Down Expand Up @@ -98,6 +106,12 @@ struct nativeBlindedHopFeaturesOpaque;
typedef struct nativeBlindedHopFeaturesOpaque LDKnativeBlindedHopFeatures;
struct nativeChannelTypeFeaturesOpaque;
typedef struct nativeChannelTypeFeaturesOpaque LDKnativeChannelTypeFeatures;
struct nativeOfferOpaque;
typedef struct nativeOfferOpaque LDKnativeOffer;
struct nativeAmountOpaque;
typedef struct nativeAmountOpaque LDKnativeAmount;
struct nativeQuantityOpaque;
typedef struct nativeQuantityOpaque LDKnativeQuantity;
struct nativeNodeIdOpaque;
typedef struct nativeNodeIdOpaque LDKnativeNodeId;
struct nativeNetworkGraphOpaque;
Expand Down Expand Up @@ -159,6 +173,8 @@ struct nativeBigSizeOpaque;
typedef struct nativeBigSizeOpaque LDKnativeBigSize;
struct nativeHostnameOpaque;
typedef struct nativeHostnameOpaque LDKnativeHostname;
struct nativeUntrustedStringOpaque;
typedef struct nativeUntrustedStringOpaque LDKnativeUntrustedString;
struct nativePrintableStringOpaque;
typedef struct nativePrintableStringOpaque LDKnativePrintableString;
struct nativeOutPointOpaque;
Expand All @@ -185,6 +201,10 @@ struct nativeUtxoFutureOpaque;
typedef struct nativeUtxoFutureOpaque LDKnativeUtxoFuture;
struct nativeOnionMessengerOpaque;
typedef struct nativeOnionMessengerOpaque LDKnativeOnionMessenger;
struct nativeBlindedPathOpaque;
typedef struct nativeBlindedPathOpaque LDKnativeBlindedPath;
struct nativeBlindedHopOpaque;
typedef struct nativeBlindedHopOpaque LDKnativeBlindedHop;
struct nativeInvoiceOpaque;
typedef struct nativeInvoiceOpaque LDKnativeInvoice;
struct nativeSignedRawInvoiceOpaque;
Expand All @@ -209,8 +229,6 @@ struct nativeInvoiceSignatureOpaque;
typedef struct nativeInvoiceSignatureOpaque LDKnativeInvoiceSignature;
struct nativePrivateRouteOpaque;
typedef struct nativePrivateRouteOpaque LDKnativePrivateRoute;
struct nativeRapidGossipSyncOpaque;
typedef struct nativeRapidGossipSyncOpaque LDKnativeRapidGossipSync;
struct nativeInitOpaque;
typedef struct nativeInitOpaque LDKnativeInit;
struct nativeErrorMessageOpaque;
Expand Down Expand Up @@ -285,13 +303,21 @@ struct nativeLightningErrorOpaque;
typedef struct nativeLightningErrorOpaque LDKnativeLightningError;
struct nativeCommitmentUpdateOpaque;
typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate;
struct nativeUnsignedInvoiceRequestOpaque;
typedef struct nativeUnsignedInvoiceRequestOpaque LDKnativeUnsignedInvoiceRequest;
struct nativeInvoiceRequestOpaque;
typedef struct nativeInvoiceRequestOpaque LDKnativeInvoiceRequest;
struct nativeRecordOpaque;
typedef struct nativeRecordOpaque LDKnativeRecord;
struct nativeFutureOpaque;
typedef struct nativeFutureOpaque LDKnativeFuture;
struct nativeSleeperOpaque;
typedef struct nativeSleeperOpaque LDKnativeSleeper;
struct nativeMonitorUpdateIdOpaque;
typedef struct nativeMonitorUpdateIdOpaque LDKnativeMonitorUpdateId;
struct nativeLockedChannelMonitorOpaque;
typedef struct nativeLockedChannelMonitorOpaque LDKnativeLockedChannelMonitor;
struct nativeChainMonitorOpaque;
typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;
struct nativeRapidGossipSyncOpaque;
typedef struct nativeRapidGossipSyncOpaque LDKnativeRapidGossipSync;
Loading