Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Deploy indra-7.0.0-alpha.11
Browse files Browse the repository at this point in the history
  • Loading branch information
LayneHaber committed Jul 3, 2020
2 parents c6c9660 + 7085b2f commit 8f5e1cd
Show file tree
Hide file tree
Showing 82 changed files with 2,944 additions and 1,609 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ modules/*/package-lock.json

# Cache
**/.bot-store
**/.connext-store/**
**/.buidler
**/.cache
**/.config
**/.connext-store/**
**/.git
**/.jest.cache
**/.local
Expand Down
28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ log_finish=@echo $$((`date "+%s"` - `cat $(startTime)`)) > $(totalTime); rm $(st
default: dev
all: dev staging release
dev: bot database proxy node test-runner
staging: database ethprovider proxy node-staging test-runner-staging webserver
release: database ethprovider proxy node-release test-runner-release webserver
staging: database ethprovider proxy node-staging test-runner-staging webserver bot-staging
release: database ethprovider proxy node-release test-runner-release webserver bot-staging

########################################
# Command & Control Shortcuts
Expand All @@ -65,10 +65,10 @@ start-prod:
bash ops/start-prod.sh

start-bot: bot
bash ops/test/bot.sh 2 1000
bash ops/test/tps.sh 2 1000

start-bot-farm: bot
bash ops/test/bot.sh 10 1000
bash ops/test/tps.sh 10 1000

stop:
bash ops/stop.sh
Expand Down Expand Up @@ -107,6 +107,7 @@ quick-reset:
bash ops/db.sh 'truncate table rebalance_profile cascade;'
bash ops/db.sh 'truncate table app_instance cascade;'
bash ops/redis.sh 'flushall'
rm -rf modules/*/.connext-store
touch modules/node/src/main.ts

reset: stop
Expand Down Expand Up @@ -165,11 +166,13 @@ watch: watch-integration
test-backwards-compatibility: pull-backwards-compatible
bash ops/test/integration.sh $(backwards_compatible_version)

test-bot: bot
bash ops/test/bot.sh 2 1000 10

test-bot-farm: bot
bash ops/test/bot.sh 10 1000 50
test-tps: test-tps-md
test-tps-sm: bot
bash ops/test/tps.sh 2 0 10
test-tps-md: bot
bash ops/test/tps.sh 10 0 10
test-tps-lg: bot
bash ops/test/tps.sh 40 0 10

test-cf: cf-core
bash ops/test/cf.sh
Expand Down Expand Up @@ -349,6 +352,13 @@ node-staging: node $(shell find modules/node/ops $(find_options))
docker tag $(project)_node $(project)_node:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@

bot-staging: bot $(shell find modules/bot/ops $(find_options))
$(log_start)
$(docker_run) "cd modules/bot && MODE=staging npm run build"
docker build --file modules/bot/ops/Dockerfile $(image_cache) --tag $(project)_bot .
docker tag $(project)_bot $(project)_bot:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@

proxy: $(shell find ops/proxy $(find_options))
$(log_start)
docker build --file ops/proxy/indra/Dockerfile $(image_cache) --tag $(project)_proxy ops
Expand Down
16 changes: 9 additions & 7 deletions docs/src/how-to/deploy-indra.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# How To Deploy an Indra Node

Lets say you want to deploy an Indra payment node to `https://indra.example.com` (we'll call this url `$DOMAINNAME`)
Expand All @@ -18,12 +17,13 @@ SSH_KEY=$HOME/.ssh/id_rsa bash ops/setup-ubuntu.sh $SERVER_IP
(`$HOME/.ssh/id_rsa` is the default `SSH_KEY`, if this is what you're using then no need to supply it)

If this is a fresh Ubuntu server from DigitalOcean or AWS then the above script should:
- configure an "ubuntu" user and disable root login (if enabled)
- give an additional ssh public key login access if key specified by the `PUB_KEY` env var is available (defaults to `$HOME/.ssh/autodeployer.pub`)
- install docker & make & other dependencies
- upgrade everything to the latest version
- save your mnemonic in a docker secret called `indra_mnemonic`
- reboot

- configure an "ubuntu" user and disable root login (if enabled)
- give an additional ssh public key login access if key specified by the `PUB_KEY` env var is available (defaults to `$HOME/.ssh/autodeployer.pub`)
- install docker & make & other dependencies
- upgrade everything to the latest version
- save your mnemonic in a docker secret called `indra_mnemonic`
- reboot

Note: this script is idempotent aka you can run it over and over again w/out causing any problems. In fact, re-running it every month or so will help keep things up-to-date (you can skip inputting the mnemonic on subsequent runs).

Expand Down Expand Up @@ -69,3 +69,5 @@ The above will download & run docker images associated with the commit/release y
```bash
git checkout indra-6.0.8 && make restart-prod
```

Before you are able to start sending payments, you will have to make sure to properly collateralize your node. The signer address is available as `accounts[0]` off of your mnemonic and can also be found by querying the `/api/config` endpoint under `signerAddress`. Node's should have collateral in all supported tokens, as well as sufficient eth to pay for all transactions from the wallet to the channels. By default, the supported token addresses will include ETH and the `Token` address from the network context of your node (available in `address-book.json`).
10 changes: 5 additions & 5 deletions modules/apps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@connext/apps",
"version": "7.0.0-alpha.8",
"version": "7.0.0-alpha.11",
"description": "Connext Counterfactual Apps",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand All @@ -18,11 +18,11 @@
"clean": "rm -rf ./dist"
},
"devDependencies": {
"@connext/contracts": "3.2.3",
"@connext/utils": "7.0.0-alpha.8",
"@connext/types": "7.0.0-alpha.8",
"@connext/contracts": "3.3.0",
"@connext/utils": "7.0.0-alpha.11",
"@connext/types": "7.0.0-alpha.11",
"ethers": "5.0.2",
"rollup": "2.12.1",
"rollup": "2.18.1",
"@rollup/plugin-json": "4.1.0",
"rollup-plugin-typescript2": "0.27.1",
"typescript": "3.9.5"
Expand Down
20 changes: 20 additions & 0 deletions modules/bot/ops/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:12.13.0-alpine3.10
WORKDIR /root
ENV HOME /root
RUN apk add --update --no-cache bash curl g++ gcc git jq make python
RUN npm config set unsafe-perm true
RUN npm install -g npm@6.14.5
RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/ed77b63706ea721766a62ff22d3a251d8b4a6a30/wait-for-it.sh > /bin/wait-for && chmod +x /bin/wait-for

COPY modules/bot/package.json package.json
RUN npm install --only=production > /dev/null 2>&1
# In staging mode we bundle source from @connext packages into the node bundle
# This means the node bundle needs access to the deps for @connext packages too
RUN cp -r node_modules/@connext/*/node_modules/* node_modules
COPY modules/bot/ops ops
COPY modules/bot/dist dist
# used to fund agents
COPY modules/contracts/dist contracts/dist
ENV PATH="./node_modules/.bin:${PATH}"
EXPOSE 3333
ENTRYPOINT ["bash", "ops/entry.sh"]
12 changes: 12 additions & 0 deletions modules/bot/ops/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e

echo "Bot registry container launched!"

function finish {
echo && echo "Bot container exiting.." && exit
}

trap finish SIGTERM SIGINT
echo "Launching registry!";echo
npm run start:registry
11 changes: 7 additions & 4 deletions modules/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
"author": "",
"license": "ISC",
"dependencies": {
"@connext/client": "7.0.0-alpha.8",
"@connext/store": "7.0.0-alpha.8",
"@connext/types": "7.0.0-alpha.8",
"@connext/utils": "7.0.0-alpha.8",
"@connext/client": "7.0.0-alpha.11",
"@connext/contracts": "3.3.0",
"@connext/store": "7.0.0-alpha.11",
"@connext/types": "7.0.0-alpha.11",
"@connext/utils": "7.0.0-alpha.11",
"axios": "0.19.2",
"body-parser": "1.19.0",
"ethers": "5.0.2",
"express": "4.17.1",
"interval-promise": "1.4.0",
"yargs": "15.3.1"
},
Expand Down
36 changes: 22 additions & 14 deletions modules/bot/src/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
IConnextClient,
ILoggerService,
PublicParams,
Address,
} from "@connext/types";
import {
abrv,
delay,
getRandomBytes32,
getTestGraphReceiptToSign,
getTestVerifyingContract,
Expand All @@ -33,6 +35,7 @@ export class Agent {
private readonly log: ILoggerService,
private readonly client: IConnextClient,
private readonly privateKey: string,
private readonly errorOnProtocolFailure: boolean,
) {}

async start() {
Expand Down Expand Up @@ -104,6 +107,7 @@ export class Agent {
});

// Add failure listeners
// Always fail on a conditional transfer failed event
this.client.on(EventNames.CONDITIONAL_TRANSFER_FAILED_EVENT, async (eData) => {
if (!eData.paymentId) {
this.log.warn(`Ignoring untracked transfer ${eData.paymentId}.`);
Expand All @@ -112,13 +116,14 @@ export class Agent {
this.retrieveResolverAndReject(eData.paymentId, eData.error);
});

// Fail on protocol events IFF specified
this.client.on(EventNames.PROPOSE_INSTALL_FAILED_EVENT, async (eData) => {
const paymentId = eData.params.meta?.["paymentId"];
if (!paymentId) {
this.log.warn(`Ignoring untracked proposal failure ${stringify(eData)}.`);
return;
}
this.retrieveResolverAndReject(paymentId, eData.error);
this.errorOnProtocolFailure && this.retrieveResolverAndReject(paymentId, eData.error);
});

this.client.on(EventNames.INSTALL_FAILED_EVENT, async (eData) => {
Expand All @@ -127,7 +132,7 @@ export class Agent {
this.log.warn(`Ignoring untracked install failure ${stringify(eData)}.`);
return;
}
this.retrieveResolverAndReject(paymentId, eData.error);
this.errorOnProtocolFailure && this.retrieveResolverAndReject(paymentId, eData.error);
});

this.client.on(EventNames.UPDATE_STATE_FAILED_EVENT, async (eData) => {
Expand All @@ -136,7 +141,7 @@ export class Agent {
this.log.warn(`Ignoring untracked take action failure ${stringify(eData)}.`);
return;
}
this.retrieveResolverAndReject(this.apps[appId], eData.error);
this.errorOnProtocolFailure && this.retrieveResolverAndReject(this.apps[appId], eData.error);
});

this.client.on(EventNames.UNINSTALL_FAILED_EVENT, async (eData) => {
Expand All @@ -145,7 +150,7 @@ export class Agent {
this.log.warn(`Ignoring untracked uninstall failure ${stringify(eData)}.`);
return;
}
this.retrieveResolverAndReject(this.apps[appId], eData.error);
this.errorOnProtocolFailure && this.retrieveResolverAndReject(this.apps[appId], eData.error);
});
}

Expand Down Expand Up @@ -184,13 +189,15 @@ export class Agent {
receiverIdentifier: string,
signerAddress: string,
amount: BigNumber,
assetId: Address = AddressZero,
id: string = getRandomBytes32(),
type: ConditionalTransferTypes = ConditionalTransferTypes.SignedTransfer,
type: ConditionalTransferTypes = ConditionalTransferTypes.GraphTransfer,
) {
const params = await this.getTransferParameters(
receiverIdentifier,
signerAddress,
amount,
assetId,
id,
type,
);
Expand All @@ -212,13 +219,13 @@ export class Agent {
reject,
};

// const timeout = 35_000;
// delay(timeout).then(() => {
// if (this.payments[id]) {
// delete this.payments[id];
// return reject(new Error(`Payment ${id} timed out after ${timeout / 1000} s`));
// }
// });
const timeout = 10_000;
delay(timeout).then(() => {
if (this.payments[id]) {
delete this.payments[id];
return reject(new Error(`Payment ${id} timed out after ${timeout / 1000} s`));
}
});
});
}

Expand All @@ -240,17 +247,18 @@ export class Agent {
receiverIdentifier: string,
signerAddress: string,
amount: BigNumber,
assetId: string,
id: string,
type: ConditionalTransferTypes,
) {
const baseParams = {
conditionType: type as any,
amount,
assetId: AddressZero,
assetId,
recipient: receiverIdentifier,
};
switch (type) {
case ConditionalTransferTypes.SignedTransfer: {
case ConditionalTransferTypes.GraphTransfer: {
const { chainId } = await this.client.ethProvider.getNetwork();
const receipt = getTestGraphReceiptToSign();
const verifyingContract = getTestVerifyingContract();
Expand Down
8 changes: 4 additions & 4 deletions modules/bot/src/agents/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { utils } from "ethers";
import { Argv } from "yargs";

import { env } from "../env";
import { addAgentIdentifierToIndex, getAgentFromIndex } from "../helpers/agentIndex";
import { externalBotRegistry } from "../helpers/agentIndex";

import { Agent } from "./agent";

Expand Down Expand Up @@ -58,18 +58,18 @@ export default {
nodeIdentifier: ${client.nodeIdentifier}
nodeSignerAddress: ${client.nodeSignerAddress}`);

const agent = new Agent(log, client, argv.privateKey);
const agent = new Agent(log, client, argv.privateKey, true);
log.info("Agent starting up.");
await agent.start();
log.info("Agent started.");

log.info(`Registering address ${client.publicIdentifier}`);
await addAgentIdentifierToIndex(client.publicIdentifier);
await externalBotRegistry.add(client.publicIdentifier);

await agent.depositIfNeeded(TRANSFER_AMT, DEPOSIT_AMT);
await client.requestCollateral(CONVENTION_FOR_ETH_ASSET_ID);

const receiverIdentifier = await getAgentFromIndex(0);
const receiverIdentifier = await externalBotRegistry.get(0);
// the first bot should sit and unlock transactions
if (receiverIdentifier === client.publicIdentifier) {
return;
Expand Down
Loading

0 comments on commit 8f5e1cd

Please sign in to comment.