Skip to content

Commit

Permalink
make more channels and set accept-amp for AMP payments in integrati…
Browse files Browse the repository at this point in the history
…on tests
  • Loading branch information
antonilol committed Sep 16, 2022
1 parent 6e75f7e commit d71ddc0
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 27 deletions.
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
2 changes: 2 additions & 0 deletions lnd/setup/alice.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions lnd/setup/bob.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rpclisten=0.0.0.0:10010
restlisten=0.0.0.0:38882
tlsextradomain=bob-lnd.sphinx
accept-keysend=true
accept-amp=true
maxpendingchannels=69
alias=bob-lnd
bitcoin.node=bitcoind
bitcoin.defaultchanconfs=2
Expand Down
2 changes: 2 additions & 0 deletions lnd/setup/carol.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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
Expand Down
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
59 changes: 34 additions & 25 deletions lnd/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,17 @@ 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);
console.log(`=> ${node.alias} confirmed balance:`, confirmed);
if (!confirmed) {
const ares = await lightning.newAddress(node);
const addy = ares.address;
console.log("=> ALICE address", addy);
console.log(`=> ${node.alias} address`, addy);
await bitcoind.mine(101, addy);
console.log("=> 101 blocks mined to alice!", addy);
console.log(`=> 101 blocks mined to ${node.alias}!`);
await sleep(5000);
}
return true;
Expand Down Expand Up @@ -73,8 +62,10 @@ async function channels(node) {
await bitcoind.mine(6, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");
console.log("=> 6 blocked mined to Alice!");
await sleep(20000)
if (!channels.length) {
console.log("=> alice opening channels...");
if (channels.length) {
console.log(`=> ${node.alias} already has open channels`);
} else {
console.log(`=> ${node.alias} opening ${peersToMake.length} channels...`);
// open channels here
await asyncForEach(peersToMake, async (p) => {
await lightning.openChannel(node, {
Expand All @@ -83,25 +74,39 @@ async function channels(node) {
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);
}
}

async function logChannels(node) {
try {
const chans = await lightning.listChannels(node);
console.log(`${node.alias} channels:`, chans.channels);
} catch (e) {
console.log("=> 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 coinsAndChannels(nodes.nodes.alice);

await forEachNode(coins);

await forEachNode(channels);

await bitcoind.mine(6, "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr");
console.log("=> mined 6 blocks to confirm channels");

await sleep(2500);

await forEachNode(logChannels);
}

unlockAll();
Expand All @@ -110,6 +115,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
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 d71ddc0

Please sign in to comment.