Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2022 17:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// first, download the gossip data
print("Sending rapid gossip sync request…");
var request = URLRequest(url: URL(string: "")!)
request.httpMethod = "GET"
let startA =
let (data, _) = try await request)
let finishA =
let elapsedA = Double(finishA.uptimeNanoseconds-startA.uptimeNanoseconds)/1_000_000_000
print("Received rapid gossip sync response: \(data.count) bytes! Time: \(elapsedA)s");
let reversedGenesisHashHex = "6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000"
let reversedGenesisHash = PolarIntegrationSample.hexStringToBytes(hexString: reversedGenesisHashHex)!
let logger = LDKTraitImplementations.PolarLogger()
let networkGraph = NetworkGraph(genesis_hash: reversedGenesisHash, logger: logger)
let rapidSync = RapidGossipSync(network_graph: networkGraph)
let gossipDataRaw = [UInt8](data)
print("Applying rapid sync data…")
let startB =
let timestamp = rapidSync.update_network_graph(update_data: gossipDataRaw)
if let error = timestamp.getError() {
print("error! type: \(error.getValueType())")
let specificError = error.getValueAsLightningError()
print("details: \(specificError?.get_err())")
let finishB =
let elapsedB = Double(finishB.uptimeNanoseconds-startB.uptimeNanoseconds)/1_000_000_000
print("Applied rapid sync data: \(timestamp.getValue())! Time: \(elapsedB)s")
print("Measuring graph size…")
let startC =
let graphBytes = networkGraph.write()
let finishC =
let elapsedC = Double(finishC.uptimeNanoseconds-startC.uptimeNanoseconds)/1_000_000_000
print("Network graph size: \(graphBytes.count)! Time: \(elapsedC)s")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment