Skip to content

Instantly share code, notes, and snippets.

@rsbondi
Created February 26, 2019 20:45
Show Gist options
  • Save rsbondi/655801272818c1593535fb65c24ce9cd to your computer and use it in GitHub Desktop.
Save rsbondi/655801272818c1593535fb65c24ce9cd to your computer and use it in GitHub Desktop.
Generate random graph dot file for lnet
const fs = require('fs')
const args = process.argv.reduce((o, a) => {
if(~a.indexOf('=')) {
const kv = a.split('=')
o[kv[0]] = kv[1]
}
return o
}, {})
let nodes = []
for(let i=0; i<args.count; i++) {
nodes.push(Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15))
}
let graph = ''
let cons = {}
for (let i=0; i < nodes.length; i++) {
const node = nodes[i]
const peers = Math.floor(Math.random() * (args.maxchannels || 3)) + 1
cons[node] = []
for(let p = 0; p < peers; p++) {
const d = Math.floor(Math.random() * args.count)
if(d === i) { p--; continue } // con't connect to self, try again
const src = nodes[d]
if(~cons[node].indexOf(src)) { p--; continue } // only one connection
if(cons[src] && ~cons[src].indexOf(node)) { p--; continue } // the other way
cons[node].push(src)
const cap = Math.floor(Math.random() * (10000000 - 500000 + 1) + 500000)
graph += ` "${src}" -- "${node}" [capacity="${cap}"];\n`
}
}
fs.writeFileSync(args.out, Buffer.from(`graph g {\n${graph}}`))
@rsbondi
Copy link
Author

rsbondi commented Feb 26, 2019

For creating a random configuration of lightning nodes for use with lnet

usage

node index.js count=xx maxchannels=xx out=random.dot
lnet start random.dot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment