Skip to content

Commit

Permalink
Fix findRoute segfault.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Sep 13, 2023
1 parent 4323dca commit eed8878
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
33 changes: 33 additions & 0 deletions ci/LDKSwift/Tests/LDKSwiftTests/HumanObjectPeerTestInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,39 @@ public class HumanObjectPeerTestInstance {

let recreatedInvoice = Bolt11Invoice.fromStr(s: invoice.toStr())
XCTAssertTrue(recreatedInvoice.isOk())

// find route

do {
let payerPubkey = peer1.channelManager.getOurNodeId()
let payeePubkey = peer2.channelManager.getOurNodeId()
let paymentParameters = PaymentParameters.initForKeysend(payeePubkey: payeePubkey, finalCltvExpiryDelta: 3, allowMpp: false)

let amount = invoice.amountMilliSatoshis()!
let routeParameters = RouteParameters(paymentParamsArg: paymentParameters, finalValueMsatArg: amount)
let randomSeedBytes: [UInt8] = [UInt8](repeating: 0, count: 32)
let scoringParams = ProbabilisticScoringDecayParameters.initWithDefault()
let networkGraph = peer1.constructor!.netGraph!
let scorer = ProbabilisticScorer(decayParams: scoringParams, networkGraph: networkGraph, logger: logger)
let score = scorer.asScore()

let scoreParams = ProbabilisticScoringFeeParameters.initWithDefault()

let foundRoute = Bindings.findRoute(
ourNodePubkey: payerPubkey,
routeParams: routeParameters,
networkGraph: networkGraph,
firstHops: usableChannelsA,
logger: logger,
scorer: score,
scoreParams: scoreParams,
randomSeedBytes: randomSeedBytes
)

let route = foundRoute.getValue()!
let fees = route.getTotalFees()
print("found route fees: \(fees)")
}

let channelManagerConstructor = peer1.constructor!
let invoicePaymentResult = Bindings.payInvoice(invoice: invoice, retryStrategy: Bindings.Retry.initWithAttempts(a: 3), channelmanager: channelManagerConstructor.channelManager)
Expand Down
4 changes: 3 additions & 1 deletion out/Bindings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,9 @@ public class Bindings {
if let firstHops = firstHops {

let firstHopsVector = Vec_ChannelDetailsZ(
array: firstHops, instantiationContext: "Bindings.swift::\(#function):\(#line)")
array: firstHops, instantiationContext: "Bindings.swift::\(#function):\(#line)"
)
.dangle()

firstHopsVectorPointer = UnsafeMutablePointer<LDKCVec_ChannelDetailsZ>.allocate(capacity: 1)
firstHopsVectorPointer!.initialize(to: firstHopsVector.cType!)
Expand Down
8 changes: 6 additions & 2 deletions out/traits/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ extension Bindings {
if let firstHops = firstHops {

let firstHopsVector = Vec_ChannelDetailsZ(
array: firstHops, instantiationContext: "Router.swift::\(#function):\(#line)")
array: firstHops, instantiationContext: "Router.swift::\(#function):\(#line)"
)
.dangle()

firstHopsVectorPointer = UnsafeMutablePointer<LDKCVec_ChannelDetailsZ>.allocate(capacity: 1)
firstHopsVectorPointer!.initialize(to: firstHopsVector.cType!)
Expand Down Expand Up @@ -323,7 +325,9 @@ extension Bindings {
if let firstHops = firstHops {

let firstHopsVector = Vec_ChannelDetailsZ(
array: firstHops, instantiationContext: "Router.swift::\(#function):\(#line)")
array: firstHops, instantiationContext: "Router.swift::\(#function):\(#line)"
)
.dangle()

firstHopsVectorPointer = UnsafeMutablePointer<LDKCVec_ChannelDetailsZ>.allocate(capacity: 1)
firstHopsVectorPointer!.initialize(to: firstHopsVector.cType!)
Expand Down
2 changes: 2 additions & 0 deletions src/generation/base_type_generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ export abstract class BaseTypeGenerator<Type extends RustType> {
// memoryManagementInfix = ''
// }
}
} else if (argument.isAsteriskPointer && this.isPointerArgumentNullable(argument, containerType)) {
memoryManagementInfix = '.dangle()';
}
} else if (argument.type instanceof RustPrimitiveWrapper && argument.type.isDeallocatable()) {
// memoryManagementInfix = '.dangle()';
Expand Down

0 comments on commit eed8878

Please sign in to comment.