Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to version 0.0.124 #133

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
run: |
echo `pwd`
mkdir -p ${{ inputs.destination }}/bin
git clone --branch 0.0.123-bindings https://github.com/lightningdevkit/rust-lightning ${{ inputs.destination }}/rust-lightning
git clone --branch 0.0.124-bindings https://github.com/lightningdevkit/rust-lightning ${{ inputs.destination }}/rust-lightning
git clone --branch main https://github.com/lightningdevkit/ldk-c-bindings ${{ inputs.destination }}/ldk-c-bindings
- name: Install Rust, required targets
if: ${{ inputs.configureRustNightly == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ In order to generate these bindings from scratch, you will need to clone two dep
**[rust-lightning](https://github.com/lightningdevkit/rust-lightning)**, (a specific branch built for bindings compatibility):

```shell
git clone --branch 0.0.123-bindings https://github.com/lightningdevkit/rust-lightning /path/to/rust-lightning
git clone --branch 0.0.124-bindings https://github.com/lightningdevkit/rust-lightning /path/to/rust-lightning
```

**[ldk-c-bindings](https://github.com/lightningdevkit/ldk-c-bindings)**:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct ChannelManagerConstructionParameters {
public var scoreParams: ProbabilisticScoringFeeParameters?
public var payerRetries: Retry = Retry.initWithAttempts(a: UInt32(3))
public var logger: Logger

public init (config: UserConfig, entropySource: EntropySource, nodeSigner: NodeSigner, signerProvider: SignerProvider, feeEstimator: FeeEstimator, chainMonitor: ChainMonitor, txBroadcaster: BroadcasterInterface, logger: Logger, enableP2PGossip: Bool = false, scorer: MultiThreadedLockableScore? = nil, scoreParams: ProbabilisticScoringFeeParameters? = nil, payerRetries: Retry = Retry.initWithAttempts(a: UInt32(3))) {
self.config = config
self.entropySource = entropySource
Expand All @@ -55,7 +55,7 @@ public struct ChannelManagerConstructionParameters {
self.chainMonitor = chainMonitor
self.txBroadcaster = txBroadcaster
self.logger = logger

self.enableP2PGossip = enableP2PGossip
self.scorer = scorer
if scorer != nil && scoreParams == nil {
Expand All @@ -65,7 +65,7 @@ public struct ChannelManagerConstructionParameters {
}
self.payerRetries = payerRetries
}

private class CMCRouter: Router {
override func findRoute(payer: [UInt8], routeParams: Bindings.RouteParameters, firstHops: [Bindings.ChannelDetails]?, inflightHtlcs: Bindings.InFlightHtlcs) -> Bindings.Result_RouteLightningErrorZ {
let errorString = "Error: Router unavailable: ChannelManagerConstructor initialized without Scorer or NetworkGraph."
Expand All @@ -78,7 +78,7 @@ public struct ChannelManagerConstructionParameters {
return .initWithErr(e: LightningError(errArg: errorString, actionArg: ErrorAction.initWithIgnoreAndLog(a: .Error)))
}
}

fileprivate func router(networkGraph: NetworkGraph?) -> Router {
if let netGraph = networkGraph, let scorer = self.scorer, let scoreParams = self.scoreParams {
return DefaultRouter(networkGraph: netGraph, logger: self.logger, entropySource: self.entropySource, scorer: scorer.asLockableScore(), scoreParams: scoreParams).asRouter()
Expand All @@ -101,17 +101,17 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
public let channel_manager_latest_block_hash: [UInt8]?

private let constructionParameters: ChannelManagerConstructionParameters

fileprivate var customPersister: CustomChannelManagerPersister?
fileprivate var customEventHandler: EventHandler?
public private(set) var netGraph: NetworkGraph?
fileprivate var graphMessageHandler: GossipSync?




// public private(set) var payer: InvoicePayer?

public let peerManager: PeerManager
private var tcpPeerHandler: TCPPeerHandler?

Expand All @@ -127,7 +127,7 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
public init(channelManagerSerialized: [UInt8], channelMonitorsSerialized: [[UInt8]], networkGraph: NetworkGraphArgument, filter: Filter?, params: ChannelManagerConstructionParameters, logger: Logger) throws {

self.constructionParameters = params

var monitors: [ChannelMonitor] = []
self.channel_monitors = []

Expand Down Expand Up @@ -155,7 +155,7 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
}

print("Collected channel monitors, reading channel manager")

switch networkGraph {
case .instance(let graph):
self.netGraph = graph
Expand All @@ -166,11 +166,11 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
}
self.netGraph = netGraphResult.getValue()
}

// TODO: figure out better way to obtain a router
let router = params.router(networkGraph: self.netGraph)
let channelManagerReadArgs = ChannelManagerReadArgs(entropySource: params.entropySource, nodeSigner: params.nodeSigner, signerProvider: params.signerProvider, feeEstimator: params.feeEstimator, chainMonitor: params.chainMonitor.asWatch(), txBroadcaster: params.txBroadcaster, router: router, logger: params.logger, defaultConfig: params.config, channelMonitors: monitors)

guard let (latestBlockHash, channelManager) = Bindings.readThirtyTwoBytesChannelManager(ser: channelManagerSerialized, arg: channelManagerReadArgs).getValue() else {
throw InvalidSerializedDataError.invalidSerializedChannelManager
}
Expand Down Expand Up @@ -222,17 +222,17 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
public init(network: Network, currentBlockchainTipHash: [UInt8], currentBlockchainTipHeight: UInt32, netGraph: NetworkGraph?, params: ChannelManagerConstructionParameters) {

self.constructionParameters = params

self.channel_monitors = []
self.channel_manager_latest_block_hash = nil
let block = BestBlock(blockHashArg: currentBlockchainTipHash, heightArg: currentBlockchainTipHeight)
let chainParameters = ChainParameters(networkArg: network, bestBlockArg: block)

self.netGraph = netGraph
let router = params.router(networkGraph: self.netGraph)
let timestampSeconds = UInt32(NSDate().timeIntervalSince1970)
self.channelManager = ChannelManager(feeEst: params.feeEstimator, chainMonitor: params.chainMonitor.asWatch(), txBroadcaster: params.txBroadcaster, router: router, logger: params.logger, entropySource: params.entropySource, nodeSigner: params.nodeSigner, signerProvider: params.signerProvider, config: params.config, params: chainParameters, currentTimestamp: timestampSeconds)

let channelMessageHandler = channelManager.asChannelMessageHandler()
let noCustomMessages = IgnoringMessageHandler().asCustomMessageHandler()
let noOnionMessages = IgnoringMessageHandler().asOnionMessageHandler()
Expand All @@ -246,7 +246,7 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
} else {
messageHandler = MessageHandler(chanHandlerArg: channelMessageHandler, routeHandlerArg: noRoutingMessages, onionMessageHandlerArg: noOnionMessages, customMessageHandlerArg: noCustomMessages)
}

let random_data = params.entropySource.getSecureRandomBytes();

self.peerManager = PeerManager(messageHandler: messageHandler, currentTime: timestampSeconds, ephemeralRandomData: random_data, logger: params.logger, nodeSigner: params.nodeSigner)
Expand Down Expand Up @@ -290,10 +290,12 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
self.customPersister = CustomChannelManagerPersister(handler: persister)
self.customEventHandler = CustomEventHandler(handler: persister)

let ignoringMessageHandler = IgnoringMessageHandler()
let onionMessenger = OnionMessenger.initWith(entropySource: self.constructionParameters.entropySource, nodeSigner: self.constructionParameters.nodeSigner, logger: self.constructionParameters.logger, nodeIdLookup: NodeIdLookUp(), messageRouter: MessageRouter(), offersHandler: self.channelManager.asOffersMessageHandler(), asyncPaymentsHandler: ignoringMessageHandler.asAsyncPaymentsMessageHandler(), customHandler: ignoringMessageHandler.asCustomOnionMessageHandler())

// if there is a graph msg handler, set its is_owned to false
// self.graph_msg_handler?.cOpaqueStruct?.is_owned = false

self.backgroundProcessor = BackgroundProcessor.start(persister: self.customPersister!, eventHandler: self.customEventHandler!, chainMonitor: self.constructionParameters.chainMonitor, channelManager: self.channelManager, gossipSync: self.graphMessageHandler ?? GossipSync.none(), peerManager: self.peerManager, logger: self.constructionParameters.logger, scorer: self.constructionParameters.scorer?.asWriteableScore())
self.backgroundProcessor = BackgroundProcessor.start(persister: self.customPersister!, eventHandler: self.customEventHandler!, chainMonitor: self.constructionParameters.chainMonitor, channelManager: self.channelManager, onionMessenger: onionMessenger, gossipSync: self.graphMessageHandler ?? GossipSync.none(), peerManager: self.peerManager, logger: self.constructionParameters.logger, scorer: self.constructionParameters.scorer?.asWriteableScore())

// restore it back to true
// self.graph_msg_handler?.cOpaqueStruct?.is_owned = true
Expand Down Expand Up @@ -360,15 +362,15 @@ fileprivate class CustomChannelManagerPersister: Persister {
self.handler = handler
super.init()
}

override func persistManager(channelManager: Bindings.ChannelManager) -> Bindings.Result_NoneIOErrorZ {
return self.handler.persistManager(channelManager: channelManager)
}

override func persistGraph(networkGraph: Bindings.NetworkGraph) -> Bindings.Result_NoneIOErrorZ {
return self.handler.persistGraph(networkGraph: networkGraph)
}

override func persistScorer(scorer: Bindings.WriteableScore) -> Bindings.Result_NoneIOErrorZ {
return self.handler.persistScorer(scorer: scorer)
}
Expand All @@ -383,15 +385,15 @@ fileprivate class CustomEventHandler: EventHandler {
super.init()
}

override func handleEvent(event: Bindings.Event) {
override func handleEvent(event: Bindings.Event) -> Bindings.Result_NoneReplayEventZ {
// self.handler.handle_event(event: event.clone())
self.handler.handleEvent(event: event)
}

}

public protocol ExtendedChannelManagerPersister: Persister {
func handleEvent(event: Event) -> Void;
func handleEvent(event: Event) -> Result_NoneReplayEventZ;
}

public class TCPPeerHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public class HumanObjectPeerTestInstance {
self.interface = underlyingInterface
super.init()
}

override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.WriteableEcdsaChannelSigner {
override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.EcdsaChannelSigner {
let ck = self.interface.deriveChannelSigner(channelValueSatoshis: channelValueSatoshis, channelKeysId: channelKeysId)
return ck
}
Expand All @@ -226,14 +226,14 @@ public class HumanObjectPeerTestInstance {
self.master = master
super.init()
}

func handleEvent(event: Event) {
// let eventClone = event.clone()

func handleEvent(event: Event) -> Result_NoneReplayEventZ {
print("peer \(self.master.seed) received event: \(event.getValueType())")
Task {
// clone to avoid deallocation-related issues
await master.pendingEventTracker.addEvent(event: event)
}
return .initWithOk()
}

override func persistScorer(scorer: Bindings.WriteableScore) -> Bindings.Result_NoneIOErrorZ {
Expand All @@ -252,10 +252,12 @@ public class HumanObjectPeerTestInstance {
}

fileprivate class TestPersister: Persist {
override func persistNewChannel(channelFundingOutpoint channelId: Bindings.OutPoint, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {

override func persistNewChannel(channelFundingOutpoint: Bindings.OutPoint, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
.Completed
}
override func updatePersistedChannel(channelFundingOutpoint channelId: Bindings.OutPoint, update: Bindings.ChannelMonitorUpdate, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {

override func updatePersistedChannel(channelFundingOutpoint: Bindings.OutPoint, monitorUpdate: Bindings.ChannelMonitorUpdate, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
.Completed
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class TestChannelManagerPersister : Persister, ExtendedChannelManagerPersister {
self.channelManager = channelManager
super.init()
}

func handleEvent(event: Event) {
// privateHandleEvent(event: event)
tnull marked this conversation as resolved.
Show resolved Hide resolved
func handleEvent(event: Event) -> Result_NoneReplayEventZ {
.initWithOk()
}

override func persistScorer(scorer: Bindings.WriteableScore) -> Bindings.Result_NoneIOErrorZ {
Expand Down
6 changes: 3 additions & 3 deletions ci/LDKSwift/Tests/LDKSwiftTests/TestPersister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import LDKHeaders
#endif

class TestPersister: Persist {

override func persistNewChannel(channelFundingOutpoint channelId: Bindings.OutPoint, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
override func persistNewChannel(channelFundingOutpoint: Bindings.OutPoint, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
.Completed
}

override func updatePersistedChannel(channelFundingOutpoint channelId: Bindings.OutPoint, update: Bindings.ChannelMonitorUpdate, data: Bindings.ChannelMonitor, updateId: Bindings.MonitorUpdateId) -> Bindings.ChannelMonitorUpdateStatus {
override func updatePersistedChannel(channelFundingOutpoint: Bindings.OutPoint, monitorUpdate: Bindings.ChannelMonitorUpdate, monitor: Bindings.ChannelMonitor) -> Bindings.ChannelMonitorUpdateStatus {
.Completed
}

Expand Down
17 changes: 9 additions & 8 deletions ci/LDKSwift/Tests/LDKSwiftTests/WrappedSignerProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WrappedSignerProviderTests: XCTestCase {

let handshakeConfig = ChannelHandshakeConfig.initWithDefault()
handshakeConfig.setMinimumDepth(val: 1)
handshakeConfig.setAnnouncedChannel(val: false)
// handshakeConfig.setAnnouncedChannel(val: false)

let handshakeLimits = ChannelHandshakeLimits.initWithDefault()
handshakeLimits.setForceAnnouncedChannelPreference(val: false)
Expand Down Expand Up @@ -105,10 +105,10 @@ class WrappedSignerProviderTests: XCTestCase {
print("entering wrapper: signGossipMessage()")
return myKeysManager!.keysManager.asNodeSigner().signGossipMessage(msg: msg)
}

override func signInvoice(hrpBytes: [UInt8], invoiceData: [UInt8], recipient: Bindings.Recipient) -> Bindings.Result_RecoverableSignatureNoneZ {
override func signInvoice(invoice: Bindings.RawBolt11Invoice, recipient: Bindings.Recipient) -> Bindings.Result_RecoverableSignatureNoneZ {
print("entering wrapper: signInvoice()")
return myKeysManager!.keysManager.asNodeSigner().signInvoice(hrpBytes: hrpBytes, invoiceData: invoiceData, recipient: recipient)
return myKeysManager!.keysManager.asNodeSigner().signInvoice(invoice: invoice, recipient: recipient)
}
}

Expand All @@ -122,17 +122,18 @@ class WrappedSignerProviderTests: XCTestCase {

class MySignerProvider: SignerProvider {
weak var myKeysManager: MyKeysManager?
override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.WriteableEcdsaChannelSigner {

override func deriveChannelSigner(channelValueSatoshis: UInt64, channelKeysId: [UInt8]) -> Bindings.EcdsaChannelSigner {
print("entering wrapper: deriveChannelSigner()")
return myKeysManager!.keysManager.asSignerProvider().deriveChannelSigner(channelValueSatoshis: channelValueSatoshis, channelKeysId: channelKeysId)
return myKeysManager!.keysManager.deriveChannelKeys(channelValueSatoshis: channelValueSatoshis, params: channelKeysId).asEcdsaChannelSigner()
}

override func generateChannelKeysId(inbound: Bool, channelValueSatoshis: UInt64, userChannelId: [UInt8]) -> [UInt8] {
print("entering wrapper: generateChannelKeysId()")
return myKeysManager!.keysManager.asSignerProvider().generateChannelKeysId(inbound: inbound, channelValueSatoshis: channelValueSatoshis, userChannelId: userChannelId)
}

override func readChanSigner(reader: [UInt8]) -> Bindings.Result_WriteableEcdsaChannelSignerDecodeErrorZ {
override func readChanSigner(reader: [UInt8]) -> Bindings.Result_EcdsaChannelSignerDecodeErrorZ {
print("entering wrapper: readChanSigner()")
return myKeysManager!.keysManager.asSignerProvider().readChanSigner(reader: reader)
}
Expand Down
Loading
Loading