]> git.bitcoin.ninja Git - ldk-java/commitdiff
[Java] Update batteries and tests to LDK 0.0.121
authorMatt Corallo <git@bluematt.me>
Tue, 23 Jan 2024 23:54:08 +0000 (23:54 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 29 Jan 2024 16:37:42 +0000 (16:37 +0000)
src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
src/test/java/org/ldk/HumanObjectPeerTest.java

index bfa33991c13a31402731543d4dcf860d2d4b469d..2c96bd30ed427f3d6072a847735aa49b622c1db6 100644 (file)
@@ -80,6 +80,7 @@ public class ChannelManagerConstructor {
     private final Logger logger;
     private final EntropySource entropy_source;
     private final NodeSigner node_signer;
+    private final Router router;
 
     /**
      * Exposes the `ProbabilisticScorer` wrapped inside a lock. Don't forget to `close` this lock when you're done with
@@ -158,16 +159,30 @@ public class ChannelManagerConstructor {
         this.scorer = MultiThreadedLockableScore.of(this.prob_scorer.as_Score());
 
         assert(scoring_fee_params != null);
-        DefaultRouter default_router = DefaultRouter.of(this.net_graph, logger, entropy_source.get_secure_random_bytes(), scorer.as_LockableScore(), scoring_fee_params);
-        Router router;
+        DefaultRouter default_router = DefaultRouter.of(this.net_graph, logger, entropy_source, scorer.as_LockableScore(), scoring_fee_params);
         if (router_wrapper != null) {
             router = Router.new_impl(new Router.RouterInterface() {
-                @Override public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
+                @Override
+                public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
                     return router_wrapper.find_route(payer, route_params, first_hops, inflight_htlcs, null, null, default_router);
                 }
-                @Override public Result_RouteLightningErrorZ find_route_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] payment_hash, byte[] payment_id) {
+
+                @Override
+                public Result_RouteLightningErrorZ find_route_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] payment_hash, byte[] payment_id) {
                     return router_wrapper.find_route(payer, route_params, first_hops, inflight_htlcs, payment_hash, payment_id, default_router);
                 }
+
+                @Override
+                public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                    return default_router.as_Router().create_blinded_payment_paths(recipient, first_hops, tlvs, amount_msats);
+                }
+            }, new MessageRouter.MessageRouterInterface() {
+                @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                    return default_router.as_MessageRouter().find_path(sender, peers, destination);
+                }
+                @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                    return default_router.as_MessageRouter().create_blinded_paths(recipient, peers);
+                }
             });
         } else {
             router = default_router.as_Router();
@@ -200,7 +215,7 @@ public class ChannelManagerConstructor {
         this.logger = logger;
         if (filter != null) {
             for (ChannelMonitor monitor : monitors) {
-                monitor.load_outputs_to_watch(filter);
+                monitor.load_outputs_to_watch(filter, logger);
             }
         }
     }
@@ -225,8 +240,7 @@ public class ChannelManagerConstructor {
         this.scorer = MultiThreadedLockableScore.of(this.prob_scorer.as_Score());
 
         assert(scoring_fee_params != null);
-        DefaultRouter default_router = DefaultRouter.of(this.net_graph, logger, entropy_source.get_secure_random_bytes(), scorer.as_LockableScore(), scoring_fee_params);
-        Router router;
+        DefaultRouter default_router = DefaultRouter.of(this.net_graph, logger, entropy_source, scorer.as_LockableScore(), scoring_fee_params);
         if (router_wrapper != null) {
             router = Router.new_impl(new Router.RouterInterface() {
                 @Override public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
@@ -235,6 +249,18 @@ public class ChannelManagerConstructor {
                 @Override public Result_RouteLightningErrorZ find_route_with_id(byte[] payer, RouteParameters route_params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs, byte[] payment_hash, byte[] payment_id) {
                     return router_wrapper.find_route(payer, route_params, first_hops, inflight_htlcs, payment_hash, payment_id, default_router);
                 }
+
+                @Override
+                public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                    return default_router.as_Router().create_blinded_payment_paths(recipient, first_hops, tlvs, amount_msats);
+                }
+            }, new MessageRouter.MessageRouterInterface() {
+                @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                    return default_router.as_MessageRouter().find_path(sender, peers, destination);
+                }
+                @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                    return default_router.as_MessageRouter().create_blinded_paths(recipient, peers);
+                }
             });
         } else {
             router = default_router.as_Router();
@@ -288,7 +314,7 @@ public class ChannelManagerConstructor {
             routing_msg_handler = graph_msg_handler.as_RoutingMessageHandler();
         else
             routing_msg_handler = ignoring_handler.as_RoutingMessageHandler();
-        OnionMessenger messenger = OnionMessenger.of(this.entropy_source, this.node_signer, this.logger, DefaultMessageRouter.of().as_MessageRouter(), channel_manager.as_OffersMessageHandler(), IgnoringMessageHandler.of().as_CustomOnionMessageHandler());
+        OnionMessenger messenger = OnionMessenger.of(this.entropy_source, this.node_signer, this.logger, this.router.get_message_router(), channel_manager.as_OffersMessageHandler(), IgnoringMessageHandler.of().as_CustomOnionMessageHandler());
         this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
                 routing_msg_handler, messenger.as_OnionMessageHandler(),
                 ignoring_handler.as_CustomMessageHandler(), (int)(System.currentTimeMillis() / 1000),
index 322b5695f9f27d265984d658eefe10a804db47e9..5485f3e3d80dbb878ecf35f1670f200f380200fb 100644 (file)
@@ -78,7 +78,7 @@ class HumanObjectPeerTestInstance {
             SignerProvider underlying_sp = underlying_km.as_SignerProvider();
             must_free_objs.add(new WeakReference<>(underlying_sp));
             return SignerProvider.new_impl(new SignerProvider.SignerProviderInterface() {
-                @Override public Result_CVec_u8ZNoneZ get_destination_script() { return underlying_sp.get_destination_script(); }
+                @Override public Result_CVec_u8ZNoneZ get_destination_script(byte[] channel_keys_id) { return underlying_sp.get_destination_script(channel_keys_id); }
                 @Override public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() { return underlying_sp.get_shutdown_scriptpubkey(); }
                 @Override public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, UInt128 user_channel_id) {
                     return underlying_sp.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id);
@@ -99,17 +99,17 @@ class HumanObjectPeerTestInstance {
                             @Override public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages) {
                                 return underlying_cs.validate_holder_commitment(holder_tx, preimages);
                             }
+                            @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
+                                return underlying_cs.validate_counterparty_revocation(idx, secret);
+                            }
                             @Override public byte[] channel_keys_id() { return underlying_cs.channel_keys_id(); }
                             @Override public void provide_channel_parameters(ChannelTransactionParameters channel_parameters) {
                                 underlying_cs.provide_channel_parameters(channel_parameters);
                             }
                         };
                         EcdsaChannelSigner.EcdsaChannelSignerInterface ecsi = new EcdsaChannelSigner.EcdsaChannelSignerInterface() {
-                            @Override public Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages) {
-                                return underlying_ecs.sign_counterparty_commitment(commitment_tx, preimages);
-                            }
-                            @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
-                                return underlying_ecs.validate_counterparty_revocation(idx, secret);
+                            @Override public Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] inbound_htlc_preimages, byte[][] outbound_htlc_preimages) {
+                                return underlying_ecs.sign_counterparty_commitment(commitment_tx, inbound_htlc_preimages, outbound_htlc_preimages);
                             }
                             @Override public Result_ECDSASignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction commitment_tx) {
                                 return underlying_ecs.sign_holder_commitment(commitment_tx);
@@ -438,6 +438,11 @@ class HumanObjectPeerTestInstance {
                         return find_route(payer, route_params, first_hops, inflight_htlcs);
                     }
 
+                    @Override
+                    public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                        return Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ.err();
+                    }
+
                     @Override
                     public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
                         while (true) {
@@ -457,9 +462,16 @@ class HumanObjectPeerTestInstance {
                                 break;
                             }
                         }
-                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, ScoreLookUp.new_impl(new ScoreLookUp.ScoreLookUpInterface() {
-                            @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage, ProbabilisticScoringFeeParameters params) { return 0; }
-                        }), ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger,
+                                ScoreLookUp.new_impl((candidate, usage, params1) -> candidate.source().as_slice()[1]),
+                                ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                    }
+                }, new MessageRouter.MessageRouterInterface() {
+                    @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                        return Result_OnionMessagePathNoneZ.err();
+                    }
+                    @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                        return Result_CVec_BlindedPathZNoneZ.err();
                     }
                 });
                 ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0));
@@ -543,6 +555,11 @@ class HumanObjectPeerTestInstance {
                         return find_route(payer, route_params, first_hops, inflight_htlcs);
                     }
 
+                    @Override
+                    public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                        return Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ.err();
+                    }
+
                     @Override
                     public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
                         while (true) {
@@ -562,9 +579,16 @@ class HumanObjectPeerTestInstance {
                                 break;
                             }
                         }
-                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, ScoreLookUp.new_impl(new ScoreLookUp.ScoreLookUpInterface() {
-                            @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage, ProbabilisticScoringFeeParameters params) { return 0; }
-                        }), ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger,
+                                ScoreLookUp.new_impl((candidate, usage, params1) -> candidate.source().as_slice()[0]),
+                                ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                    }
+                }, new MessageRouter.MessageRouterInterface() {
+                    @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                        return Result_OnionMessagePathNoneZ.err();
+                    }
+                    @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                        return Result_CVec_BlindedPathZNoneZ.err();
                     }
                 });
                 this.setup_route_handler();
@@ -847,7 +871,7 @@ class HumanObjectPeerTestInstance {
 
         UInt128 user_id = new UInt128(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
 
-        Result_ThirtyTwoBytesAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, user_id, null);
+        Result_ThirtyTwoBytesAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, user_id, Option_ThirtyTwoBytesZ.none(), null);
         assert cc_res instanceof Result_ThirtyTwoBytesAPIErrorZ.Result_ThirtyTwoBytesAPIErrorZ_OK;
 
         // Previously, this was a SEGFAULT instead of get_funding_txo() returning null.
@@ -948,7 +972,7 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
         RawBolt11Invoice raw_invoice = signed_raw.raw_invoice();
         byte[] desc_hash = raw_invoice.signable_hash();
         Description raw_invoice_description = raw_invoice.description();
-        String description_string = raw_invoice_description.into_inner();
+        String description_string = raw_invoice_description.into_inner().get_a();
         boolean has_null = false;
         for (byte db : invoice_description.getBytes())
             if (db == 0)
@@ -981,7 +1005,7 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
             RouteHint[] route_hints = ((Result_Bolt11InvoiceSignOrCreationErrorZ.Result_Bolt11InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
 
             Payee payee = Payee.clear(peer2.node_id, route_hints, invoice_features, 42);
-            PaymentParameters pay_params = PaymentParameters.of(payee, Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0]);
+            PaymentParameters pay_params = PaymentParameters.of(payee, Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0], new long[0]);
             RouteParameters route_params = RouteParameters.from_payment_params_and_value(pay_params, 10000000);
             Result_RouteLightningErrorZ route_res = UtilMethods.find_route(
                     peer1.chan_manager.get_our_node_id(), route_params, peer1.net_graph,
@@ -1011,8 +1035,13 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
             payment_res = peer1.chan_manager.send_payment_with_route(r2, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
             assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
         } else {
-            Result_ThirtyTwoBytesPaymentErrorZ send_res = UtilMethods.pay_invoice(((Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res, Retry.attempts(0), peer1.chan_manager);
-            assert send_res instanceof Result_ThirtyTwoBytesPaymentErrorZ.Result_ThirtyTwoBytesPaymentErrorZ_OK;
+            Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ pay_params_res =
+                UtilMethods.payment_parameters_from_invoice(((Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res);
+            assert pay_params_res.is_ok();
+            Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK pay_params =
+                (Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK)pay_params_res;
+            Result_NoneRetryableSendFailureZ pay_res = peer1.chan_manager.send_payment(pay_params.res.get_a(), pay_params.res.get_b(), new byte[32], pay_params.res.get_c(), Retry.attempts(0));
+            assert pay_res.is_ok();
         }
 
         if (reload_peers) {