Skip to content

Commit

Permalink
more channels, accept-amp and lndsetup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Oct 2, 2022
1 parent c214380 commit d389a31
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 44 deletions.
3 changes: 3 additions & 0 deletions alts/proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ services:
entrypoint: ["node", "/lndsetup/index.js"]
volumes:
- ./lnd/alice/.lnd:/alice/.lnd
- ./lnd/bob/.lnd:/bob/.lnd
- ./lnd/carol/.lnd:/carol/.lnd
- ./lnd/dave/.lnd:/dave/.lnd
- ./lnd/setup:/lndsetup
- ./lnd/setup/nodes/proxynodes.js:/lndsetup/nodes.js

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ services:
entrypoint: ["node", "/lndsetup/index.js"]
volumes:
- ./lnd/alice/.lnd:/alice/.lnd
- ./lnd/bob/.lnd:/bob/.lnd
- ./lnd/carol/.lnd:/carol/.lnd
- ./lnd/setup:/lndsetup
- ./lnd/setup/nodes/nodes.js:/lndsetup/nodes.js

Expand Down
4 changes: 3 additions & 1 deletion lnd/setup/alice.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ rpclisten=0.0.0.0:10009
restlisten=0.0.0.0:38881
tlsextradomain=alice-lnd.sphinx
accept-keysend=true
accept-amp=true
maxpendingchannels=69
alias=alice-lnd
bitcoin.node=bitcoind
bitcoin.defaultchanconfs=2
bitcoind.rpcuser=evan
bitcoind.rpcpass=thepass
bitcoind.rpchost=bitcoind.sphinx
bitcoind.zmqpubrawblock=tcp://bitcoind.sphinx:28332
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
6 changes: 4 additions & 2 deletions lnd/setup/bob.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ debuglevel=info
rpclisten=0.0.0.0:10010
restlisten=0.0.0.0:38882
tlsextradomain=bob-lnd.sphinx
accept-keysend=true
accept-keysend=false
accept-amp=true
maxpendingchannels=69
alias=bob-lnd
bitcoin.node=bitcoind
bitcoin.defaultchanconfs=2
bitcoind.rpcuser=evan
bitcoind.rpcpass=thepass
bitcoind.rpchost=bitcoind.sphinx
bitcoind.zmqpubrawblock=tcp://bitcoind.sphinx:28332
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
4 changes: 3 additions & 1 deletion lnd/setup/carol.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ rpclisten=0.0.0.0:10011
restlisten=0.0.0.0:38883
tlsextradomain=carol-lnd.sphinx
accept-keysend=true
accept-amp=false
maxpendingchannels=69
alias=carol-lnd
bitcoin.node=bitcoind
bitcoin.defaultchanconfs=2
bitcoind.rpcuser=evan
bitcoind.rpcpass=thepass
bitcoind.rpchost=bitcoind.sphinx
bitcoind.zmqpubrawblock=tcp://bitcoind.sphinx:28332
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
bitcoind.zmqpubrawtx=tcp://bitcoind.sphinx:28333
2 changes: 2 additions & 0 deletions lnd/setup/dave.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rpclisten=0.0.0.0:10012
restlisten=0.0.0.0:38884
tlsextradomain=dave-lnd.sphinx
accept-keysend=true
accept-amp=true
maxpendingchannels=69
alias=dave-lnd
bitcoin.node=bitcoind
bitcoin.defaultchanconfs=2
Expand Down
91 changes: 53 additions & 38 deletions lnd/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,24 @@ async function createOrUnlockWallet(node) {
console.log("[LND] WALLET UNLOCKED");
}
} catch (e) {
console.log("=> err", e);
}
}

async function coinsAndChannels(node) {
try {
const coins_success = await coins(node);
if (coins_success) {
await channels(node);
}
} catch (e) {
console.log("=> err", e);
console.log("=> createOrUnlockWallet error:", e);
}
}

