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

make more channels for amp #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
environment:
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
5 changes: 4 additions & 1 deletion lnd/setup/bob.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ debuglevel=info
rpclisten=0.0.0.0:10010
restlisten=0.0.0.0:38882
tlsextradomain=bob-lnd.sphinx
# accept-keysend=false
accept-keysend=true
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
90 changes: 53 additions & 37 deletions lnd/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,20 @@ async function createOrUnlockWallet(node) {
}
}

async function coinsAndChannels(node) {
try {
const coins_success = await coins(node);
if (coins_success) {
await channels(node);
}
} catch (e) {
console.log("=> err", 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 @@ -79,19 +66,24 @@ async function channels(node) {
return exists ? false : true;
})
: [];

console.log("peers to make:", peersToMake);

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) {
antonilol marked this conversation as resolved.
Show resolved Hide resolved
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) => {
console.log("open channel with:", p);

Expand All @@ -113,25 +105,45 @@ async function channels(node) {
});
}
});
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 @@ -140,6 +152,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 @@ -47,6 +47,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 @@ -52,6 +52,13 @@ const nodes = {
password: "bob12345",
type: "lnd",
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 @@ -57,6 +57,13 @@ const nodes = {
password: "bob12345",
type: "lnd",
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