X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FRouter.mts;h=547f0e4f4dbe9955848e53444b220d92175f65e3;hb=95f752857f468437e0a3717fb94ef24b2f80ae49;hp=b2d179739195689064a306ebb8a8a47742393745;hpb=76982ad5233afc2759d085bb243f33149369ab9b;p=ldk-java diff --git a/ts/structs/Router.mts b/ts/structs/Router.mts index b2d17973..547f0e4f 100644 --- a/ts/structs/Router.mts +++ b/ts/structs/Router.mts @@ -1,4 +1,5 @@ import { TxOut } from '../structs/TxOut.mjs'; +import { BigEndianScalar } from '../structs/BigEndianScalar.mjs'; import { AccessError } from '../enums/AccessError.mjs'; import { COption_NoneZ } from '../enums/COption_NoneZ.mjs'; import { ChannelMonitorUpdateErr } from '../enums/ChannelMonitorUpdateErr.mjs'; @@ -13,9 +14,14 @@ import { Secp256k1Error } from '../enums/Secp256k1Error.mjs'; import { SemanticError } from '../enums/SemanticError.mjs'; import { SiPrefix } from '../enums/SiPrefix.mjs'; import { Bech32Error } from '../structs/Bech32Error.mjs'; +import { BlindedRoute } from '../structs/BlindedRoute.mjs'; +import { Result_BlindedRouteNoneZ } from '../structs/Result_BlindedRouteNoneZ.mjs'; +import { DecodeError } from '../structs/DecodeError.mjs'; +import { Result_BlindedRouteDecodeErrorZ } from '../structs/Result_BlindedRouteDecodeErrorZ.mjs'; +import { BlindedHop } from '../structs/BlindedHop.mjs'; +import { Result_BlindedHopDecodeErrorZ } from '../structs/Result_BlindedHopDecodeErrorZ.mjs'; import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs'; import { CounterpartyCommitmentSecrets } from '../structs/CounterpartyCommitmentSecrets.mjs'; -import { DecodeError } from '../structs/DecodeError.mjs'; import { Result_CounterpartyCommitmentSecretsDecodeErrorZ } from '../structs/Result_CounterpartyCommitmentSecretsDecodeErrorZ.mjs'; import { Result_SecretKeyErrorZ } from '../structs/Result_SecretKeyErrorZ.mjs'; import { Result_PublicKeyErrorZ } from '../structs/Result_PublicKeyErrorZ.mjs'; @@ -93,7 +99,6 @@ import { ClosingSigned } from '../structs/ClosingSigned.mjs'; import { Shutdown } from '../structs/Shutdown.mjs'; import { ChannelReestablish } from '../structs/ChannelReestablish.mjs'; import { ChannelAnnouncement } from '../structs/ChannelAnnouncement.mjs'; -import { NodeAnnouncement } from '../structs/NodeAnnouncement.mjs'; import { ErrorMessage } from '../structs/ErrorMessage.mjs'; import { WarningMessage } from '../structs/WarningMessage.mjs'; import { ErrorAction } from '../structs/ErrorAction.mjs'; @@ -108,7 +113,6 @@ import { Result_NoneChannelMonitorUpdateErrZ } from '../structs/Result_NoneChann import { HTLCUpdate } from '../structs/HTLCUpdate.mjs'; import { MonitorEvent } from '../structs/MonitorEvent.mjs'; import { ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ } from '../structs/ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ.mjs'; -import { Option_C2Tuple_usizeTransactionZZ } from '../structs/Option_C2Tuple_usizeTransactionZZ.mjs'; import { FixedPenaltyScorer } from '../structs/FixedPenaltyScorer.mjs'; import { Result_FixedPenaltyScorerDecodeErrorZ } from '../structs/Result_FixedPenaltyScorerDecodeErrorZ.mjs'; import { TwoTuple_u64u64Z } from '../structs/TwoTuple_u64u64Z.mjs'; @@ -134,6 +138,7 @@ import { Access, AccessInterface } from '../structs/Access.mjs'; import { Option_AccessZ } from '../structs/Option_AccessZ.mjs'; import { Result_boolLightningErrorZ } from '../structs/Result_boolLightningErrorZ.mjs'; import { ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ } from '../structs/ThreeTuple_ChannelAnnouncementChannelUpdateChannelUpdateZ.mjs'; +import { Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ } from '../structs/Option_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ.mjs'; import { Result_NoneLightningErrorZ } from '../structs/Result_NoneLightningErrorZ.mjs'; import { ChannelUpdateInfo } from '../structs/ChannelUpdateInfo.mjs'; import { Result_ChannelUpdateInfoDecodeErrorZ } from '../structs/Result_ChannelUpdateInfoDecodeErrorZ.mjs'; @@ -160,6 +165,8 @@ import { Result_SignatureNoneZ } from '../structs/Result_SignatureNoneZ.mjs'; import { TwoTuple_SignatureSignatureZ } from '../structs/TwoTuple_SignatureSignatureZ.mjs'; import { Result_C2Tuple_SignatureSignatureZNoneZ } from '../structs/Result_C2Tuple_SignatureSignatureZNoneZ.mjs'; import { Result_SecretKeyNoneZ } from '../structs/Result_SecretKeyNoneZ.mjs'; +import { Option_ScalarZ } from '../structs/Option_ScalarZ.mjs'; +import { Result_SharedSecretNoneZ } from '../structs/Result_SharedSecretNoneZ.mjs'; import { ClosingTransaction } from '../structs/ClosingTransaction.mjs'; import { UnsignedChannelAnnouncement } from '../structs/UnsignedChannelAnnouncement.mjs'; import { BaseSign, BaseSignInterface } from '../structs/BaseSign.mjs'; @@ -209,6 +216,8 @@ import { Option_TypeZ } from '../structs/Option_TypeZ.mjs'; import { Result_COption_TypeZDecodeErrorZ } from '../structs/Result_COption_TypeZDecodeErrorZ.mjs'; import { PaymentError } from '../structs/PaymentError.mjs'; import { Result_PaymentIdPaymentErrorZ } from '../structs/Result_PaymentIdPaymentErrorZ.mjs'; +import { InFlightHtlcs } from '../structs/InFlightHtlcs.mjs'; +import { Result_InFlightHtlcsDecodeErrorZ } from '../structs/Result_InFlightHtlcsDecodeErrorZ.mjs'; import { ParseError } from '../structs/ParseError.mjs'; import { Result_SiPrefixParseErrorZ } from '../structs/Result_SiPrefixParseErrorZ.mjs'; import { Invoice } from '../structs/Invoice.mjs'; @@ -248,6 +257,8 @@ import { PeerHandleError } from '../structs/PeerHandleError.mjs'; import { Result_CVec_u8ZPeerHandleErrorZ } from '../structs/Result_CVec_u8ZPeerHandleErrorZ.mjs'; import { Result_NonePeerHandleErrorZ } from '../structs/Result_NonePeerHandleErrorZ.mjs'; import { Result_boolPeerHandleErrorZ } from '../structs/Result_boolPeerHandleErrorZ.mjs'; +import { SendError } from '../structs/SendError.mjs'; +import { Result_NoneSendErrorZ } from '../structs/Result_NoneSendErrorZ.mjs'; import { Result_NoneErrorZ } from '../structs/Result_NoneErrorZ.mjs'; import { Result_NetAddressDecodeErrorZ } from '../structs/Result_NetAddressDecodeErrorZ.mjs'; import { UpdateAddHTLC } from '../structs/UpdateAddHTLC.mjs'; @@ -276,6 +287,8 @@ import { UpdateFee } from '../structs/UpdateFee.mjs'; import { Result_UpdateFeeDecodeErrorZ } from '../structs/Result_UpdateFeeDecodeErrorZ.mjs'; import { Result_UpdateFulfillHTLCDecodeErrorZ } from '../structs/Result_UpdateFulfillHTLCDecodeErrorZ.mjs'; import { Result_UpdateAddHTLCDecodeErrorZ } from '../structs/Result_UpdateAddHTLCDecodeErrorZ.mjs'; +import { OnionMessage } from '../structs/OnionMessage.mjs'; +import { Result_OnionMessageDecodeErrorZ } from '../structs/Result_OnionMessageDecodeErrorZ.mjs'; import { Ping } from '../structs/Ping.mjs'; import { Result_PingDecodeErrorZ } from '../structs/Result_PingDecodeErrorZ.mjs'; import { Pong } from '../structs/Pong.mjs'; @@ -289,6 +302,7 @@ import { Result_ErrorMessageDecodeErrorZ } from '../structs/Result_ErrorMessageD import { Result_WarningMessageDecodeErrorZ } from '../structs/Result_WarningMessageDecodeErrorZ.mjs'; import { UnsignedNodeAnnouncement } from '../structs/UnsignedNodeAnnouncement.mjs'; import { Result_UnsignedNodeAnnouncementDecodeErrorZ } from '../structs/Result_UnsignedNodeAnnouncementDecodeErrorZ.mjs'; +import { NodeAnnouncement } from '../structs/NodeAnnouncement.mjs'; import { Result_NodeAnnouncementDecodeErrorZ } from '../structs/Result_NodeAnnouncementDecodeErrorZ.mjs'; import { Result_QueryShortChannelIdsDecodeErrorZ } from '../structs/Result_QueryShortChannelIdsDecodeErrorZ.mjs'; import { ReplyShortChannelIdsEnd } from '../structs/ReplyShortChannelIdsEnd.mjs'; @@ -304,13 +318,17 @@ import { Option_FilterZ } from '../structs/Option_FilterZ.mjs'; import { LockedChannelMonitor } from '../structs/LockedChannelMonitor.mjs'; import { Result_LockedChannelMonitorNoneZ } from '../structs/Result_LockedChannelMonitorNoneZ.mjs'; import { MessageSendEventsProvider, MessageSendEventsProviderInterface } from '../structs/MessageSendEventsProvider.mjs'; +import { OnionMessageProvider, OnionMessageProviderInterface } from '../structs/OnionMessageProvider.mjs'; import { EventHandler, EventHandlerInterface } from '../structs/EventHandler.mjs'; import { EventsProvider, EventsProviderInterface } from '../structs/EventsProvider.mjs'; import { BigSize } from '../structs/BigSize.mjs'; import { ChannelUsage } from '../structs/ChannelUsage.mjs'; import { Score, ScoreInterface } from '../structs/Score.mjs'; -import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScore.mjs'; +import { LockableScore, LockableScoreInterface } from '../structs/LockableScore.mjs'; +import { WriteableScore, WriteableScoreInterface } from '../structs/WriteableScore.mjs'; import { Persister, PersisterInterface } from '../structs/Persister.mjs'; +import { FutureCallback, FutureCallbackInterface } from '../structs/FutureCallback.mjs'; +import { Future } from '../structs/Future.mjs'; import { ChannelHandshakeConfig } from '../structs/ChannelHandshakeConfig.mjs'; import { ChannelHandshakeLimits } from '../structs/ChannelHandshakeLimits.mjs'; import { UserConfig } from '../structs/UserConfig.mjs'; @@ -328,6 +346,7 @@ import { ChannelManagerReadArgs } from '../structs/ChannelManagerReadArgs.mjs'; import { ExpandedKey } from '../structs/ExpandedKey.mjs'; import { DataLossProtect } from '../structs/DataLossProtect.mjs'; import { RoutingMessageHandler, RoutingMessageHandlerInterface } from '../structs/RoutingMessageHandler.mjs'; +import { OnionMessageHandler, OnionMessageHandlerInterface } from '../structs/OnionMessageHandler.mjs'; import { CustomMessageReader, CustomMessageReaderInterface } from '../structs/CustomMessageReader.mjs'; import { CustomMessageHandler, CustomMessageHandlerInterface } from '../structs/CustomMessageHandler.mjs'; import { IgnoringMessageHandler } from '../structs/IgnoringMessageHandler.mjs'; @@ -340,8 +359,11 @@ import { ReadOnlyNetworkGraph } from '../structs/ReadOnlyNetworkGraph.mjs'; import { P2PGossipSync } from '../structs/P2PGossipSync.mjs'; import { DirectedChannelInfo } from '../structs/DirectedChannelInfo.mjs'; import { EffectiveCapacity } from '../structs/EffectiveCapacity.mjs'; -import { LockableScore, LockableScoreInterface } from '../structs/LockableScore.mjs'; +import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScore.mjs'; +import { MultiThreadedScoreLock } from '../structs/MultiThreadedScoreLock.mjs'; import { ProbabilisticScoringParameters } from '../structs/ProbabilisticScoringParameters.mjs'; +import { OnionMessenger } from '../structs/OnionMessenger.mjs'; +import { Destination } from '../structs/Destination.mjs'; import { RawDataPart } from '../structs/RawDataPart.mjs'; import { Sha256 } from '../structs/Sha256.mjs'; import { ExpiryTime } from '../structs/ExpiryTime.mjs'; @@ -364,7 +386,19 @@ export interface RouterInterface { * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ - find_route(payer: Uint8Array, route_params: RouteParameters, payment_hash: Uint8Array, first_hops: ChannelDetails[], scorer: Score): Result_RouteLightningErrorZ; + find_route(payer: Uint8Array, route_params: RouteParameters, payment_hash: Uint8Array, first_hops: ChannelDetails[], inflight_htlcs: InFlightHtlcs): Result_RouteLightningErrorZ; + /**Lets the router know that payment through a specific path has failed. + */ + notify_payment_path_failed(path: RouteHop[], short_channel_id: bigint): void; + /**Lets the router know that payment through a specific path was successful. + */ + notify_payment_path_successful(path: RouteHop[]): void; + /**Lets the router know that a payment probe was successful. + */ + notify_payment_probe_successful(path: RouteHop[]): void; + /**Lets the router know that a payment probe failed. + */ + notify_payment_probe_failed(path: RouteHop[], short_channel_id: bigint): void; } class LDKRouterHolder { @@ -378,6 +412,9 @@ export class Router extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKRouter; + /* @internal */ + public instance_idx?: number; + /* @internal */ constructor(_dummy: object, ptr: bigint) { super(ptr, bindings.Router_free); @@ -388,7 +425,7 @@ export class Router extends CommonBase { public static new_impl(arg: RouterInterface): Router { const impl_holder: LDKRouterHolder = new LDKRouterHolder(); let structImplementation = { - find_route (payer: number, route_params: bigint, payment_hash: number, first_hops: number, scorer: bigint): bigint { + find_route (payer: number, route_params: bigint, payment_hash: number, first_hops: number, inflight_htlcs: bigint): bigint { const payer_conv: Uint8Array = bindings.decodeUint8Array(payer); const route_params_hu_conv: RouteParameters = new RouteParameters(null, route_params); const payment_hash_conv: Uint8Array = bindings.decodeUint8Array(payment_hash); @@ -401,16 +438,65 @@ export class Router extends CommonBase { first_hops_conv_16_arr[q] = first_hops_conv_16_hu_conv; } bindings.freeWasmMemory(first_hops) - const ret_hu_conv: Score = new Score(null, scorer); - CommonBase.add_ref_from(ret_hu_conv, this); - const ret: Result_RouteLightningErrorZ = arg.find_route(payer_conv, route_params_hu_conv, payment_hash_conv, first_hops_conv_16_arr, ret_hu_conv); + const inflight_htlcs_hu_conv: InFlightHtlcs = new InFlightHtlcs(null, inflight_htlcs); + CommonBase.add_ref_from(inflight_htlcs_hu_conv, this); + const ret: Result_RouteLightningErrorZ = arg.find_route(payer_conv, route_params_hu_conv, payment_hash_conv, first_hops_conv_16_arr, inflight_htlcs_hu_conv); const result: bigint = ret == null ? 0n : ret.clone_ptr(); return result; }, + notify_payment_path_failed (path: number, short_channel_id: bigint): void { + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: bigint = bindings.getU64ArrayElem(path, k); + const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); + CommonBase.add_ref_from(path_conv_10_hu_conv, this); + path_conv_10_arr[k] = path_conv_10_hu_conv; + } + bindings.freeWasmMemory(path) + arg.notify_payment_path_failed(path_conv_10_arr, short_channel_id); + }, + notify_payment_path_successful (path: number): void { + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: bigint = bindings.getU64ArrayElem(path, k); + const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); + CommonBase.add_ref_from(path_conv_10_hu_conv, this); + path_conv_10_arr[k] = path_conv_10_hu_conv; + } + bindings.freeWasmMemory(path) + arg.notify_payment_path_successful(path_conv_10_arr); + }, + notify_payment_probe_successful (path: number): void { + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: bigint = bindings.getU64ArrayElem(path, k); + const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); + CommonBase.add_ref_from(path_conv_10_hu_conv, this); + path_conv_10_arr[k] = path_conv_10_hu_conv; + } + bindings.freeWasmMemory(path) + arg.notify_payment_probe_successful(path_conv_10_arr); + }, + notify_payment_probe_failed (path: number, short_channel_id: bigint): void { + const path_conv_10_len: number = bindings.getArrayLength(path); + const path_conv_10_arr: RouteHop[] = new Array(path_conv_10_len).fill(null); + for (var k = 0; k < path_conv_10_len; k++) { + const path_conv_10: bigint = bindings.getU64ArrayElem(path, k); + const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10); + CommonBase.add_ref_from(path_conv_10_hu_conv, this); + path_conv_10_arr[k] = path_conv_10_hu_conv; + } + bindings.freeWasmMemory(path) + arg.notify_payment_probe_failed(path_conv_10_arr, short_channel_id); + }, } as bindings.LDKRouter; - const ptr: bigint = bindings.LDKRouter_new(structImplementation); + const ptr_idx: [bigint, number] = bindings.LDKRouter_new(structImplementation); - impl_holder.held = new Router(null, ptr); + impl_holder.held = new Router(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; impl_holder.held.bindings_instance = structImplementation; return impl_holder.held; } @@ -420,13 +506,53 @@ export class Router extends CommonBase { * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ - public find_route(payer: Uint8Array, route_params: RouteParameters, payment_hash: Uint8Array, first_hops: ChannelDetails[], scorer: Score): Result_RouteLightningErrorZ { - const ret: bigint = bindings.Router_find_route(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(payer, 33)), route_params == null ? 0n : CommonBase.get_ptr_of(route_params), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), bindings.encodeUint64Array(first_hops != null ? first_hops.map(first_hops_conv_16 => first_hops_conv_16 == null ? 0n : CommonBase.get_ptr_of(first_hops_conv_16)) : null), scorer == null ? 0n : CommonBase.get_ptr_of(scorer)); + public find_route(payer: Uint8Array, route_params: RouteParameters, payment_hash: Uint8Array, first_hops: ChannelDetails[], inflight_htlcs: InFlightHtlcs): Result_RouteLightningErrorZ { + const ret: bigint = bindings.Router_find_route(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(payer, 33)), route_params == null ? 0n : CommonBase.get_ptr_of(route_params), bindings.encodeUint8Array(bindings.check_arr_len(payment_hash, 32)), bindings.encodeUint64Array(first_hops != null ? first_hops.map(first_hops_conv_16 => first_hops_conv_16 == null ? 0n : CommonBase.get_ptr_of(first_hops_conv_16)) : null), inflight_htlcs == null ? 0n : CommonBase.get_ptr_of(inflight_htlcs)); const ret_hu_conv: Result_RouteLightningErrorZ = Result_RouteLightningErrorZ.constr_from_ptr(ret); CommonBase.add_ref_from(this, route_params); first_hops.forEach((first_hops_conv_16: ChannelDetails) => { CommonBase.add_ref_from(this, first_hops_conv_16); }); - CommonBase.add_ref_from(this, scorer); + CommonBase.add_ref_from(this, inflight_htlcs); + // Due to rust's strict-ownership memory model, in some cases we need to "move" + // an object to pass exclusive ownership to the function being called. + // In most cases, we avoid this being visible in GC'd languages by cloning the object + // at the FFI layer, creating a new object which Rust can claim ownership of + // However, in some cases (eg here), there is no way to clone an object, and thus + // we actually have to pass full ownership to Rust. + // Thus, after this call, inflight_htlcs is reset to null and is now a dummy object. + CommonBase.set_null_skip_free(inflight_htlcs);; return ret_hu_conv; } + /** + * Lets the router know that payment through a specific path has failed. + */ + public notify_payment_path_failed(path: RouteHop[], short_channel_id: bigint): void { + bindings.Router_notify_payment_path_failed(this.ptr, bindings.encodeUint64Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0n : CommonBase.get_ptr_of(path_conv_10)) : null), short_channel_id); + path.forEach((path_conv_10: RouteHop) => { CommonBase.add_ref_from(this, path_conv_10); }); + } + + /** + * Lets the router know that payment through a specific path was successful. + */ + public notify_payment_path_successful(path: RouteHop[]): void { + bindings.Router_notify_payment_path_successful(this.ptr, bindings.encodeUint64Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0n : CommonBase.get_ptr_of(path_conv_10)) : null)); + path.forEach((path_conv_10: RouteHop) => { CommonBase.add_ref_from(this, path_conv_10); }); + } + + /** + * Lets the router know that a payment probe was successful. + */ + public notify_payment_probe_successful(path: RouteHop[]): void { + bindings.Router_notify_payment_probe_successful(this.ptr, bindings.encodeUint64Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0n : CommonBase.get_ptr_of(path_conv_10)) : null)); + path.forEach((path_conv_10: RouteHop) => { CommonBase.add_ref_from(this, path_conv_10); }); + } + + /** + * Lets the router know that a payment probe failed. + */ + public notify_payment_probe_failed(path: RouteHop[], short_channel_id: bigint): void { + bindings.Router_notify_payment_probe_failed(this.ptr, bindings.encodeUint64Array(path != null ? path.map(path_conv_10 => path_conv_10 == null ? 0n : CommonBase.get_ptr_of(path_conv_10)) : null), short_channel_id); + path.forEach((path_conv_10: RouteHop) => { CommonBase.add_ref_from(this, path_conv_10); }); + } + }