Skip to content

Commit

Permalink
2.0.58 (#950)
Browse files Browse the repository at this point in the history
* Update version to 2.0.58
* Reduce the number of blockchain calls in getAllPastEvents
* Increase the time interval for getAllPastEvents calls
  • Loading branch information
vukdjoric authored and alexveljkovic committed Jul 19, 2019
1 parent 53f565a commit 7840080
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion modules/Blockchain/Ethereum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion modules/service/dh-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class DHService {

await this.commandExecutor.add({
name: 'dhOfferHandleCommand',
delay: 15000,
delay: 45000,
data,
transactional: false,
});
Expand Down
10 changes: 5 additions & 5 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "2.0.57",
"version": "2.0.58",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand Down

0 comments on commit 7840080

Please sign in to comment.