diff --git a/Cargo.lock b/Cargo.lock index adbb645c1d..765706fd3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1890,17 +1890,17 @@ dependencies = [ "esplora-client 0.12.3", "ldk-node 0.6.2", "libc", - "lightning 0.3.0+git", - "lightning-background-processor 0.2.0+git", - "lightning-block-sync 0.2.0+git", - "lightning-invoice 0.34.0+git", - "lightning-liquidity 0.2.0+git", - "lightning-macros 0.2.0+git", - "lightning-net-tokio 0.2.0+git", - "lightning-persister 0.2.0+git", - "lightning-rapid-gossip-sync 0.2.0+git", - "lightning-transaction-sync 0.2.0+git", - "lightning-types 0.3.0+git", + "lightning 0.2.5", + "lightning-background-processor 0.2.3", + "lightning-block-sync 0.2.0", + "lightning-invoice 0.34.1", + "lightning-liquidity 0.2.3", + "lightning-macros 0.2.1", + "lightning-net-tokio 0.2.0", + "lightning-persister 0.2.3", + "lightning-rapid-gossip-sync 0.2.3", + "lightning-transaction-sync 0.2.1", + "lightning-types 0.3.5", "lnd_grpc_rust", "log", "proptest", @@ -1971,24 +1971,24 @@ dependencies = [ "libm", "lightning-invoice 0.33.2", "lightning-types 0.2.0", - "possiblyrandom 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "possiblyrandom 0.2.0", ] [[package]] name = "lightning" -version = "0.3.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.5" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bech32", "bitcoin", "dnssec-prover", "hashbrown 0.13.2", "libm", - "lightning-invoice 0.34.0+git", - "lightning-macros 0.2.0+git", - "lightning-types 0.3.0+git", + "lightning-invoice 0.34.1", + "lightning-macros 0.2.1", + "lightning-types 0.3.5", "musig2", - "possiblyrandom 0.2.0 (git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix)", + "possiblyrandom 0.2.1", "regex", ] @@ -2007,16 +2007,16 @@ dependencies = [ [[package]] name = "lightning-background-processor" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.3" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", "bitcoin-io", "bitcoin_hashes", - "lightning 0.3.0+git", - "lightning-liquidity 0.2.0+git", - "lightning-rapid-gossip-sync 0.2.0+git", - "possiblyrandom 0.2.0 (git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix)", + "lightning 0.2.5", + "lightning-liquidity 0.2.3", + "lightning-rapid-gossip-sync 0.2.3", + "possiblyrandom 0.2.1", ] [[package]] @@ -2034,12 +2034,12 @@ dependencies = [ [[package]] name = "lightning-block-sync" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.0" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", "chunked_transfer", - "lightning 0.3.0+git", + "lightning 0.2.5", "serde_json", "tokio", ] @@ -2058,12 +2058,12 @@ dependencies = [ [[package]] name = "lightning-invoice" -version = "0.34.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.34.1" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bech32", "bitcoin", - "lightning-types 0.3.0+git", + "lightning-types 0.3.5", "serde", ] @@ -2084,15 +2084,15 @@ dependencies = [ [[package]] name = "lightning-liquidity" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.3" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", "chrono", - "lightning 0.3.0+git", - "lightning-invoice 0.34.0+git", - "lightning-macros 0.2.0+git", - "lightning-types 0.3.0+git", + "lightning 0.2.5", + "lightning-invoice 0.34.1", + "lightning-macros 0.2.1", + "lightning-types 0.3.5", "serde", "serde_json", ] @@ -2110,8 +2110,8 @@ dependencies = [ [[package]] name = "lightning-macros" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.1" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "proc-macro2", "quote", @@ -2131,11 +2131,11 @@ dependencies = [ [[package]] name = "lightning-net-tokio" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.0" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", - "lightning 0.3.0+git", + "lightning 0.2.5", "tokio", ] @@ -2152,11 +2152,11 @@ dependencies = [ [[package]] name = "lightning-persister" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.3" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", - "lightning 0.3.0+git", + "lightning 0.2.5", "tokio", "windows-sys 0.48.0", ] @@ -2175,13 +2175,13 @@ dependencies = [ [[package]] name = "lightning-rapid-gossip-sync" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.3" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", "bitcoin-io", "bitcoin_hashes", - "lightning 0.3.0+git", + "lightning 0.2.5", ] [[package]] @@ -2200,15 +2200,15 @@ dependencies = [ [[package]] name = "lightning-transaction-sync" -version = "0.2.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.1" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", "electrum-client 0.24.1", "esplora-client 0.12.3", "futures", - "lightning 0.3.0+git", - "lightning-macros 0.2.0+git", + "lightning 0.2.5", + "lightning-macros 0.2.1", ] [[package]] @@ -2222,8 +2222,8 @@ dependencies = [ [[package]] name = "lightning-types" -version = "0.3.0+git" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.3.5" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "bitcoin", ] @@ -2650,8 +2650,8 @@ dependencies = [ [[package]] name = "possiblyrandom" -version = "0.2.0" -source = "git+https://github.com/ZeusLN/rust-lightning?branch=lsps7-for-ldk-node-close-fix#a7fa715285f940e25f721516371eac59956ccf32" +version = "0.2.1" +source = "git+https://github.com/ZeusLN/rust-lightning?branch=zeus-0.2#24130051a9766467bbfece5ef909e2aa3729c985" dependencies = [ "getrandom 0.2.17", ] diff --git a/Cargo.toml b/Cargo.toml index 0b655e49fd..a08ab2dd6d 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,17 +39,17 @@ default = [] #lightning-liquidity = { version = "0.2.0", features = ["std"] } #lightning-macros = { version = "0.2.0" } -lightning = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["std"] } -lightning-types = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix" } -lightning-invoice = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["std"] } -lightning-net-tokio = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix" } -lightning-persister = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["tokio"] } -lightning-background-processor = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix" } -lightning-rapid-gossip-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix" } -lightning-block-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["rest-client", "rpc-client", "tokio"] } -lightning-transaction-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["esplora-async-https", "time", "electrum-rustls-ring"] } -lightning-liquidity = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["std"] } -lightning-macros = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix" } +lightning = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["std"] } +lightning-types = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2" } +lightning-invoice = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["std"] } +lightning-net-tokio = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2" } +lightning-persister = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["tokio"] } +lightning-background-processor = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2" } +lightning-rapid-gossip-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2" } +lightning-block-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["rest-client", "rpc-client", "tokio"] } +lightning-transaction-sync = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["esplora-async-https", "time", "electrum-rustls-ring"] } +lightning-liquidity = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["std"] } +lightning-macros = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2" } bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] } bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]} @@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false} winapi = { version = "0.3", features = ["winbase"] } [dev-dependencies] -lightning = { git = "https://github.com/ZeusLN/rust-lightning", branch = "lsps7-for-ldk-node-close-fix", features = ["std", "_test_utils"] } +lightning = { git = "https://github.com/ZeusLN/rust-lightning", branch = "zeus-0.2", features = ["std", "_test_utils"] } proptest = "1.0.0" regex = "1.5.6" criterion = { version = "0.7.0", features = ["async_tokio"] } diff --git a/Package.swift b/Package.swift index a74dfef5a5..2c667d3c39 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let tag = "v0.7.0" -let checksum = "073c332d846ad2e6863fe3f7bbfe02a378cbed9286d9057c9b2c5500fb816365" +let checksum = "649c2c08ff6870220eb8c3871728c9791c40215040a0e9714963130dd0394d98" let url = "https://github.com/lightningdevkit/ldk-node/releases/download/\(tag)/LDKNodeFFI.xcframework.zip" let package = Package( diff --git a/benches/payments.rs b/benches/payments.rs index ba69e046d4..c854049a37 100644 --- a/benches/payments.rs +++ b/benches/payments.rs @@ -40,6 +40,7 @@ fn spawn_payment(node_a: Arc, node_b: Arc, amount_msat: u64) { node_b.node_id(), preimage, None, + None, ); match payment_id { @@ -109,6 +110,7 @@ async fn send_payments(node_a: Arc, node_b: Arc) -> std::time::Durat node_a.node_id(), PaymentPreimage(preimage_bytes), None, + None, ) .ok() .unwrap(); diff --git a/bindings/swift/Sources/LDKNode/LDKNode.swift b/bindings/swift/Sources/LDKNode/LDKNode.swift index d4a10f584c..4a6a3a5b44 100644 --- a/bindings/swift/Sources/LDKNode/LDKNode.swift +++ b/bindings/swift/Sources/LDKNode/LDKNode.swift @@ -849,18 +849,26 @@ public protocol Bolt11PaymentProtocol : AnyObject { func receiveForHash(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash) throws -> Bolt11Invoice + func receiveForHashWithRouteHints(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash, routeHints: RouteHints) throws -> Bolt11Invoice + func receiveVariableAmount(description: Bolt11InvoiceDescription, expirySecs: UInt32) throws -> Bolt11Invoice func receiveVariableAmountForHash(description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash) throws -> Bolt11Invoice + func receiveVariableAmountForHashWithRouteHints(description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash, routeHints: RouteHints) throws -> Bolt11Invoice + func receiveVariableAmountViaJitChannel(description: Bolt11InvoiceDescription, expirySecs: UInt32, maxProportionalLspFeeLimitPpmMsat: UInt64?) throws -> Bolt11Invoice func receiveVariableAmountViaJitChannelForHash(description: Bolt11InvoiceDescription, expirySecs: UInt32, maxProportionalLspFeeLimitPpmMsat: UInt64?, paymentHash: PaymentHash) throws -> Bolt11Invoice + func receiveVariableAmountWithRouteHints(description: Bolt11InvoiceDescription, expirySecs: UInt32, routeHints: RouteHints) throws -> Bolt11Invoice + func receiveViaJitChannel(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, maxLspFeeLimitMsat: UInt64?) throws -> Bolt11Invoice func receiveViaJitChannelForHash(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, maxLspFeeLimitMsat: UInt64?, paymentHash: PaymentHash) throws -> Bolt11Invoice + func receiveWithRouteHints(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, routeHints: RouteHints) throws -> Bolt11Invoice + func send(invoice: Bolt11Invoice, routeParameters: RouteParametersConfig?, paymentTimeoutSecs: UInt64?) throws -> PaymentId func sendProbes(invoice: Bolt11Invoice, routeParameters: RouteParametersConfig?) throws @@ -958,6 +966,18 @@ open func receiveForHash(amountMsat: UInt64, description: Bolt11InvoiceDescripti }) } +open func receiveForHashWithRouteHints(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash, routeHints: RouteHints)throws -> Bolt11Invoice { + return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_receive_for_hash_with_route_hints(self.uniffiClonePointer(), + FfiConverterUInt64.lower(amountMsat), + FfiConverterTypeBolt11InvoiceDescription.lower(description), + FfiConverterUInt32.lower(expirySecs), + FfiConverterTypePaymentHash.lower(paymentHash), + FfiConverterTypeRouteHints.lower(routeHints),$0 + ) +}) +} + open func receiveVariableAmount(description: Bolt11InvoiceDescription, expirySecs: UInt32)throws -> Bolt11Invoice { return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { uniffi_ldk_node_fn_method_bolt11payment_receive_variable_amount(self.uniffiClonePointer(), @@ -977,6 +997,17 @@ open func receiveVariableAmountForHash(description: Bolt11InvoiceDescription, ex }) } +open func receiveVariableAmountForHashWithRouteHints(description: Bolt11InvoiceDescription, expirySecs: UInt32, paymentHash: PaymentHash, routeHints: RouteHints)throws -> Bolt11Invoice { + return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_receive_variable_amount_for_hash_with_route_hints(self.uniffiClonePointer(), + FfiConverterTypeBolt11InvoiceDescription.lower(description), + FfiConverterUInt32.lower(expirySecs), + FfiConverterTypePaymentHash.lower(paymentHash), + FfiConverterTypeRouteHints.lower(routeHints),$0 + ) +}) +} + open func receiveVariableAmountViaJitChannel(description: Bolt11InvoiceDescription, expirySecs: UInt32, maxProportionalLspFeeLimitPpmMsat: UInt64?)throws -> Bolt11Invoice { return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { uniffi_ldk_node_fn_method_bolt11payment_receive_variable_amount_via_jit_channel(self.uniffiClonePointer(), @@ -998,6 +1029,16 @@ open func receiveVariableAmountViaJitChannelForHash(description: Bolt11InvoiceDe }) } +open func receiveVariableAmountWithRouteHints(description: Bolt11InvoiceDescription, expirySecs: UInt32, routeHints: RouteHints)throws -> Bolt11Invoice { + return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_receive_variable_amount_with_route_hints(self.uniffiClonePointer(), + FfiConverterTypeBolt11InvoiceDescription.lower(description), + FfiConverterUInt32.lower(expirySecs), + FfiConverterTypeRouteHints.lower(routeHints),$0 + ) +}) +} + open func receiveViaJitChannel(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, maxLspFeeLimitMsat: UInt64?)throws -> Bolt11Invoice { return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { uniffi_ldk_node_fn_method_bolt11payment_receive_via_jit_channel(self.uniffiClonePointer(), @@ -1021,6 +1062,17 @@ open func receiveViaJitChannelForHash(amountMsat: UInt64, description: Bolt11Inv }) } +open func receiveWithRouteHints(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32, routeHints: RouteHints)throws -> Bolt11Invoice { + return try FfiConverterTypeBolt11Invoice.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_receive_with_route_hints(self.uniffiClonePointer(), + FfiConverterUInt64.lower(amountMsat), + FfiConverterTypeBolt11InvoiceDescription.lower(description), + FfiConverterUInt32.lower(expirySecs), + FfiConverterTypeRouteHints.lower(routeHints),$0 + ) +}) +} + open func send(invoice: Bolt11Invoice, routeParameters: RouteParametersConfig?, paymentTimeoutSecs: UInt64?)throws -> PaymentId { return try FfiConverterTypePaymentId.lift(try rustCallWithError(FfiConverterTypeNodeError.lift) { uniffi_ldk_node_fn_method_bolt11payment_send(self.uniffiClonePointer(), @@ -10290,6 +10342,80 @@ extension QrPaymentResult: Equatable, Hashable {} +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum RouteHints { + + case none + case automatic + case custom(userChannelIds: [UserChannelId] + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeRouteHints: FfiConverterRustBuffer { + typealias SwiftType = RouteHints + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RouteHints { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .none + + case 2: return .automatic + + case 3: return .custom(userChannelIds: try FfiConverterSequenceTypeUserChannelId.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: RouteHints, into buf: inout [UInt8]) { + switch value { + + + case .none: + writeInt(&buf, Int32(1)) + + + case .automatic: + writeInt(&buf, Int32(2)) + + + case let .custom(userChannelIds): + writeInt(&buf, Int32(3)) + FfiConverterSequenceTypeUserChannelId.write(userChannelIds, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteHints_lift(_ buf: RustBuffer) throws -> RouteHints { + return try FfiConverterTypeRouteHints.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeRouteHints_lower(_ value: RouteHints) -> RustBuffer { + return FfiConverterTypeRouteHints.lower(value) +} + + + +extension RouteHints: Equatable, Hashable {} + + + public enum VssHeaderProviderError { @@ -12083,6 +12209,31 @@ fileprivate struct FfiConverterSequenceTypeSocketAddress: FfiConverterRustBuffer } } +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeUserChannelId: FfiConverterRustBuffer { + typealias SwiftType = [UserChannelId] + + public static func write(_ value: [UserChannelId], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeUserChannelId.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UserChannelId] { + let len: Int32 = try readInt(&buf) + var seq = [UserChannelId]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeUserChannelId.read(from: &buf)) + } + return seq + } +} + #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -13129,24 +13280,36 @@ private var initializationResult: InitializationResult = { if (uniffi_ldk_node_checksum_method_bolt11payment_receive_for_hash() != 27050) { return InitializationResult.apiChecksumMismatch } + if (uniffi_ldk_node_checksum_method_bolt11payment_receive_for_hash_with_route_hints() != 62426) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount() != 4893) { return InitializationResult.apiChecksumMismatch } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount_for_hash() != 1402) { return InitializationResult.apiChecksumMismatch } + if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount_for_hash_with_route_hints() != 42267) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount_via_jit_channel() != 24506) { return InitializationResult.apiChecksumMismatch } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount_via_jit_channel_for_hash() != 38025) { return InitializationResult.apiChecksumMismatch } + if (uniffi_ldk_node_checksum_method_bolt11payment_receive_variable_amount_with_route_hints() != 44813) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_via_jit_channel() != 16532) { return InitializationResult.apiChecksumMismatch } if (uniffi_ldk_node_checksum_method_bolt11payment_receive_via_jit_channel_for_hash() != 1143) { return InitializationResult.apiChecksumMismatch } + if (uniffi_ldk_node_checksum_method_bolt11payment_receive_with_route_hints() != 6817) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_ldk_node_checksum_method_bolt11payment_send() != 53480) { return InitializationResult.apiChecksumMismatch } diff --git a/src/builder.rs b/src/builder.rs index 348364538b..6373777e64 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -73,9 +73,8 @@ use crate::peer_store::PeerStore; use crate::runtime::Runtime; use crate::tx_broadcaster::TransactionBroadcaster; use crate::types::{ - ChainMonitor, ChannelManager, ClosedChannelStore, DynStore, DynStoreWrapper, GossipSync, Graph, - KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, - SyncAndAsyncKVStore, + ChainMonitor, ChannelManager, ClosedChannelStore, DynStore, GossipSync, Graph, KeysManager, + MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, }; use crate::wallet::persist::KVStoreWalletPersister; use crate::wallet::Wallet; @@ -566,12 +565,14 @@ impl NodeBuilder { let storage_dir_path = self.config.storage_dir_path.clone(); fs::create_dir_all(storage_dir_path.clone()) .map_err(|_| BuildError::StoragePathAccessFailed)?; - let kv_store = SqliteStore::new( - storage_dir_path.into(), - Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()), - Some(io::sqlite_store::KV_TABLE_NAME.to_string()), - ) - .map_err(|_| BuildError::KVStoreSetupFailed)?; + let kv_store = Arc::new( + SqliteStore::new( + storage_dir_path.into(), + Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()), + Some(io::sqlite_store::KV_TABLE_NAME.to_string()), + ) + .map_err(|_| BuildError::KVStoreSetupFailed)?, + ); self.build_with_store(node_entropy, kv_store) } @@ -583,7 +584,7 @@ impl NodeBuilder { fs::create_dir_all(storage_dir_path.clone()) .map_err(|_| BuildError::StoragePathAccessFailed)?; - let kv_store = FilesystemStore::new(storage_dir_path); + let kv_store = Arc::new(FilesystemStore::new(storage_dir_path)); self.build_with_store(node_entropy, kv_store) } @@ -615,7 +616,7 @@ impl NodeBuilder { BuildError::KVStoreSetupFailed })?; - self.build_with_store(node_entropy, vss_store) + self.build_with_store(node_entropy, Arc::new(vss_store)) } /// Builds a [`Node`] instance with a [VSS] backend and according to the options @@ -642,7 +643,7 @@ impl NodeBuilder { BuildError::KVStoreSetupFailed })?; - self.build_with_store(node_entropy, vss_store) + self.build_with_store(node_entropy, Arc::new(vss_store)) } /// Builds a [`Node`] instance with a [VSS] backend and according to the options @@ -667,7 +668,7 @@ impl NodeBuilder { BuildError::KVStoreSetupFailed })?; - self.build_with_store(node_entropy, vss_store) + self.build_with_store(node_entropy, Arc::new(vss_store)) } /// Builds a [`Node`] instance with a dual-write store (VSS + local SQLite) backend and @@ -704,7 +705,7 @@ impl NodeBuilder { .map_err(|_| BuildError::KVStoreSetupFailed)?; let dual_store = DualStore::new(vss_store, local_store); - self.build_with_store(node_entropy, dual_store) + self.build_with_store(node_entropy, Arc::new(dual_store)) } /// Builds a [`Node`] instance with a dual-write store (VSS + local SQLite) backend and @@ -739,12 +740,12 @@ impl NodeBuilder { .map_err(|_| BuildError::KVStoreSetupFailed)?; let dual_store = DualStore::new(vss_store, local_store); - self.build_with_store(node_entropy, dual_store) + self.build_with_store(node_entropy, Arc::new(dual_store)) } /// Builds a [`Node`] instance according to the options previously configured. - pub fn build_with_store( - &self, node_entropy: NodeEntropy, kv_store: S, + pub fn build_with_store( + &self, node_entropy: NodeEntropy, kv_store: Arc, ) -> Result { let logger = setup_logger(&self.log_writer_config, &self.config)?; @@ -770,7 +771,7 @@ impl NodeBuilder { seed_bytes, runtime, logger, - Arc::new(DynStoreWrapper(kv_store)), + kv_store, ) } } @@ -1161,10 +1162,8 @@ impl ArcedNodeBuilder { } /// Builds a [`Node`] instance according to the options previously configured. - // Note that the generics here don't actually work for Uniffi, but we don't currently expose - // this so its not needed. - pub fn build_with_store( - &self, node_entropy: Arc, kv_store: S, + pub fn build_with_store( + &self, node_entropy: Arc, kv_store: Arc, ) -> Result, BuildError> { self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new) } diff --git a/src/chain/bitcoind.rs b/src/chain/bitcoind.rs index e1dcff7670..04a5e546e5 100644 --- a/src/chain/bitcoind.rs +++ b/src/chain/bitcoind.rs @@ -6,7 +6,6 @@ // accordance with one or both of these licenses. use std::collections::{HashMap, VecDeque}; -use std::future::Future; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; @@ -24,7 +23,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader}; use lightning_block_sync::rest::RestClient; use lightning_block_sync::rpc::{RpcClient, RpcError}; use lightning_block_sync::{ - BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache, + AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache, SpvClient, }; use serde::Serialize; @@ -656,34 +655,26 @@ impl std::ops::Deref for UtxoSourceClient { impl BlockSource for UtxoSourceClient { fn get_header<'a>( &'a self, header_hash: &'a BlockHash, height_hint: Option, - ) -> impl Future> + 'a { - async move { - match self { - Self::Rpc(client) => client.get_header(header_hash, height_hint).await, - Self::Rest(client) => client.get_header(header_hash, height_hint).await, - } + ) -> AsyncBlockSourceResult<'a, BlockHeaderData> { + match self { + Self::Rpc(client) => client.get_header(header_hash, height_hint), + Self::Rest(client) => client.get_header(header_hash, height_hint), } } fn get_block<'a>( &'a self, header_hash: &'a BlockHash, - ) -> impl Future> + 'a { - async move { - match self { - Self::Rpc(client) => client.get_block(header_hash).await, - Self::Rest(client) => client.get_block(header_hash).await, - } + ) -> AsyncBlockSourceResult<'a, BlockData> { + match self { + Self::Rpc(client) => client.get_block(header_hash), + Self::Rest(client) => client.get_block(header_hash), } } - fn get_best_block<'a>( - &'a self, - ) -> impl Future), BlockSourceError>> + 'a { - async move { - match self { - Self::Rpc(client) => client.get_best_block().await, - Self::Rest(client) => client.get_best_block().await, - } + fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (BlockHash, Option)> { + match self { + Self::Rpc(client) => client.get_best_block(), + Self::Rest(client) => client.get_best_block(), } } } @@ -691,23 +682,17 @@ impl BlockSource for UtxoSourceClient { impl UtxoSource for UtxoSourceClient { fn get_block_hash_by_height<'a>( &'a self, block_height: u32, - ) -> impl Future> + 'a { - async move { - match self { - Self::Rpc(client) => client.get_block_hash_by_height(block_height).await, - Self::Rest(client) => client.get_block_hash_by_height(block_height).await, - } + ) -> AsyncBlockSourceResult<'a, BlockHash> { + match self { + Self::Rpc(client) => client.get_block_hash_by_height(block_height), + Self::Rest(client) => client.get_block_hash_by_height(block_height), } } - fn is_output_unspent<'a>( - &'a self, outpoint: OutPoint, - ) -> impl Future> + 'a { - async move { - match self { - Self::Rpc(client) => client.is_output_unspent(outpoint).await, - Self::Rest(client) => client.is_output_unspent(outpoint).await, - } + fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> { + match self { + Self::Rpc(client) => client.is_output_unspent(outpoint), + Self::Rest(client) => client.is_output_unspent(outpoint), } } } @@ -1260,40 +1245,38 @@ impl BitcoindClient { impl BlockSource for BitcoindClient { fn get_header<'a>( &'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option, - ) -> impl Future> + 'a { - async move { - match self { - BitcoindClient::Rpc { rpc_client, .. } => { - rpc_client.get_header(header_hash, height_hint).await - }, - BitcoindClient::Rest { rest_client, .. } => { - rest_client.get_header(header_hash, height_hint).await - }, - } + ) -> AsyncBlockSourceResult<'a, BlockHeaderData> { + match self { + BitcoindClient::Rpc { rpc_client, .. } => { + Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await }) + }, + BitcoindClient::Rest { rest_client, .. } => { + Box::pin(async move { rest_client.get_header(header_hash, height_hint).await }) + }, } } fn get_block<'a>( &'a self, header_hash: &'a bitcoin::BlockHash, - ) -> impl Future> + 'a { - async move { - match self { - BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await, - BitcoindClient::Rest { rest_client, .. } => { - rest_client.get_block(header_hash).await - }, - } + ) -> AsyncBlockSourceResult<'a, BlockData> { + match self { + BitcoindClient::Rpc { rpc_client, .. } => { + Box::pin(async move { rpc_client.get_block(header_hash).await }) + }, + BitcoindClient::Rest { rest_client, .. } => { + Box::pin(async move { rest_client.get_block(header_hash).await }) + }, } } - fn get_best_block<'a>( - &'a self, - ) -> impl Future), BlockSourceError>> + 'a { - async move { - match self { - BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await, - BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await, - } + fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option)> { + match self { + BitcoindClient::Rpc { rpc_client, .. } => { + Box::pin(async move { rpc_client.get_best_block().await }) + }, + BitcoindClient::Rest { rest_client, .. } => { + Box::pin(async move { rest_client.get_best_block().await }) + }, } } } diff --git a/src/data_store.rs b/src/data_store.rs index d295ece514..87bd831c9b 100644 --- a/src/data_store.rs +++ b/src/data_store.rs @@ -177,7 +177,6 @@ mod tests { use super::*; use crate::hex_utils; use crate::io::test_utils::InMemoryStore; - use crate::types::DynStoreWrapper; #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] struct TestObjectId { @@ -236,7 +235,7 @@ mod tests { #[test] fn data_is_persisted() { - let store: Arc = Arc::new(DynStoreWrapper(InMemoryStore::new())); + let store: Arc = Arc::new(InMemoryStore::new()); let logger = Arc::new(TestLogger::new()); let primary_namespace = "datastore_test_primary".to_string(); let secondary_namespace = "datastore_test_secondary".to_string(); diff --git a/src/event.rs b/src/event.rs index bf117c181b..684e9de9ae 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1831,11 +1831,10 @@ mod tests { use super::*; use crate::io::test_utils::InMemoryStore; - use crate::types::DynStoreWrapper; #[tokio::test] async fn event_queue_persistence() { - let store: Arc = Arc::new(DynStoreWrapper(InMemoryStore::new())); + let store: Arc = Arc::new(InMemoryStore::new()); let logger = Arc::new(TestLogger::new()); let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger))); assert_eq!(event_queue.next_event(), None); @@ -1873,7 +1872,7 @@ mod tests { #[tokio::test] async fn event_queue_concurrency() { - let store: Arc = Arc::new(DynStoreWrapper(InMemoryStore::new())); + let store: Arc = Arc::new(InMemoryStore::new()); let logger = Arc::new(TestLogger::new()); let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger))); assert_eq!(event_queue.next_event(), None); diff --git a/src/io/dual_store.rs b/src/io/dual_store.rs index 0081ce19d3..f91885a9e6 100644 --- a/src/io/dual_store.rs +++ b/src/io/dual_store.rs @@ -35,6 +35,7 @@ //! 60-second timeout and does not block node startup. use std::future::Future; +use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -516,29 +517,29 @@ impl KVStoreSync for DualStore { impl KVStore for DualStore { fn read( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let result = KVStoreSync::read(self, primary_namespace, secondary_namespace, key); - async move { result } + Box::pin(async move { result }) } fn write( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let result = KVStoreSync::write(self, primary_namespace, secondary_namespace, key, buf); - async move { result } + Box::pin(async move { result }) } fn remove( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let result = KVStoreSync::remove(self, primary_namespace, secondary_namespace, key, lazy); - async move { result } + Box::pin(async move { result }) } fn list( &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let result = KVStoreSync::list(self, primary_namespace, secondary_namespace); - async move { result } + Box::pin(async move { result }) } } diff --git a/src/io/sqlite_store/mod.rs b/src/io/sqlite_store/mod.rs index 772b359817..ee23eada22 100644 --- a/src/io/sqlite_store/mod.rs +++ b/src/io/sqlite_store/mod.rs @@ -6,10 +6,12 @@ // accordance with one or both of these licenses. //! Objects related to [`SqliteStore`] live here. +use std::boxed::Box; use std::collections::HashMap; use std::fs; use std::future::Future; use std::path::PathBuf; +use std::pin::Pin; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; @@ -121,7 +123,7 @@ impl SqliteStore { impl KVStore for SqliteStore { fn read( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); @@ -129,17 +131,17 @@ impl KVStore for SqliteStore { let fut = tokio::task::spawn_blocking(move || { inner.read_internal(&primary_namespace, &secondary_namespace, &key) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn write( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key); let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone()); let primary_namespace = primary_namespace.to_string(); @@ -157,17 +159,17 @@ impl KVStore for SqliteStore { buf, ) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn remove( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key); let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone()); let primary_namespace = primary_namespace.to_string(); @@ -184,29 +186,29 @@ impl KVStore for SqliteStore { &key, ) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn list( &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let inner = Arc::clone(&self.inner); let fut = tokio::task::spawn_blocking(move || { inner.list_internal(&primary_namespace, &secondary_namespace) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } } diff --git a/src/io/test_utils.rs b/src/io/test_utils.rs index 6eb04df3f7..f7ae6fee69 100644 --- a/src/io/test_utils.rs +++ b/src/io/test_utils.rs @@ -5,10 +5,12 @@ // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in // accordance with one or both of these licenses. +use std::boxed::Box; use std::collections::{hash_map, HashMap}; use std::future::Future; use std::panic::RefUnwindSafe; use std::path::PathBuf; +use std::pin::Pin; use std::sync::Mutex; use lightning::events::ClosureReason; @@ -104,27 +106,27 @@ impl InMemoryStore { impl KVStore for InMemoryStore { fn read( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + 'static + Send>> { let res = self.read_internal(&primary_namespace, &secondary_namespace, &key); - async move { res } + Box::pin(async move { res }) } fn write( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + 'static + Send { + ) -> Pin> + 'static + Send>> { let res = self.write_internal(&primary_namespace, &secondary_namespace, &key, buf); - async move { res } + Box::pin(async move { res }) } fn remove( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> impl Future> + 'static + Send { + ) -> Pin> + 'static + Send>> { let res = self.remove_internal(&primary_namespace, &secondary_namespace, &key, lazy); - async move { res } + Box::pin(async move { res }) } fn list( &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + 'static + Send>> { let res = self.list_internal(primary_namespace, secondary_namespace); - async move { res } + Box::pin(async move { res }) } } @@ -329,6 +331,7 @@ pub(crate) fn do_test_store(store_0: &K, store_1: &K) { &nodes[0], 1, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message }, + false, &[nodes[1].node.get_our_node_id()], 100000, ); @@ -344,7 +347,7 @@ pub(crate) fn do_test_store(store_0: &K, store_1: &K) { check_closed_broadcast!(nodes[1], true); let reason = ClosureReason::CommitmentTxConfirmed; let node_id_0 = nodes[0].node.get_our_node_id(); - check_closed_event(&nodes[1], 1, reason, &[node_id_0], 100000); + check_closed_event(&nodes[1], 1, reason, false, &[node_id_0], 100000); check_added_monitors!(nodes[1], 1); // Make sure everything is persisted as expected after close. diff --git a/src/io/vss_store.rs b/src/io/vss_store.rs index 4f33d85994..ee507cba23 100644 --- a/src/io/vss_store.rs +++ b/src/io/vss_store.rs @@ -13,6 +13,7 @@ use std::fmt; use std::future::Future; #[cfg(test)] use std::panic::RefUnwindSafe; +use std::pin::Pin; use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -278,27 +279,27 @@ impl KVStoreSync for VssStore { impl KVStore for VssStore { fn read( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); let inner = Arc::clone(&self.inner); - async move { + Box::pin(async move { inner .read_internal(&inner.async_client, primary_namespace, secondary_namespace, key) .await - } + }) } fn write( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key); let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone()); let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); let inner = Arc::clone(&self.inner); - async move { + Box::pin(async move { inner .write_internal( &inner.async_client, @@ -311,11 +312,11 @@ impl KVStore for VssStore { buf, ) .await - } + }) } fn remove( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key); let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone()); let primary_namespace = primary_namespace.to_string(); @@ -335,24 +336,22 @@ impl KVStore for VssStore { ) .await }; - async move { - if lazy { - tokio::task::spawn(async move { fut.await }); - Ok(()) - } else { - fut.await - } + if lazy { + tokio::task::spawn(async { fut.await }); + Box::pin(async { Ok(()) }) + } else { + Box::pin(async { fut.await }) } } fn list( &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let inner = Arc::clone(&self.inner); - async move { + Box::pin(async move { inner.list_internal(&inner.async_client, primary_namespace, secondary_namespace).await - } + }) } } diff --git a/src/lib.rs b/src/lib.rs index 5e3ebab618..3f82e583b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,10 +163,11 @@ use rand::Rng; use runtime::Runtime; use types::{ Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, ClosedChannelStore, - DynStore, Graph, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, - Sweeper, Wallet, + Graph, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, Wallet, +}; +pub use types::{ + ChannelDetails, CustomTlvRecord, DynStore, PeerDetails, SyncAndAsyncKVStore, UserChannelId, }; -pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId}; pub use { bip39, bitcoin, lightning, lightning_invoice, lightning_liquidity, lightning_types, tokio, vss_client, diff --git a/src/payment/asynchronous/static_invoice_store.rs b/src/payment/asynchronous/static_invoice_store.rs index cd0e2ebd28..45125cfee3 100644 --- a/src/payment/asynchronous/static_invoice_store.rs +++ b/src/payment/asynchronous/static_invoice_store.rs @@ -161,11 +161,11 @@ mod tests { use crate::io::test_utils::InMemoryStore; use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore; - use crate::types::{DynStore, DynStoreWrapper}; + use crate::types::DynStore; #[tokio::test] async fn static_invoice_store_test() { - let store: Arc = Arc::new(DynStoreWrapper(InMemoryStore::new())); + let store: Arc = Arc::new(InMemoryStore::new()); let static_invoice_store = StaticInvoiceStore::new(Arc::clone(&store)); let static_invoice = invoice(); diff --git a/src/peer_store.rs b/src/peer_store.rs index ce8a9810ee..59cd3d94f0 100644 --- a/src/peer_store.rs +++ b/src/peer_store.rs @@ -156,11 +156,10 @@ mod tests { use super::*; use crate::io::test_utils::InMemoryStore; - use crate::types::DynStoreWrapper; #[test] fn peer_info_persistence() { - let store: Arc = Arc::new(DynStoreWrapper(InMemoryStore::new())); + let store: Arc = Arc::new(InMemoryStore::new()); let logger = Arc::new(TestLogger::new()); let peer_store = PeerStore::new(Arc::clone(&store), Arc::clone(&logger)); diff --git a/src/scoring.rs b/src/scoring.rs index 6385f2f56b..e85abade3e 100644 --- a/src/scoring.rs +++ b/src/scoring.rs @@ -12,8 +12,7 @@ use crate::config::{ use crate::io::utils::write_external_pathfinding_scores_to_cache; use crate::logger::LdkLogger; use crate::runtime::Runtime; -use crate::types::DynStore; -use crate::{write_node_metrics, Logger, NodeMetrics, Scorer}; +use crate::{write_node_metrics, DynStore, Logger, NodeMetrics, Scorer}; /// Start a background task that periodically downloads scores via an external url and merges them into the local /// pathfinding scores. diff --git a/src/types.rs b/src/types.rs index 47e9a677a1..51f71d7a50 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,8 +6,6 @@ // accordance with one or both of these licenses. use std::fmt; -use std::future::Future; -use std::pin::Pin; use std::sync::{Arc, Mutex}; use bitcoin::secp256k1::PublicKey; @@ -51,139 +49,8 @@ where { } -pub(crate) trait DynStoreTrait: Send + Sync { - fn read_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> Pin, bitcoin::io::Error>> + Send + 'static>>; - fn write_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> Pin> + Send + 'static>>; - fn remove_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> Pin> + Send + 'static>>; - fn list_async( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> Pin, bitcoin::io::Error>> + Send + 'static>>; - - fn read( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> Result, bitcoin::io::Error>; - fn write( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> Result<(), bitcoin::io::Error>; - fn remove( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> Result<(), bitcoin::io::Error>; - fn list( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> Result, bitcoin::io::Error>; -} - -impl<'a> KVStore for dyn DynStoreTrait + 'a { - fn read( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, bitcoin::io::Error>> + Send + 'static { - DynStoreTrait::read_async(self, primary_namespace, secondary_namespace, key) - } - - fn write( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + Send + 'static { - DynStoreTrait::write_async(self, primary_namespace, secondary_namespace, key, buf) - } - - fn remove( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> impl Future> + Send + 'static { - DynStoreTrait::remove_async(self, primary_namespace, secondary_namespace, key, lazy) - } - - fn list( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, bitcoin::io::Error>> + Send + 'static { - DynStoreTrait::list_async(self, primary_namespace, secondary_namespace) - } -} - -impl<'a> KVStoreSync for dyn DynStoreTrait + 'a { - fn read( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> Result, bitcoin::io::Error> { - DynStoreTrait::read(self, primary_namespace, secondary_namespace, key) - } - - fn write( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> Result<(), bitcoin::io::Error> { - DynStoreTrait::write(self, primary_namespace, secondary_namespace, key, buf) - } - - fn remove( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> Result<(), bitcoin::io::Error> { - DynStoreTrait::remove(self, primary_namespace, secondary_namespace, key, lazy) - } - - fn list( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> Result, bitcoin::io::Error> { - DynStoreTrait::list(self, primary_namespace, secondary_namespace) - } -} - -pub(crate) type DynStore = dyn DynStoreTrait; - -pub(crate) struct DynStoreWrapper(pub(crate) T); - -impl DynStoreTrait for DynStoreWrapper { - fn read_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> Pin, bitcoin::io::Error>> + Send + 'static>> { - Box::pin(KVStore::read(&self.0, primary_namespace, secondary_namespace, key)) - } - - fn write_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> Pin> + Send + 'static>> { - Box::pin(KVStore::write(&self.0, primary_namespace, secondary_namespace, key, buf)) - } - - fn remove_async( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> Pin> + Send + 'static>> { - Box::pin(KVStore::remove(&self.0, primary_namespace, secondary_namespace, key, lazy)) - } - - fn list_async( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> Pin, bitcoin::io::Error>> + Send + 'static>> { - Box::pin(KVStore::list(&self.0, primary_namespace, secondary_namespace)) - } - - fn read( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> Result, bitcoin::io::Error> { - KVStoreSync::read(&self.0, primary_namespace, secondary_namespace, key) - } - - fn write( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> Result<(), bitcoin::io::Error> { - KVStoreSync::write(&self.0, primary_namespace, secondary_namespace, key, buf) - } - - fn remove( - &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> Result<(), bitcoin::io::Error> { - KVStoreSync::remove(&self.0, primary_namespace, secondary_namespace, key, lazy) - } - - fn list( - &self, primary_namespace: &str, secondary_namespace: &str, - ) -> Result, bitcoin::io::Error> { - KVStoreSync::list(&self.0, primary_namespace, secondary_namespace) - } -} +/// A type alias for [`SyncAndAsyncKVStore`] with `Sync`/`Send` markers; +pub type DynStore = dyn SyncAndAsyncKVStore + Sync + Send; pub type Persister = MonitorUpdatingPersister< Arc, diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 055d742dc8..2757786ac1 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -7,6 +7,7 @@ use std::future::Future; use std::ops::Deref; +use std::pin::Pin; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -990,18 +991,20 @@ impl Listen for Wallet { impl WalletSource for Wallet { fn list_confirmed_utxos<'a>( &'a self, - ) -> impl Future, ()>> + Send + 'a { - async move { self.list_confirmed_utxos_inner() } + ) -> Pin, ()>> + Send + 'a>> { + Box::pin(async move { self.list_confirmed_utxos_inner() }) } - fn get_change_script<'a>(&'a self) -> impl Future> + Send + 'a { - async move { self.get_change_script_inner() } + fn get_change_script<'a>( + &'a self, + ) -> Pin> + Send + 'a>> { + Box::pin(async move { self.get_change_script_inner() }) } fn sign_psbt<'a>( &'a self, psbt: Psbt, - ) -> impl Future> + Send + 'a { - async move { self.sign_psbt_inner(psbt) } + ) -> Pin> + Send + 'a>> { + Box::pin(async move { self.sign_psbt_inner(psbt) }) } } @@ -1201,15 +1204,17 @@ impl SignerProvider for WalletKeysManager { impl ChangeDestinationSource for WalletKeysManager { fn get_change_destination_script<'a>( &'a self, - ) -> impl Future> + Send + 'a { - async move { - self.wallet + ) -> Pin> + Send + 'a>> { + let wallet = Arc::clone(&self.wallet); + let logger = Arc::clone(&self.logger); + Box::pin(async move { + wallet .get_new_internal_address() .map_err(|e| { - log_error!(self.logger, "Failed to retrieve new address from wallet: {}", e); + log_error!(logger, "Failed to retrieve new address from wallet: {}", e); }) .map(|addr| addr.script_pubkey()) .map_err(|_| ()) - } + }) } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 96f58297c7..49445cd1d6 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -10,10 +10,12 @@ pub(crate) mod logging; +use std::boxed::Box; use std::collections::{HashMap, HashSet}; use std::env; use std::future::Future; use std::path::PathBuf; +use std::pin::Pin; use std::sync::{Arc, RwLock}; use std::time::Duration; @@ -421,7 +423,7 @@ pub(crate) fn setup_node_for_async_payments( let node = match config.store_type { TestStoreType::TestSyncStore => { - let kv_store = TestSyncStore::new(config.node_config.storage_dir_path.into()); + let kv_store = Arc::new(TestSyncStore::new(config.node_config.storage_dir_path.into())); builder.build_with_store(config.node_entropy.into(), kv_store).unwrap() }, TestStoreType::Sqlite => builder.build(config.node_entropy.into()).unwrap(), @@ -818,8 +820,11 @@ pub(crate) async fn do_channel_full_cycle( .unwrap(); println!("\nA send"); - let payment_id = node_a.bolt11_payment().send(&invoice, None).unwrap(); - assert_eq!(node_a.bolt11_payment().send(&invoice, None), Err(NodeError::DuplicatePayment)); + let payment_id = node_a.bolt11_payment().send(&invoice, None, None).unwrap(); + assert_eq!( + node_a.bolt11_payment().send(&invoice, None, None), + Err(NodeError::DuplicatePayment) + ); assert!(!node_a.list_payments_with_filter(|p| p.id == payment_id).is_empty()); @@ -855,7 +860,10 @@ pub(crate) async fn do_channel_full_cycle( assert!(matches!(node_b.payment(&payment_id).unwrap().kind, PaymentKind::Bolt11 { .. })); // Assert we fail duplicate outbound payments and check the status hasn't changed. - assert_eq!(Err(NodeError::DuplicatePayment), node_a.bolt11_payment().send(&invoice, None)); + assert_eq!( + Err(NodeError::DuplicatePayment), + node_a.bolt11_payment().send(&invoice, None, None) + ); assert_eq!(node_a.payment(&payment_id).unwrap().status, PaymentStatus::Succeeded); assert_eq!(node_a.payment(&payment_id).unwrap().direction, PaymentDirection::Outbound); assert_eq!(node_a.payment(&payment_id).unwrap().amount_msat, Some(invoice_amount_1_msat)); @@ -873,7 +881,7 @@ pub(crate) async fn do_channel_full_cycle( let underpaid_amount = invoice_amount_2_msat - 1; assert_eq!( Err(NodeError::InvalidAmount), - node_a.bolt11_payment().send_using_amount(&invoice, underpaid_amount, None) + node_a.bolt11_payment().send_using_amount(&invoice, underpaid_amount, None, None) ); println!("\nB overpaid receive"); @@ -884,8 +892,10 @@ pub(crate) async fn do_channel_full_cycle( let overpaid_amount_msat = invoice_amount_2_msat + 100; println!("\nA overpaid send"); - let payment_id = - node_a.bolt11_payment().send_using_amount(&invoice, overpaid_amount_msat, None).unwrap(); + let payment_id = node_a + .bolt11_payment() + .send_using_amount(&invoice, overpaid_amount_msat, None, None) + .unwrap(); expect_event!(node_a, PaymentSuccessful); let received_amount = match node_b.next_event_async().await { ref e @ Event::PaymentReceived { amount_msat, .. } => { @@ -916,12 +926,12 @@ pub(crate) async fn do_channel_full_cycle( let determined_amount_msat = 2345_678; assert_eq!( Err(NodeError::InvalidInvoice), - node_a.bolt11_payment().send(&variable_amount_invoice, None) + node_a.bolt11_payment().send(&variable_amount_invoice, None, None) ); println!("\nA send_using_amount"); let payment_id = node_a .bolt11_payment() - .send_using_amount(&variable_amount_invoice, determined_amount_msat, None) + .send_using_amount(&variable_amount_invoice, determined_amount_msat, None, None) .unwrap(); expect_event!(node_a, PaymentSuccessful); @@ -958,7 +968,7 @@ pub(crate) async fn do_channel_full_cycle( manual_payment_hash, ) .unwrap(); - let manual_payment_id = node_a.bolt11_payment().send(&manual_invoice, None).unwrap(); + let manual_payment_id = node_a.bolt11_payment().send(&manual_invoice, None, None).unwrap(); let claimable_amount_msat = expect_payment_claimable_event!( node_b, @@ -1001,7 +1011,8 @@ pub(crate) async fn do_channel_full_cycle( manual_fail_payment_hash, ) .unwrap(); - let manual_fail_payment_id = node_a.bolt11_payment().send(&manual_fail_invoice, None).unwrap(); + let manual_fail_payment_id = + node_a.bolt11_payment().send(&manual_fail_invoice, None, None).unwrap(); expect_payment_claimable_event!( node_b, @@ -1044,7 +1055,13 @@ pub(crate) async fn do_channel_full_cycle( let custom_tlvs = vec![CustomTlvRecord { type_num: 13377331, value: vec![1, 2, 3] }]; let keysend_payment_id = node_a .spontaneous_payment() - .send_with_custom_tlvs(keysend_amount_msat, node_b.node_id(), None, custom_tlvs.clone()) + .send_with_custom_tlvs( + keysend_amount_msat, + node_b.node_id(), + None, + custom_tlvs.clone(), + None, + ) .unwrap(); expect_event!(node_a, PaymentSuccessful); let next_event = node_b.next_event_async().await; @@ -1289,7 +1306,6 @@ pub(crate) async fn do_channel_full_cycle( } // A `KVStore` impl for testing purposes that wraps all our `KVStore`s and asserts their synchronicity. -#[derive(Clone)] pub(crate) struct TestSyncStore { inner: Arc, } @@ -1304,7 +1320,7 @@ impl TestSyncStore { impl KVStore for TestSyncStore { fn read( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); @@ -1312,16 +1328,16 @@ impl KVStore for TestSyncStore { let fut = tokio::task::spawn_blocking(move || { inner.read_internal(&primary_namespace, &secondary_namespace, &key) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn write( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); @@ -1329,16 +1345,16 @@ impl KVStore for TestSyncStore { let fut = tokio::task::spawn_blocking(move || { inner.write_internal(&primary_namespace, &secondary_namespace, &key, buf) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn remove( &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, - ) -> impl Future> + 'static + Send { + ) -> Pin> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let key = key.to_string(); @@ -1346,28 +1362,28 @@ impl KVStore for TestSyncStore { let fut = tokio::task::spawn_blocking(move || { inner.remove_internal(&primary_namespace, &secondary_namespace, &key, lazy) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } fn list( &self, primary_namespace: &str, secondary_namespace: &str, - ) -> impl Future, io::Error>> + 'static + Send { + ) -> Pin, io::Error>> + Send>> { let primary_namespace = primary_namespace.to_string(); let secondary_namespace = secondary_namespace.to_string(); let inner = Arc::clone(&self.inner); let fut = tokio::task::spawn_blocking(move || { inner.list_internal(&primary_namespace, &secondary_namespace) }); - async move { + Box::pin(async move { fut.await.unwrap_or_else(|e| { let msg = format!("Failed to IO operation due join error: {}", e); Err(io::Error::new(io::ErrorKind::Other, msg)) }) - } + }) } } diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index 9b02cd61f0..afde9a42a3 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -31,7 +31,7 @@ use ldk_node::payment::{ ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus, QrPaymentResult, }; -use ldk_node::{Builder, Event, NodeError}; +use ldk_node::{Builder, DynStore, Event, NodeError}; use lightning::ln::channelmanager::PaymentId; use lightning::routing::gossip::{NodeAlias, NodeId}; use lightning::routing::router::RouteParametersConfig; @@ -231,7 +231,7 @@ async fn multi_hop_sending() { .bolt11_payment() .receive(2_500_000, &invoice_description.clone().into(), 9217) .unwrap(); - nodes[0].bolt11_payment().send(&invoice, Some(route_params)).unwrap(); + nodes[0].bolt11_payment().send(&invoice, Some(route_params), None).unwrap(); expect_event!(nodes[1], PaymentForwarded); @@ -252,14 +252,15 @@ async fn start_stop_reinit() { let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap()); - let test_sync_store = TestSyncStore::new(config.node_config.storage_dir_path.clone().into()); + let test_sync_store: Arc = + Arc::new(TestSyncStore::new(config.node_config.storage_dir_path.clone().into())); let sync_config = EsploraSyncConfig { background_sync_config: None }; setup_builder!(builder, config.node_config); builder.set_chain_source_esplora(esplora_url.clone(), Some(sync_config)); let node = - builder.build_with_store(config.node_entropy.into(), test_sync_store.clone()).unwrap(); + builder.build_with_store(config.node_entropy.into(), Arc::clone(&test_sync_store)).unwrap(); node.start().unwrap(); let expected_node_id = node.node_id(); @@ -298,7 +299,7 @@ async fn start_stop_reinit() { builder.set_chain_source_esplora(esplora_url.clone(), Some(sync_config)); let reinitialized_node = - builder.build_with_store(config.node_entropy.into(), test_sync_store).unwrap(); + builder.build_with_store(config.node_entropy.into(), Arc::clone(&test_sync_store)).unwrap(); reinitialized_node.start().unwrap(); assert_eq!(reinitialized_node.node_id(), expected_node_id); @@ -990,7 +991,7 @@ async fn run_splice_channel_test(bitcoind_chain_source: bool) { Err(NodeError::ChannelSplicingFailed), ); assert_eq!( - node_b.spontaneous_payment().send(amount_msat, node_a.node_id(), None), + node_b.spontaneous_payment().send(amount_msat, node_a.node_id(), None, None), Err(NodeError::PaymentSendingFailed) ); @@ -1022,7 +1023,7 @@ async fn run_splice_channel_test(bitcoind_chain_source: bool) { assert_eq!(node_b.list_balances().total_lightning_balance_sats, 4_000_000); let payment_id = - node_b.spontaneous_payment().send(amount_msat, node_a.node_id(), None).unwrap(); + node_b.spontaneous_payment().send(amount_msat, node_a.node_id(), None, None).unwrap(); expect_payment_successful_event!(node_b, Some(payment_id), None); expect_payment_received_event!(node_a, amount_msat); @@ -1116,7 +1117,7 @@ async fn simple_bolt12_send_receive() { let expected_payer_note = Some("Test".to_string()); let payment_id = node_a .bolt12_payment() - .send(&offer, expected_quantity, expected_payer_note.clone(), None) + .send(&offer, expected_quantity, expected_payer_note.clone(), None, None) .unwrap(); expect_payment_successful_event!(node_a, Some(payment_id), None); @@ -1172,7 +1173,7 @@ async fn simple_bolt12_send_receive() { let expected_payer_note = Some("Test".to_string()); assert!(node_a .bolt12_payment() - .send_using_amount(&offer, less_than_offer_amount, None, None, None) + .send_using_amount(&offer, less_than_offer_amount, None, None, None, None) .is_err()); let payment_id = node_a .bolt12_payment() @@ -1182,6 +1183,7 @@ async fn simple_bolt12_send_receive() { expected_quantity, expected_payer_note.clone(), None, + None, ) .unwrap(); @@ -1245,6 +1247,7 @@ async fn simple_bolt12_send_receive() { expected_quantity, expected_payer_note.clone(), None, + None, ) .unwrap(); let invoice = node_a.bolt12_payment().request_refund_payment(&refund).unwrap(); @@ -1428,7 +1431,7 @@ async fn async_payment() { node_receiver.stop().unwrap(); let payment_id = - node_sender.bolt12_payment().send_using_amount(&offer, 5_000, None, None, None).unwrap(); + node_sender.bolt12_payment().send_using_amount(&offer, 5_000, None, None, None, None).unwrap(); // Sleep to allow the payment reach a state where the htlc is held and waiting for the receiver to come online. tokio::time::sleep(std::time::Duration::from_millis(3000)).await; @@ -1626,7 +1629,7 @@ async fn unified_qr_send_receive() { let uqr_payment = node_b.unified_qr_payment().receive(expected_amount_sats, "asdf", expiry_sec); let uri_str = uqr_payment.clone().unwrap(); - let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None) { + let offer_payment_id: PaymentId = match node_a.unified_qr_payment().send(&uri_str, None, None) { Ok(QrPaymentResult::Bolt12 { payment_id }) => { println!("\nBolt12 payment sent successfully with PaymentID: {:?}", payment_id); payment_id @@ -1647,7 +1650,7 @@ async fn unified_qr_send_receive() { // Cut off the BOLT12 part to fallback to BOLT11. let uri_str_without_offer = uri_str.split("&lno=").next().unwrap(); let invoice_payment_id: PaymentId = - match node_a.unified_qr_payment().send(uri_str_without_offer, None) { + match node_a.unified_qr_payment().send(uri_str_without_offer, None, None) { Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => { panic!("Expected Bolt11 payment but got Bolt12"); }, @@ -1670,7 +1673,7 @@ async fn unified_qr_send_receive() { // Cut off any lightning part to fallback to on-chain only. let uri_str_without_lightning = onchain_uqr_payment.split("&lightning=").next().unwrap(); - let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning, None) { + let txid = match node_a.unified_qr_payment().send(&uri_str_without_lightning, None, None) { Ok(QrPaymentResult::Bolt12 { payment_id: _ }) => { panic!("Expected on-chain payment but got Bolt12") }, @@ -1786,7 +1789,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) { // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node. println!("Paying JIT invoice!"); - let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None).unwrap(); + let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None, None).unwrap(); expect_channel_pending_event!(service_node, client_node.node_id()); expect_channel_ready_event!(service_node, client_node.node_id()); expect_event!(service_node, PaymentForwarded); @@ -1823,7 +1826,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) { // Have the payer_node pay the invoice, to check regular forwards service_node -> client_node // are working as expected. println!("Paying regular invoice!"); - let payment_id = payer_node.bolt11_payment().send(&invoice, None).unwrap(); + let payment_id = payer_node.bolt11_payment().send(&invoice, None, None).unwrap(); expect_payment_successful_event!(payer_node, Some(payment_id), None); expect_event!(service_node, PaymentForwarded); expect_payment_received_event!(client_node, amount_msat); @@ -1849,7 +1852,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) { // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node. println!("Paying JIT invoice!"); - let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None).unwrap(); + let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None, None).unwrap(); expect_channel_pending_event!(service_node, client_node.node_id()); expect_channel_ready_event!(service_node, client_node.node_id()); expect_channel_pending_event!(client_node, service_node.node_id()); @@ -1902,7 +1905,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) { // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node. println!("Paying JIT invoice!"); - let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None).unwrap(); + let payment_id = payer_node.bolt11_payment().send(&jit_invoice, None, None).unwrap(); expect_channel_pending_event!(service_node, client_node.node_id()); expect_channel_ready_event!(service_node, client_node.node_id()); expect_channel_pending_event!(client_node, service_node.node_id()); @@ -1973,7 +1976,7 @@ async fn spontaneous_send_with_custom_preimage() { let amount_msat = 100_000; let payment_id = node_a .spontaneous_payment() - .send_with_preimage(amount_msat, node_b.node_id(), custom_preimage, None) + .send_with_preimage(amount_msat, node_b.node_id(), custom_preimage, None, None) .unwrap(); // check payment status and verify stored preimage @@ -2110,7 +2113,7 @@ async fn lsps2_client_trusts_lsp() { // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node. println!("Paying JIT invoice!"); - let payment_id = payer_node.bolt11_payment().send(&res, None).unwrap(); + let payment_id = payer_node.bolt11_payment().send(&res, None, None).unwrap(); println!("Payment ID: {:?}", payment_id); let funding_txo = expect_channel_pending_event!(service_node, client_node.node_id()); expect_channel_ready_event!(service_node, client_node.node_id()); @@ -2285,7 +2288,7 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() { // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node. println!("Paying JIT invoice!"); - let _payment_id = payer_node.bolt11_payment().send(&res, None).unwrap(); + let _payment_id = payer_node.bolt11_payment().send(&res, None, None).unwrap(); let funding_txo = expect_channel_pending_event!(service_node, client_node.node_id()); expect_channel_ready_event!(service_node, client_node.node_id()); expect_channel_pending_event!(client_node, service_node.node_id());