Skip to content

Commit

Permalink
For/testnet and kosta (#241)
Browse files Browse the repository at this point in the history
* sendTx: use broadcast_tx_sync..

..instead of broadcast_tx_commit.

We only should check if the tx is valid (passes mempool), but we don't have to
wait until it is included in a block;

* reduce coverage goal

* sendTx: burst `broadcast_tx_async`

add default consensus params, doesn't change current behaviour

* sendTx: Fix test with `Buffer`. Disable error case

* A bunch of things

- Introduce `eth_sendRawTransactionBatch`, for tx batch requests
- Remove Tx encoding in abci, it's useless ***BREAKING CHANGE***
- Remove TxServer (integration tests needs to be fixed)
- Allow to restore state at startup (handshake) after last successful
  submitted period.

Fixes #226

* A few fixes for period handling

Also:
  - add one simple test for `eth_sendRawTransactionBatch`

* remove BlockTicker; is not used anywhere

* Revert "remove BlockTicker; is not used anywhere"

This reverts commit cd99191.

Bullshit, it's used; I didn't catched that :facepalm

* sendTx: lazily fire the drain timer

* bin.js: chmod +x

* Dockerfile: remove chmod bin

* travis: use stages

* restore tx-encoding. Take app_hash from genesis

* tests for bridgeState.{loadState, saveState}

* Revert "reduce coverage goal"

This reverts commit a8318fc.

* lint

* add missing deterministic-json dep

* remove tx-server port references

* check if genesis is not undefined

* Squashed commit of the following:

commit 812f466
Author: Kosta Korenkov <[email protected]>
Date:   Fri Apr 12 18:31:28 2019 +0300

    fix(period): validator fails to resubmit the very first period (#223)

    * fix(period): validator fails to resubmit the very first period

    Because the code was tied to the height which may be higher on the next resubmission

    * test(submitPeriod): refactor and 100% coverage

commit 7e1dc36
Author: pinkiebell <[email protected]>
Date:   Fri Apr 12 17:30:08 2019 +0200

    Dockerfile: remove install of yarn, already included (#225)

* update packages. fix github leapdao packages

* submitPeriod: update test expectation

* fix: github prefix for tendermint-node link in package.json

* docs: add comment regarding time_iota_ms
  • Loading branch information
pinkiebell authored and troggy committed Apr 19, 2019
1 parent 7a710cb commit 31da940
Show file tree
Hide file tree
Showing 27 changed files with 255 additions and 234 deletions.
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
language: node_js
cache: yarn
node_js:
- '8.11'
before_script: yarn global add codecov
script:
- yarn lint
- yarn test
- codecov
- "8.11"
cache: yarn
jobs:
include:
- stage: tests
name: "yarn lint"
script: yarn lint

- stage: tests
name: "yarn test and codecov"
before_script: yarn global add codecov
script:
- yarn test
- codecov
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ARG BUILD_DEPS="git g++ cmake make python2"
WORKDIR /opt/leap-node
RUN apk add --no-cache --update --virtual build_deps $BUILD_DEPS
COPY . /opt/leap-node
RUN chmod 755 bin.js
RUN yarn install --production
RUN yarn link
RUN apk del build_deps
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Your local port `9999` forwards now to the remote host on address `127.0.0.1` an
### Available cli arguments

- `no-validators-updates` — disabling validators set updates (default: false)
- `port` — tx endpoint port (default: 3000)
- `rpcaddr` — host for http RPC server (default: localhost)
- `rpcport` — port for http RPC server (default: 8645)
- `wsaddr` — host for websocket RPC server (default: localhost)
Expand Down
Empty file modified bin.js
100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ services:
- leap-node:/root
ports:
# ATTENTION: if you are going to run this on an untrusted network, guard all ports except `p2p`.
# tx server
- "3000:3000"
# rpc
- "8645:8645"
# ws
Expand Down
22 changes: 3 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ async function run() {
})();

global.app = lotion({
initialState: {
mempool: [],
balances: {}, // stores account balances like this { [colorIndex]: { address1: 0, ... } }
owners: {}, // index for NFT ownerOf call
unspent: {}, // stores unspent outputs (deposits, transfers)
processedDeposit: 0,
slots: [],
epoch: {
epoch: 0,
lastEpochHeight: 0,
epochLength: null,
epochLengthIndex: -1,
},
gas: {
minPrice: 0,
minPriceIndex: -1,
},
},
networkId: `${config.network}-${config.networkId}`,
genesis: config.genesis,
devMode: cliArgs.devMode,
Expand Down Expand Up @@ -110,7 +92,9 @@ async function run() {
app.useBlock(blockHandler(bridgeState, db, nodeConfig));
app.usePeriod(periodHandler(bridgeState));

app.listen(cliArgs.port).then(async params => {
const lastGoodState = await bridgeState.loadState();

app.listen(lastGoodState).then(async params => {
blockTicker.subscribe(eventsRelay.onNewBlock);
await printStartupInfo(params, bridgeState);

Expand Down
64 changes: 12 additions & 52 deletions lotion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ const level = require('level');
const axios = require('axios');
const { join } = require('path');
const ABCIServer = require('./lib/abci-app.js');
const TxServer = require('./lib/tx-server.js');
const Tendermint = require('./lib/tendermint.js');
const rimraf = require('rimraf');
const generateNetworkId = require('./lib/network-id.js');
const getNodeInfo = require('./lib/node-info.js');
const getRoot = require('./lib/get-root.js');
const os = require('os');
const merk = require('merk');
const { EventEmitter } = require('events');

const LOTION_HOME = process.env.LOTION_HOME || join(os.homedir(), '.lotion');
Expand All @@ -33,7 +29,6 @@ function getGenesis(genesisPath) {
}

function Lotion(opts = {}) {
const initialState = opts.initialState || {};
const peers = opts.peers || [];
const logTendermint = opts.logTendermint || false;
const createEmptyBlocks =
Expand All @@ -44,7 +39,6 @@ function Lotion(opts = {}) {
const { unsafeRpc, readonlyValidator } = opts;
const txMiddleware = [];
const queryMiddleware = [];
const initializerMiddleware = [];
const blockMiddleware = [];
const periodMiddleware = [];
const initChainMiddleware = [];
Expand All @@ -59,12 +53,10 @@ function Lotion(opts = {}) {
? JSON.parse(getGenesis(opts.genesis))
: opts.genesis;

const appState = Object.assign({}, initialState);
const bus = new EventEmitter();
let appInfo;
let abciServer;
let tendermint;
let txHTTPServer;
let lotionPath;

const networkId =
Expand All @@ -73,8 +65,6 @@ function Lotion(opts = {}) {
txMiddleware,
blockMiddleware,
queryMiddleware,
initializerMiddleware,
initialState,
devMode,
genesis
);
Expand Down Expand Up @@ -112,8 +102,6 @@ function Lotion(opts = {}) {
appMethods.usePeriod(middleware.middleware);
} else if (middleware.type === 'initChain') {
appMethods.useInitChain(middleware.middleware);
} else if (middleware.type === 'initializer') {
appMethods.useInitializer(middleware.middleware);
} else if (middleware.type === 'post-listen') {
appMethods.usePostListen(middleware.middleware);
}
Expand All @@ -134,44 +122,30 @@ function Lotion(opts = {}) {
useQuery: queryHandler => {
queryMiddleware.push(queryHandler);
},
useInitializer: initializer => {
initializerMiddleware.push(initializer);
},
usePostListen: postListener => {
// TODO: rename "post listen", there's probably a more descriptive name.
postListenMiddleware.push(postListener);
},
listen: txServerPort => {
listen: (store) => {
return new Promise(async resolve => {
// set up abci server, then tendermint node, then tx server
// set up abci server, then tendermint node
const { tendermintPort, abciPort, p2pPort } = await getPorts(
opts.p2pPort,
opts.tendermintPort,
opts.abciPort
);

const { tendermintAddr } = opts;

// initialize merk store
const merkDb = level(join(lotionPath, 'merk'));
const store = await merk(merkDb);

const tendermintRpcUrl = `http://localhost:${tendermintPort}`;

for (const initializer of initializerMiddleware) {
await initializer(appState);
}
Object.assign(store, appState);
const initialAppHash = (await getRoot(store)).toString('hex');
abciServer = ABCIServer({
txMiddleware,
blockMiddleware,
queryMiddleware,
initializerMiddleware,
store,
initialAppHash,
periodMiddleware,
initChainMiddleware,
genesis,
});
abciServer.listen(abciPort, 'localhost');

Expand All @@ -188,7 +162,6 @@ function Lotion(opts = {}) {
peers,
genesis,
keys,
initialAppHash,
unsafeRpc,
readonlyValidator,
});
Expand All @@ -201,34 +174,21 @@ function Lotion(opts = {}) {

await tendermint.synced;

const nodeInfo = await getNodeInfo(lotionPath);
const txServer = TxServer({
tendermintRpcUrl,
store,
nodeInfo,
txEndpoints,
port: txServerPort,
});
txHTTPServer = txServer.listen(txServerPort, 'localhost', () => {
// add some references to useful variables to app object.
appInfo = {
tendermintPort,
abciPort,
txServerPort,
p2pPort,
lotionPath,
genesisPath: join(lotionPath, 'config', 'genesis.json'),
};
appInfo = {
tendermintPort,
abciPort,
p2pPort,
lotionPath,
genesisPath: join(lotionPath, 'config', 'genesis.json'),
};

bus.emit('listen');
resolve(appInfo);
});
bus.emit('listen');
resolve(appInfo);
});
},
close: () => {
abciServer.close();
tendermint.close();
txHTTPServer.close();
},
info: () => appInfo,
lotionPath: () => lotionPath,
Expand Down
39 changes: 14 additions & 25 deletions lotion/lib/abci-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
const createABCIServer = require('js-abci');
const decodeTx = require('./tx-encoding.js').decode;
const jsondiffpatch = require('jsondiffpatch');
const getRoot = require('./get-root.js');
const { stringify } = require('deterministic-json');

const { getAddress } = require('../../src/utils');

Expand Down Expand Up @@ -105,9 +103,9 @@ module.exports = function configureABCIServer({
txMiddleware,
blockMiddleware,
store,
// initialAppHash,
initChainMiddleware,
periodMiddleware,
genesis,
}) {
const chainInfo = {
height: 1,
Expand Down Expand Up @@ -159,10 +157,7 @@ module.exports = function configureABCIServer({
for (const blockHandler of blockMiddleware) {
await blockHandler(store, chainInfo);
}
const appHash = await getRoot(store);
// by returning nothing on commit, we get no empty blocks anymore
// Maybe we return the wrong hash? ;)
// return { data: appHash };

return {};
};

Expand Down Expand Up @@ -202,26 +197,20 @@ module.exports = function configureABCIServer({
return { status: rsp.status };
};

abciApp.query = () => {
try {
return {
value: Buffer.from(stringify(store)),
height: chainInfo.height - 1,
proof: '',
key: '',
index: 0,
code: 0,
log: '',
};
} catch (e) {
return { code: 2, log: `invalid query: ${e.message}` };
abciApp.info = async () => {
const rsp = {};

if (genesis && genesis.app_hash) {
rsp.lastBlockAppHash = Buffer.from(genesis.app_hash, 'hex');
}
};

abciApp.info = async () => {
const rootHash = await getRoot(store);
// TODO: should also return lastBlockHeight
return { lastBlockAppHash: rootHash };
if (store.blockHeight) {
chainInfo.height = store.blockHeight;
// we always save current bridgeState = commited block height + 1
rsp.lastBlockHeight = store.blockHeight - 1;
}

return rsp;
};

const abciServer = createABCIServer(abciApp);
Expand Down
10 changes: 0 additions & 10 deletions lotion/lib/get-root.js

This file was deleted.

16 changes: 0 additions & 16 deletions lotion/lib/node-info.js

This file was deleted.

Loading

0 comments on commit 31da940

Please sign in to comment.