Skip to content

Commit

Permalink
Allow to run validator without producing blocks (#194)
Browse files Browse the repository at this point in the history
* allow to run validator without producing blocks

* add --unsafeRpc flag

* use tendermint 0.26.4.1-leap (the one with SetReadonly RPC)

* add READONLY and UNSAFE_RPC envs to dockerfile

* stick ethereumjs-vm version to 2.4.0

* use tendermint 0.26.4.2-leap
  • Loading branch information
troggy authored Mar 11, 2019
1 parent 76ed0e4 commit c18c545
Show file tree
Hide file tree
Showing 8 changed files with 1,424 additions and 368 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ENV WS_ADDR "0.0.0.0"
ENV WS_PORT "8646"
ENV P2P_PORT "46691"
ENV TENDERMINT_ADDR "0.0.0.0"
ENV READONLY "false"
ENV UNSAFE_RPC "false"
# Either CONFIG_URL or NETWORK needs to be defined, CONFIG_URL takes precedence
ENV CONFIG_URL "http://node1.testnet.leapdao.org:8645"
# for presets/leap-NETWORK
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ services:
- "CONFIG_URL=${CONFIG_URL}"
- "NETWORK=${NETWORK}"
- "PRIVATE_KEY=${PRIVATE_KEY}"
- "READONLY=${READONLY}"
- "UNSAFE_RPC=${UNSAFE_RPC}"
stdin_open: true
tty: true
deploy:
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ async function run() {
log.replace(/I\[\d{2}-\d{2}\|\d{2}:\d{2}:\d{2}\.\d{3}\] /g, '')
);
},
unsafeRpc: cliArgs.unsafeRpc,
readonlyValidator: cliArgs.readonly,
});

if (cliArgs.fresh) {
Expand Down
3 changes: 2 additions & 1 deletion lotion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Lotion(opts = {}) {
? true
: opts.createEmptyBlocks;
const devMode = opts.devMode || false;
const { unsafeRpc } = opts;
const { unsafeRpc, readonlyValidator } = opts;
const txMiddleware = [];
const queryMiddleware = [];
const initializerMiddleware = [];
Expand Down Expand Up @@ -190,6 +190,7 @@ function Lotion(opts = {}) {
keys,
initialAppHash,
unsafeRpc,
readonlyValidator,
});
} catch (e) {
console.log('error starting tendermint node:');
Expand Down
8 changes: 7 additions & 1 deletion lotion/lib/tendermint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = async ({
initialAppHash,
createEmptyBlocks,
unsafeRpc,
readonlyValidator,
}) => {
await tendermint.init(lotionPath);

Expand Down Expand Up @@ -59,12 +60,17 @@ module.exports = async ({
if (unsafeRpc) {
opts.rpc.unsafe = true;
}
opts.consensus = {};
if (createEmptyBlocks === false) {
opts.consensus = { createEmptyBlocks: false };
opts.consensus.createEmptyBlocks = false;
}

if (!logTendermint) {
opts.logLevel = 'error';
}
if (readonlyValidator) {
opts.consensus.readonly = true;
}

let shuttingDown = false;
const tendermintProcess = tendermint.node(lotionPath, opts);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"ethereumjs-account": "^2.0.5",
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "6.0.0",
"ethereumjs-vm": "^2.4.0",
"ethereumjs-vm": "2.4.0",
"express": "^4.16.3",
"express-http-proxy": "^1.0.7",
"fs-extra": "^5.0.0",
Expand All @@ -69,7 +69,7 @@
"rimraf": "^2.6.2",
"rpc-websockets": "^4.1.2",
"tendermint": "^3.1.9",
"tendermint-node": "leapdao/tendermint-node#30b7369dcfe05abf60baf44a072691559baf6eaf",
"tendermint-node": "leapdao/tendermint-node#0ec65fb8ceed44a06b083e22c5b879a0df586396",
"tinyqueue": "^2.0.0",
"truffle-hdwallet-provider": "^1.0.3",
"varstruct": "^6.1.1",
Expand Down
19 changes: 19 additions & 0 deletions src/utils/cliArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ const options = [
default: false,
help: 'Start node with fresh state',
},
{
names: ['readonly'],
type: 'bool',
default: false,
env: 'READONLY',
help: 'Run validator without producing blocks, only observing',
},
{
names: ['unsafeRpc'],
type: 'bool',
default: false,
env: 'UNSAFE_RPC',
help: 'Run unsafe Tendermint RPC',
},
];

const parser = dashdash.createParser({ options });
Expand Down Expand Up @@ -153,4 +167,9 @@ if (cliArgs.privateKey && !fs.existsSync(cliArgs.privateKey)) {
process.exit(0);
}

if (cliArgs.readonly && !cliArgs.unsafeRpc) {
console.log('--readonly flag requires --unsafeRpc');
process.exit(0);
}

module.exports = cliArgs;
Loading

0 comments on commit c18c545

Please sign in to comment.