From 784008077d38eb93378e39ec2ae346707ef71a3e Mon Sep 17 00:00:00 2001 From: Vuk Djoric Date: Fri, 19 Jul 2019 18:18:38 +0200 Subject: [PATCH] 2.0.58 (#950) * Update version to 2.0.58 * Reduce the number of blockchain calls in getAllPastEvents * Increase the time interval for getAllPastEvents calls --- .travis.yml | 3 ++- modules/Blockchain/Ethereum/index.js | 16 +++++++++++++++- modules/service/dh-service.js | 2 +- ot-node.js | 10 +++++----- package-lock.json | 2 +- package.json | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a33c7003..d3f579281 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: env: - NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=first - NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=second - +cache: + npm: false sudo: enabled addons: apt: diff --git a/modules/Blockchain/Ethereum/index.js b/modules/Blockchain/Ethereum/index.js index b5f66437c..f101ef26a 100644 --- a/modules/Blockchain/Ethereum/index.js +++ b/modules/Blockchain/Ethereum/index.js @@ -515,13 +515,27 @@ class Ethereum { ); } + /** + * Gets the current block if one wasn't retrieved in the last 10 seconds + * @returns {int} + */ + async getCurrentBlock() { + const timeout = 10000; + if (this.lastBlockCheck == null || this.lastBlockCheck + timeout < Date.now()) { + this.lastBlock = await this.web3.eth.getBlockNumber(); + this.lastBlockCheck = Date.now(); + } + + return this.lastBlock; + } + /** * Gets all past events for the contract * @param contractName */ async getAllPastEvents(contractName) { try { - const currentBlock = await this.web3.eth.getBlockNumber(); + const currentBlock = await this.getCurrentBlock(); let fromBlock = 0; diff --git a/modules/service/dh-service.js b/modules/service/dh-service.js index 2b294242e..42f5d3d48 100644 --- a/modules/service/dh-service.js +++ b/modules/service/dh-service.js @@ -170,7 +170,7 @@ class DHService { await this.commandExecutor.add({ name: 'dhOfferHandleCommand', - delay: 15000, + delay: 45000, data, transactional: false, }); diff --git a/ot-node.js b/ot-node.js index a78b8bec8..738c4a453 100644 --- a/ot-node.js +++ b/ot-node.js @@ -566,15 +566,15 @@ class OTNode { listenBlockchainEvents(blockchain) { log.info('Starting blockchain event listener'); - const delay = 10000; + const delay = 20000; let working = false; let deadline = Date.now(); - setInterval(() => { + setInterval(async () => { if (!working && Date.now() > deadline) { working = true; - blockchain.getAllPastEvents('HOLDING_CONTRACT'); - blockchain.getAllPastEvents('PROFILE_CONTRACT'); - blockchain.getAllPastEvents('APPROVAL_CONTRACT'); + await blockchain.getAllPastEvents('HOLDING_CONTRACT'); + await blockchain.getAllPastEvents('PROFILE_CONTRACT'); + await blockchain.getAllPastEvents('APPROVAL_CONTRACT'); deadline = Date.now() + delay; working = false; } diff --git a/package-lock.json b/package-lock.json index be3c57a19..bec7456b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "2.0.57", + "version": "2.0.58", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 12f5b29c9..37561b9f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "2.0.57", + "version": "2.0.58", "description": "OriginTrail node", "main": ".eslintrc.js", "config": {