Skip to content

Commit

Permalink
Merge pull request #1168 from OriginTrail/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail Testnet Release v4.0.6
  • Loading branch information
djordjekovac authored Feb 21, 2020
2 parents 54628d3 + 6566522 commit 8c2ddce
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 145 deletions.
41 changes: 41 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# !/bin/sh
# set -x
export PATH=/usr/local/bin:$PATH
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"

# if [[ "$STAGED_FILES" = "" ]]; then
# exit 0
# fi

PASS=true

printf "\nValidating Javascript:\n"

# Check for eslint
if [[ ! -x "$ESLINT" ]]; then
printf "\t\033[41mPlease install ESlint\033[0m (npm i --save-dev eslint)"
exit 1
fi

for FILE in $STAGED_FILES
do
"$ESLINT" "$(git rev-parse --show-toplevel)/$FILE"
if [[ "$?" == 0 ]]; then
printf "\t\033[32mESLint Passed: $FILE\033[0m"
else
printf "\t\033[41mESLint Failed: $FILE\033[0m"
PASS=false
fi
done

printf "\nJavascript validation completed!\n"

if ! $PASS; then
printf "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
exit 1
else
printf "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi

exit $?
21 changes: 21 additions & 0 deletions .github/release-drafter-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name-template: 'OriginTrail Release $NEXT_PATCH_VERSION'
tag-template: "$NEXT_PATCH_VERSION"
version-template: "v$MAJOR.$MINOR.$PATCH"
categories:
- title: '🚀 Features'
labels:
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'bug'
- title: '🧰 Maintenance'
labels:
- 'internal process'
- title: '⚠️ Breaking changes'
labels:
- 'breaking change'
change-template: '- $TITLE (#$NUMBER)'
template: |
# Changes
$CHANGES
21 changes: 0 additions & 21 deletions .github/release-drafter.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# config-name: my-config.yml
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: release-drafter-template.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=second
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=third
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=fourth
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=fifth
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=docker

cache:
Expand Down Expand Up @@ -41,15 +42,15 @@ script:
- if [[ ("$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fourth" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "fourth" ) ]]; then
travis_wait 50 npm run test:bdd -- --tags=@fourth --world-parameters '{"appDataBaseDir":"$CUCUMBER_ARTIFACTS_DIR","keepFailedArtifacts":true}';
fi
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "first" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "first" ) ]]; then
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "first" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "first" ) ]]; then
npm test 2> $ARTIFACTS_DIR/mocha-logs.log;
fi
# compile and check Smart Contracts
- npm run ganache &> $ARTIFACTS_DIR/ganache.log &
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) ]]; then
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) ]]; then
npm run truffle:test > $ARTIFACTS_DIR/truffle-test.log;
fi
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) ]]; then
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) ]]; then
npm run truffle:deploy:ganache > $ARTIFACTS_DIR/truffle-migrate.log;
fi
- if [[ "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ]]; then ./test/docker/check_image.sh; fi
Expand Down
3 changes: 3 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dh_min_stake_amount": "100000000000",
"dh_min_reputation": -50,
"latest_api_version" : "v2.0",
"send_challenges_log" : true,
"database": {
"provider": "arangodb",
"username": "root",
Expand Down Expand Up @@ -140,6 +141,7 @@
"dh_min_stake_amount": "100000000000",
"dh_min_reputation": -50,
"latest_api_version" : "v2.0",
"send_challenges_log" : true,
"database": {
"provider": "arangodb",
"username": "root",
Expand Down Expand Up @@ -249,6 +251,7 @@
"dh_min_stake_amount": "100000000000",
"dh_min_reputation": -50,
"latest_api_version" : "v2.0",
"send_challenges_log" : true,
"database": {
"provider": "arangodb",
"username": "root",
Expand Down
2 changes: 1 addition & 1 deletion modules/command/dc/dc-challenge-check-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DCChallengeCheckCommand extends Command {
});

if (challenge.answer === challenge.expected_answer) {
this.logger.trace('Successfully answered to challenge.');
this.logger.trace(`Holder ${dhIdentity} successfully answered to challenge for offer ${offerId}.`);

replicatedData.status = 'HOLDING';
await replicatedData.save({ fields: ['status'] });
Expand Down
18 changes: 18 additions & 0 deletions modules/command/dh/dh-challenge-command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Command = require('../command');
const models = require('../../../models/index');
const bugsnag = require('bugsnag');

/**
* Handles one data challenge
Expand Down Expand Up @@ -51,6 +52,23 @@ class DHChallengeCommand extends Command {
);
const answer = this.challengeService.answerChallengeQuestion(blockIndex, otObject);

if (this.config.send_challenges_log) {
const bugsnagMessage = 'DH challenge answer';
bugsnag.notify(bugsnagMessage, {
user: {
dh_node_id: this.config.identity,
dc_identity: litigatorNodeId,
challenge_id: challengeId,
data_set_id: datasetId,
object_index: objectIndex,
block_index: blockIndex,
answer,
otObject,
},
severity: 'info',
});
}

this.logger.info(`Calculated answer for dataset ${datasetId}, color ${color}, object index ${objectIndex}, and block index ${blockIndex} is ${answer}`);
try {
await this.transport.challengeResponse({
Expand Down
101 changes: 48 additions & 53 deletions modules/network/kademlia/kademlia.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Kademlia {
kadence.constants.T_RESPONSETIMEOUT = this.config.request_timeout;
kadence.constants.SOLUTION_DIFFICULTY = this.config.network.solutionDifficulty;
kadence.constants.IDENTITY_DIFFICULTY = this.config.network.identityDifficulty;
kadence.constants.ALPHA = kadence.constants.K + 1;
this.log.info(`Network solution difficulty ${kadence.constants.SOLUTION_DIFFICULTY}.`);
this.log.info(`Network identity difficulty ${kadence.constants.IDENTITY_DIFFICULTY}.`);
}
Expand Down Expand Up @@ -226,30 +227,26 @@ class Kademlia {

this._registerRoutes();

this.node.listen(this.config.node_port, async () => {
this.node.listen(this.config.node_port, () => {
this.log.notify(`OT Node listening at https://${this.node.contact.hostname}:${this.node.contact.port}`);
this.kademliaUtilities.registerControlInterface(this.config, this.node);

const connected = false;
const retryPeriodSeconds = 5;
while (!connected) {
try {
// eslint-disable-next-line
const connected = await this._joinNetwork();
if (connected) {
this.log.info('Joined to the network.');
resolve();
break;
}
} catch (e) {
this.log.error(`Failed to join network ${e}`);
this.notifyError(e);
async.retry({
times: Infinity,
interval: 60000,
}, done => this.joinNetwork(done), (err, entry) => {
if (err) {
this.log.error(`Failed to join network ${err}`);
this.notifyError(err);
process.exit(1);
}

this.log.trace(`Not joined to the network. Retrying in ${retryPeriodSeconds} seconds. Bootstrap nodes are probably not online.`);
// eslint-disable-next-line
await sleep.sleep(retryPeriodSeconds * 1000);
}
if (entry) {
this.log.info(`connected to network via ${entry}`);
this.log.info(`discovered ${this.node.router.size} peers from seed`);
}
resolve();
});
});
});
}
Expand All @@ -275,43 +272,41 @@ class Kademlia {
* Try to join network
* Note: this method tries to find possible bootstrap nodes
*/
async _joinNetwork() {
return new Promise(async (accept, reject) => {
const bootstrapNodes = this.config.network.bootstraps;
utilities.shuffle(bootstrapNodes);
async joinNetwork(callback) {
let peers = Array.from(new Set(this.config.network.bootstraps
.concat(await this.node.rolodex.getBootstrapCandidates())));
peers = utilities.shuffle(peers);

if (peers.length === 0) {
this.log.info('no bootstrap seeds provided and no known profiles');
this.log.info('running in seed mode (waiting for connections)');

callback(null, null);

return this.node.router.events.once('add', (identity) => {
this.config.network.bootstraps = [
kadence.utils.getContactURL([
identity,
this.node.router.getContactByNodeId(identity),
]),
];
this.joinNetwork(callback);
});
}

if (this.config.is_bootstrap_node) {
this.log.info(`Found ${bootstrapNodes.length} provided bootstrap node(s). Running as a Bootstrap node`);
this.log.info(`joining network from ${peers.length} seeds`);
async.detectSeries(peers, (url, done) => {
const contact = kadence.utils.parseContactURL(url);
this.node.join(contact, (err) => {
done(null, (!err) && this.node.router.size > 0);
});
}, (err, result) => {
if (!result) {
this.log.error('failed to join network, will retry in 1 minute');
callback(new Error('Failed to join network'));
} else {
this.log.info(`Found ${bootstrapNodes.length} provided bootstrap node(s)`);
callback(null, result);
}

this.log.info(`Sync with network from ${bootstrapNodes.length} unique peers`);
if (bootstrapNodes.length === 0) {
this.log.info('No bootstrap seeds provided and no known profiles');
this.log.info('Running in seed mode (waiting for connections)');
accept(true);
return;
}

let connected = false;
const promises = bootstrapNodes.map(address => new Promise((acc, rej) => {
const contact = kadence.utils.parseContactURL(address);
this.log.debug(`Joining ${address}`);
this.node.join(contact, (err) => {
if (err) {
this.log.warn(`Failed to join ${address}`);
acc(false);
return;
}
this.log.trace(`Finished joining to ${address}`);
connected = this._isConnected();
acc(true);
});
}));

await Promise.all(promises);
accept(connected);
});
}

Expand Down
Loading

0 comments on commit 8c2ddce

Please sign in to comment.