Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
🔀 Merge branch 'master' into global-prod-ops
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Oct 8, 2020
2 parents 4d3aceb + c0104fd commit 4bca931
Show file tree
Hide file tree
Showing 117 changed files with 30,240 additions and 18,600 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ jobs:
- run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- run: make push

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- run: pip install mkdocs-material
- run: cd modules/docs
- run: mkdocs gh-deploy --force
- run: cd ../..

utils:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ modules/server-node/migrations/migrate.lock

# Docs
modules/client/docs
modules/documentation/site

# IDEs and editors
**/*.launch
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ test-server-node: node
watch-server-node: engine
bash ops/test-server-node.sh watch

test-browser-node: browser-node-bundle
bash ops/test-unit.sh browser-node test
watch-browser-node: browser-node-bundle
bash ops/test-unit.sh browser-node watch

test-router: router
bash ops/test-unit.sh router test
watch-router: engine
Expand Down Expand Up @@ -260,11 +265,16 @@ auth: auth-bundle $(shell find modules/auth/ops $(find_options))
docker tag $(project)_auth $(project)_auth:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@

browser-node-bundle: engine $(shell find modules/browser-node $(find_options))
browser-node: engine $(shell find modules/browser-node $(find_options))
$(log_start)
$(docker_run) "cd modules/browser-node && npm run build && touch src/index.ts"
$(log_finish) && mv -f $(totalTime) .flags/$@

browser-node-test-ui: engine $(shell find modules/browser-node-test-ui $(find_options))
$(log_start)
$(docker_run) "cd modules/browser-node-test-ui && npm run build && touch src/index.ts"
$(log_finish) && mv -f $(totalTime) .flags/$@

server-node-bundle: engine $(shell find modules/server-node $(find_options))
$(log_start)
$(docker_run) "cd modules/server-node && npm run build && touch src/index.ts"
Expand Down
95 changes: 52 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ There is an additional `config-prod.json` file that can apply to either the node
Any of these values can be overwritten by providing the same key with a new value to `config-prod.json`.

**Node Config Keys:**
- `adminToken` (type: `string`): Currently, this is only used during development to protect a few admin endpoints eg to reset the database between tests. If/when we add admin-only features in prod, they will only be accessible to those who provide the correct adminToken.
- `authUrl` (type: `string`): The url used to authenticate with the messaging service (TODO: merge this with the nats url?)
- `chainAddresses` (type: `object`): Specifies the addresses of all relevant contracts, keyed by `chainId`.
- `chainProviders` (type: `object`): Specifies the URL to use to connect to each chain's provider, keyed by `chainId`
- `logLevel` (type: `string`): one of `"debug"`, `"info"`, `"warn"`, `"error"` to specify the maximum log level that will be printed.
- `mnemonic` (type: `string`): Optional. If provided, the node will use this mnemonic. If not provided, the node will use a hard coded mnemonic with testnet funds in dev-mode (production=false). If not provided in prod, docker secrets will be used to manage the mnemonic; this is a much safer place to store a mnemonic that eg holds mainnet funds.
- `natsUrl` (type: `string`): The URL of the messaging service (TODO: merge with auth url?)
- `port` (type: `number`): The port number on which the stack should be exposed to the outside world.
- `redisUrl` (type: `string`): The URL of the redis instance used to negotiate channel-locks.

- `adminToken` (type: `string`): Currently, this is only used during development to protect a few admin endpoints eg to reset the database between tests. If/when we add admin-only features in prod, they will only be accessible to those who provide the correct adminToken.
- `authUrl` (type: `string`): The url used to authenticate with the messaging service (TODO: merge this with the nats url?)
- `chainAddresses` (type: `object`): Specifies the addresses of all relevant contracts, keyed by `chainId`.
- `chainProviders` (type: `object`): Specifies the URL to use to connect to each chain's provider, keyed by `chainId`
- `logLevel` (type: `string`): one of `"debug"`, `"info"`, `"warn"`, `"error"` to specify the maximum log level that will be printed.
- `mnemonic` (type: `string`): Optional. If provided, the node will use this mnemonic. If not provided, the node will use a hard coded mnemonic with testnet funds in dev-mode (production=false). If not provided in prod, docker secrets will be used to manage the mnemonic; this is a much safer place to store a mnemonic that eg holds mainnet funds.
- `natsUrl` (type: `string`): The URL of the messaging service (TODO: merge with auth url?)
- `port` (type: `number`): The port number on which the stack should be exposed to the outside world.
- `redisUrl` (type: `string`): The URL of the redis instance used to negotiate channel-locks.

### Router Configuration API

Expand All @@ -113,10 +114,11 @@ The router's node can be configured by adding any of the keys in `config-node.js
Any config values for either the router or the node can be overwritten by adding the same key with a new value to `config-prod.json`. This is a good strategy if this machine will only be running a routing node bc these prod config changes will also be applied to a `node` stack thats running on the same machine.

**Router Config Keys:**
- `allowedSwaps` (type: `object`): Specifies which swaps are allowed & how swap rates are determined.
- `nodeUrl` (type: `string`): The URL of the node instance used to power the router's channels.
- `port` (type: `number`): The port number on which the stack should be exposed to the outside world.
- `rebalanceProfiles` (type: `object`): Specifies the thresholds & target while collateralizing some `assetId` on some `chainId`.

- `allowedSwaps` (type: `object`): Specifies which swaps are allowed & how swap rates are determined.
- `nodeUrl` (type: `string`): The URL of the node instance used to power the router's channels.
- `port` (type: `number`): The port number on which the stack should be exposed to the outside world.
- `rebalanceProfiles` (type: `object`): Specifies the thresholds & target while collateralizing some `assetId` on some `chainId`.

### Prod Configuration API

Expand All @@ -125,13 +127,14 @@ Changes to `config-prod.json` aren't tracked by git so this is a good place to s
Be careful, changes to this file will be applied to both `node` & `router` stacks running on this machine.

**Prod Config Keys:**
- `awsAccessId` (type: `string`): An API KEY id that specifies credentials for a remote AWS S3 bucket for storing db backups
- `awsAccessKey` (type: `string`): An API KEY secret that to authenticate on a remote AWS S3 bucket for storing db backups.
- `domainName` (type: `string`): If provided, https will be auto-configured & the stack will be exposed on port 443.
- `production` (type: `boolean`): Enables prod-mode if true. Implications of this flag:
- if `false`, ops will automatically build anything that isn't available locally before starting up a given stack. If `true`, nothing will be built locally. Instead, all images will be pulled from docker hub.
- if `false`, the `global` stack will start up 2 local testnet evm.
- Mnemonic handling is affected, see docs for the `mnemonic` key in node config.

- `awsAccessId` (type: `string`): An API KEY id that specifies credentials for a remote AWS S3 bucket for storing db backups
- `awsAccessKey` (type: `string`): An API KEY secret that to authenticate on a remote AWS S3 bucket for storing db backups.
- `domainName` (type: `string`): If provided, https will be auto-configured & the stack will be exposed on port 443.
- `production` (type: `boolean`): Enables prod-mode if true. Implications of this flag:
- if `false`, ops will automatically build anything that isn't available locally before starting up a given stack. If `true`, nothing will be built locally. Instead, all images will be pulled from docker hub.
- if `false`, the `global` stack will start up 2 local testnet evm.
- Mnemonic handling is affected, see docs for the `mnemonic` key in node config.

## Architecture and Module Breakdown

Expand Down Expand Up @@ -176,43 +179,47 @@ The above command will spin up three server-nodes, one with an attached router i

Once you have the above trio set up, you can interact with your nodes via a REST interface. We've documented [example requests](https://github.com/connext/vector/tree/master/modules/server-node/examples) in the server-node module. If you're developing with VSCode, there are several REST client plugins available in the marketplace that you can use to make these queries _directly from the examples_.

First, set up your channels from Alice -> Roger and Roger -> Bob (in [1_Setup](https://github.com/connext/vector/blob/master/modules/server-node/examples/1-setup.http)):
First, set up your channels from Alice -> Roger and Roger -> Bob (in [1_Setup](https://github.com/connext/vector/blob/master/modules/server-node/examples/1-setup.http)). Note `aliceUrl` is the internal URL that Carol has access to on the Docker network. In these examples, Carol and Dave are requesting Roger to set up the channel with them so that they can be the "Bob" within the channel, which lets them deposit by transferrring directly into the channel address.:

```
### Node -> Alice
POST {{nodeUrl}}/setup
### Node -> Carol
POST {{carolUrl}}/request-setup
Content-Type: application/json
{
"counterpartyIdentifier": "{{alicePublicIdentifier}}",
"aliceUrl": "http://roger:8000",
"chainId": "{{chainId}}",
"timeout": "36000",
"publicIdentifier": "{{nodePublicIdentifier}}"
"timeout": "36000"
}
### Node -> Bob
POST {{nodeUrl}}/setup
### Node -> Dave
POST {{daveUrl}}/request-setup
Content-Type: application/json
{
"counterpartyIdentifier": "{{bobPublicIdentifier}}",
"aliceUrl": "http://roger:8000",
"chainId": "{{chainId}}",
"timeout": "36000",
"publicIdentifier": "{{nodePublicIdentifier}}"
"timeout": "36000"
}
```

Then, send an Eth deposit to Alice's channel onchain (in [2_deposit](https://github.com/connext/vector/blob/master/modules/server-node/examples/2-deposit.http)):
Then, send an Eth deposit to Alice's channel onchain. This can be done by connecting Metamask to your local EVM at `http://localhost:8545` and sending a transfer directly to the `channelAddress`, at any time, regardless of either channel participant's liveness status. A convenient way to do this using HTTP JSON-RPC calls is with a POST request:

```
POST {{aliceUrl}}/send-deposit-tx
# Send a transaction to {{channelAddress}} for 100000000000000000 Wei
POST http://localhost:8545
Content-Type: application/json
{
"channelAddress": "{{aliceNodeChannel}}",
"amount": "{{ethAmount}}",
"assetId": "0x0000000000000000000000000000000000000000",
"publicIdentifier": "{{alicePublicIdentifier}}"
"jsonrpc":"2.0",
"method":"eth_sendTransaction",
"params":[{
"from": "0x627306090abaB3A6e1400e9345bC60c78a8BEf57",
"to": "{{channelAddress}}",
"value": "0x16345785d8a0000",
"data": "0x0"
}],
"id":1
}
```

Expand All @@ -224,8 +231,7 @@ Content-Type: application/json
{
"channelAddress": "{{aliceNodeChannel}}",
"assetId": "0x0000000000000000000000000000000000000000",
"publicIdentifier": "{{alicePublicIdentifier}}"
"assetId": "0x0000000000000000000000000000000000000000"
}
```

Expand All @@ -247,8 +253,7 @@ Content-Type: application/json
"recipient": "{{bobPublicIdentifier}}",
"meta": {
"hello": "world"
},
"publicIdentifier": "{{alicePublicIdentifier}}"
}
}
```

Expand All @@ -261,8 +266,7 @@ Content-Type: application/json
{
"channelAddress": "{{aliceBobChannel}}",
"routingId": "{{routingId}}",
"preImage": "{{preImage}}",
"publicIdentifier": "{{bobPublicIdentifier}}"
"preImage": "{{preImage}}"
}
```

Expand Down Expand Up @@ -312,6 +316,11 @@ const evts = {
evt: Evt.create<ConditionalTransferResolvedPayload>(),
url: `${routerBase}${conditionalTransferResolvedPath}`,
},
[EngineEvents.SETUP]: {},
[EngineEvents.WITHDRAWAL_CREATED]: {},
[EngineEvents.WITHDRAWAL_RESOLVED]: {},
[EngineEvents.WITHDRAWAL_RECONCILED]: {},
[EngineEvents.DEPOSIT_RECONCILED]: {},
};

const logger = pino();
Expand Down
1 change: 1 addition & 0 deletions modules/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@sinclair/typebox": "0.10.1",
"crypto": "1.0.1",
"fastify": "3.4.1",
"fastify-cors": "^4.1.0",
"pino": "6.6.1",
"ts-natsutil": "1.1.1"
},
Expand Down
9 changes: 8 additions & 1 deletion modules/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fastify from "fastify";
import fastifyCors from "fastify-cors";
import pino from "pino";

import { MessagingAuthService } from "./auth/messaging-auth-service";
Expand All @@ -16,6 +17,12 @@ const logger = pino({ level: "info" });

const server = fastify({ logger });

server.register(fastifyCors, {
origin: "*",
methods: ["GET", "PUT", "POST", "OPTIONS"],
preflightContinue: true,
});

const messagingService = new MessagingAuthService(
{
messagingUrl: config.messagingUrl,
Expand Down Expand Up @@ -53,7 +60,7 @@ server.post<{ Body: PostAuthRequestBody }>(
},
);

server.listen(config.port, "0.0.0.0", (err) => {
server.listen(config.port, "0.0.0.0", err => {
if (err) {
console.error(err);
process.exit(1);
Expand Down
2 changes: 2 additions & 0 deletions modules/browser-node-test-ui/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SKIP_PREFLIGHT_CHECK=true
REACT_APP_VECTOR_CONFIG='{"adminToken":"cxt1234","authUrl":"http://localhost:5040","logLevel":"info","chainAddresses":{"1337":{"channelMastercopyAddress":"0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0","channelFactoryAddress":"0xF12b5dd4EAD5F743C6BaA640B0216200e89B60Da","hashlockTransferAddress":"0x345cA3e014Aaf5dcA488057592ee47305D9B3e10","withdrawAddress":"0xf25186B5081Ff5cE73482AD761DB0eB0d25abfBF","testTokenAddress":"0x8f0483125FCb9aaAEFA9209D8E9d7b9C8B9Fb90F"},"1338":{"channelMastercopyAddress":"0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0","channelFactoryAddress":"0xF12b5dd4EAD5F743C6BaA640B0216200e89B60Da","hashlockTransferAddress":"0x345cA3e014Aaf5dcA488057592ee47305D9B3e10","withdrawAddress":"0xf25186B5081Ff5cE73482AD761DB0eB0d25abfBF","testTokenAddress":"0x8f0483125FCb9aaAEFA9209D8E9d7b9C8B9Fb90F"}},"chainProviders":{"1337":"http://localhost:8545","1338":"http://localhost:8546"},"natsUrl":"ws://localhost:4221","port":3001,"redisUrl":"redis://localhost:6379"}'
23 changes: 23 additions & 0 deletions modules/browser-node-test-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
13 changes: 13 additions & 0 deletions modules/browser-node-test-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Browser Node Test UI

Basic UI to test that `browser-node` comes up properly.

## Setup

- Create `.env` file that matches the structure of the `.env-example` in this module.

## Running

- Run `make start-global` from repo root.
- Run `make browser-node` to link all packages and the `browser-node` bundle.
- Run `npm start` in this module.
40 changes: 40 additions & 0 deletions modules/browser-node-test-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "browser-node-test-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@connext/browser-node": "0.0.1",
"@connext/vector-utils": "0.0.1",
"@connext/vector-types": "0.0.1",
"@types/node": "14.11.2",
"@types/react": "^16.9.51",
"@types/react-dom": "^16.9.8",
"antd": "^4.6.6",
"pino": "6.6.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"typescript": "4.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added modules/browser-node-test-ui/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions modules/browser-node-test-ui/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added modules/browser-node-test-ui/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/browser-node-test-ui/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4bca931

Please sign in to comment.