async function coins(node) {
try {
const balres = await lightning.getBalance(node);
const confirmed = parseInt(balres.confirmed_balance);
console.log("=> ALICE confirmed balance:", confirmed);
if (!confirmed) {
const ares = await lightning.newAddress(node);
const addy = ares.address;
console.log("=> ALICE address", addy);
await bitcoind.mine(101, addy);
console.log("=> 101 blocks mined to alice!", addy);
await sleep(5000);
console.log(`=> ${node.alias} confirmed balance:`, confirmed);
if (confirmed < 100000000) {
const addr = (await lightning.newAddress(node)).address;
console.log(`=> ${node.alias} address`, addr);
await bitcoind.mine(1, addr);
console.log(`=> 1 block mined to ${node.alias}!`);
}
return true;
} catch (e) {
console.log("=> err:", e);
console.log("=> coins error:", e);
}
}

Expand All @@ -64,44 +51,68 @@ async function channels(node) {
return exists ? false : true;
})
: [];

if (!peersToMake.length) {
console.log(`=> ${node.alias} doesn't need to open channels`);
return;
}

await asyncForEach(peersToMake, async (p) => {
await lightning.addPeer(node, p);
});

const chans = await lightning.listChannels(node);
const channels = chans.channels || [];
await bitcoind.mine(6, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");
console.log("=> 6 blocked mined to Alice!");
await sleep(20000)
if (!channels.length) {
console.log("=> alice opening channels...");
// open channels here
if (channels.length) {
console.log(`=> ${node.alias} already has open channels`);
} else {
console.log(`=> ${node.alias} opening ${peersToMake.length} channels...`);
await asyncForEach(peersToMake, async (p) => {
await lightning.openChannel(node, {
pubkey: p.pubkey,
amount: 2000000,
push_amount: 1000000,
});
});
await bitcoind.mine(6, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");
console.log("=> 6 blocked mined to Alice!");
}
await sleep(4000);
const chans2 = await lightning.listChannels(node);
console.log("FINAL CHANS", chans2.channels);
} catch (e) {
console.log("=> err:", e);
console.log("=> channels error:", e);
}
}

async function logChannels(node) {
try {
const chans = await lightning.listChannels(node);
console.log(
`=> ${node.alias} has ${chans.channels.length} channels:`,
chans.channels.map(ch => ch.remote_pubkey)
);
} catch (e) {
console.log("=> logChannels err:", e);
}
}

async function unlockAll() {
await sleep(3500);
// createOrUnlockWallet(nodes.nodes.alice);
await asyncForEach(Object.values(nodes.nodes), async (node) => {
await createOrUnlockWallet(node);
});

await forEachNode(createOrUnlockWallet);

await sleep(5000);

await forEachNode(coins);

// coinbase outputs need 100 confs
await bitcoind.mine(100, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");
await sleep(5000);
await coinsAndChannels(nodes.nodes.alice);

await forEachNode(channels);

// ln channels need at most 6 confs
await bitcoind.mine(6, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");

await sleep(20000);

await forEachNode(logChannels);
}

unlockAll();
Expand All @@ -110,6 +121,10 @@ async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function forEachNode(callback) {
await asyncForEach(Object.values(nodes.nodes), callback);
}

async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
Expand Down
1 change: 1 addition & 0 deletions lnd/setup/lightning.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async function openChannel(node, chan) {
node_pubkey: Buffer.from(chan.pubkey, "hex").toString("base64"),
local_funding_amount: chan.amount,
push_sat: chan.push_amount,
spend_unconfirmed: true,
});
}

Expand Down
7 changes: 7 additions & 0 deletions lnd/setup/nodes/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const nodes = {
hostname: "bob-lnd.sphinx:38882",
password: "bob12345",
macaroon: "/bob/" + macpath,
channels: [
{
host: "carol-lnd.sphinx:9735",
pubkey:
"0364c05cbcbb9612036cc66297445a88bcfc21941fd816e17a56b54b0b52ff02b9",
},
],
mnemonic: [
"above",
"street",
Expand Down
7 changes: 7 additions & 0 deletions lnd/setup/nodes/proxynodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ const nodes = {
hostname: "bob-lnd.sphinx:38882",
password: "bob12345",
macaroon: "/bob/" + macpath,
channels: [
{
host: "carol-lnd.sphinx:9735",
pubkey:
"0364c05cbcbb9612036cc66297445a88bcfc21941fd816e17a56b54b0b52ff02b9",
},
],
mnemonic: [
"above",
"street",
Expand Down
3 changes: 1 addition & 2 deletions relay/dave-db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"development": {
"dialect": "sqlite",
"storage": "./configs/db/dave.db"
}
,
},
"gitactionenv": {
"dialect": "sqlite"
}
Expand Down

0 comments on commit d389a31

Please sign in to comment.