Skip to content

Commit

Permalink
Version 2.0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
kipliklotrika committed Dec 4, 2018
2 parents 009f10c + 7edd11e commit 0c7c630
Show file tree
Hide file tree
Showing 24 changed files with 643 additions and 365 deletions.
43 changes: 22 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
dist: xenial
language: node_js
node_js:
- "9"
env:
- NODE_ENV=development
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber
sudo: enabled
addons:
apt:
packages:
- s3cmd
before_script:
- mkdir -p $ARTIFACTS_DIR
- mkdir -p $CUCUMBER_ARTIFACTS_DIR
- echo arangodb3 arangodb/password password root | sudo debconf-set-selections # set username 'root'
- echo arangodb3 arangodb/password_again password root | sudo debconf-set-selections # set password 'root'
- chmod +x setup_arangodb.sh
Expand All @@ -13,34 +20,28 @@ before_script:
- cp .origintrail_noderc.travis .origintrail_noderc
- npm run bootstrap
- npm install -g [email protected] &> /dev/null
- npm install -g [email protected] &> /dev/null
- npm install -g [email protected] &> /dev/null
script:
- npm run lint
- 'if [ "$TRAVIS_EVENT_TYPE" != "push" ]; then npm run test:bdd; fi'
- if [ "$TRAVIS_EVENT_TYPE" != "push" ]; then
npm run test:bdd:dryrun
npm run test:bdd -- --world-parameters '{"appDataBaseDir":"$CUCUMBER_ARTIFACTS_DIR","keepFailedArtifacts":true}';
fi
# checks for arangodb based solution
- npm test 2> mocha-logs.log
- npm start &>arangodb.log &
- npm test 2> $ARTIFACTS_DIR/mocha-logs.log
- npm start &> $ARTIFACTS_DIR/app-start.log &
- sleep 10
- jobs
- if [ -n "$(jobs -p)" ]; then kill %1; fi
# compile and check Smart Contracts
- ganache-cli -i 5777 -p 7545 -l 10000000 -m "aspect ask story desert profit engage tuition leave fade giraffe exclude brief" &>ganache.log &
- ganache-cli -i 5777 -p 7545 -l 10000000 -m "aspect ask story desert profit engage tuition leave fade giraffe exclude brief" &> $ARTIFACTS_DIR/ganache.log &
- cd modules/Blockchain/Ethereum
- truffle test --network test > ../../../truffle-test.log
- rm -rf build && truffle migrate --reset --compile-all --network ganache > ../../../truffle-migrate.log
- cd ../../../
- truffle test --network test > $ARTIFACTS_DIR/truffle-test.log
- rm -rf build && truffle migrate --reset --compile-all --network ganache > $ARTIFACTS_DIR/truffle-migrate.log
- cd $TRAVIS_BUILD_DIR
- jobs
- kill %1
- kill -9 %1
after_script:
- cat mocha-logs.log
- rm -f mocha-logs.log
- cat arangodb.log
- rm -f arangodb.log
- cat truffle-test.log
- rm -f truffle-test.log
- cat truffle-migrate.log
- rm -f truffle-migrate.log
# enable line bellow in case you are interested in reading ganache-cli logs
# - cat ganache.log
- rm -f ganache.log
- s3cmd --acl-public put --recursive $ARTIFACTS_DIR/* s3://ot-travis-ci/${TRAVIS_REPO_SLUG}/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/
- echo "Uploaded to s3://ot-travis-ci/${TRAVIS_REPO_SLUG}/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/"
- kill -9 $(pgrep arangod)
8 changes: 4 additions & 4 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"branch": "develop"
},
"dataSetStorage": "data_set_storage",
"dc_holding_time_in_minutes": 10080,
"dc_holding_time_in_minutes": 60,
"dc_token_amount_per_holder": "50000000000000000000",
"dc_litigation_interval_in_minutes": 5,
"dh_max_holding_time_in_minutes": 10080,
Expand Down Expand Up @@ -189,7 +189,7 @@
"branch": "release/staging"
},
"dataSetStorage": "data_set_storage",
"dc_holding_time_in_minutes": 1440,
"dc_holding_time_in_minutes": 60,
"dc_token_amount_per_holder": "1",
"dc_litigation_interval_in_minutes": 5,
"dh_max_holding_time_in_minutes": 1440,
Expand Down Expand Up @@ -289,7 +289,7 @@
"branch": "release/stable"
},
"dataSetStorage": "data_set_storage",
"dc_holding_time_in_minutes": 10080,
"dc_holding_time_in_minutes": 60,
"dc_token_amount_per_holder": "50000000000000000000",
"dc_litigation_interval_in_minutes": 5,
"dh_max_holding_time_in_minutes": 10080,
Expand Down Expand Up @@ -392,7 +392,7 @@
"branch": "master"
},
"dataSetStorage": "data_set_storage",
"dc_holding_time_in_minutes": 10080,
"dc_holding_time_in_minutes": 60,
"dc_token_amount_per_holder": "50000000000000000000",
"dc_litigation_interval_in_minutes": 5,
"dh_max_holding_time_in_minutes": 10080,
Expand Down
16 changes: 8 additions & 8 deletions modules/Blockchain/Ethereum/contracts/Profile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ contract Profile {
}

require(minimalStake <= profileStorage.getStake(payer).sub(profileStorage.getStakeReserved(payer)),
"Profile does not have enough stake to take new jobs!");
"Data creator does not have enough stake to take new jobs!");
require(minimalStake <= profileStorage.getStake(identity1).sub(profileStorage.getStakeReserved(identity1)),
"Profile does not have enough stake to take new jobs!");
"First profile does not have enough stake to take new jobs!");
require(minimalStake <= profileStorage.getStake(identity2).sub(profileStorage.getStakeReserved(identity2)),
"Profile does not have enough stake to take new jobs!");
"Second profile does not have enough stake to take new jobs!");
require(minimalStake <= profileStorage.getStake(identity3).sub(profileStorage.getStakeReserved(identity3)),
"Profile does not have enough stake to take new jobs!");
"Third profile does not have enough stake to take new jobs!");

require(profileStorage.getStake(payer).sub(profileStorage.getStakeReserved(payer)) >= amount.mul(3),
"Profile does not have enough stake for reserving!");
"Data creator does not have enough stake for reserving!");
require(profileStorage.getStake(identity1).sub(profileStorage.getStakeReserved(identity1)) >= amount,
"Profile does not have enough stake for reserving!");
"First profile does not have enough stake for reserving!");
require(profileStorage.getStake(identity2).sub(profileStorage.getStakeReserved(identity2)) >= amount,
"Profile does not have enough stake for reserving!");
"Second profile does not have enough stake for reserving!");
require(profileStorage.getStake(identity3).sub(profileStorage.getStakeReserved(identity3)) >= amount,
"Profile does not have enough stake for reserving!");
"Third profile does not have enough stake for reserving!");


profileStorage.increaseStakesReserved(
Expand Down
7 changes: 0 additions & 7 deletions modules/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,6 @@ class EventEmitter {

this._on('api-network-query', (data) => {
logger.info(`Network-query handling triggered with query ${JSON.stringify(data.query)}.`);
if (!appState.enoughFunds) {
data.response.status(400);
data.response.send({
message: 'Insufficient funds',
});
return;
}

dvController.queryNetwork(data.query)
.then((queryId) => {
Expand Down
13 changes: 11 additions & 2 deletions modules/GS1Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,12 @@ class GS1Importer {
// eslint-disable-next-line
const { vertices: newDenormalizedVertices, edges: newDenormalizedEdges } = denormalizeGraph(dataSetId, allVertices, allEdges);

allVertices.map((v) => {
newDenormalizedVertices.map((v) => {
v.inTransaction = true;
return v;
});
await Promise.all(newDenormalizedVertices.map(vertex => this.db.addVertex(vertex)));
allEdges.map((e) => {
newDenormalizedEdges.map((e) => {
e.inTransaction = true;
return e;
});
Expand All @@ -824,6 +824,15 @@ class GS1Importer {

await this.db.commit();

normalizedVertices.map((v) => {
delete v.inTransaction;
return v;
});
normalizedEdges.map((e) => {
delete e.inTransaction;
return e;
});

return {
vertices: normalizedVertices,
edges: normalizedEdges,
Expand Down
8 changes: 7 additions & 1 deletion modules/command/dh/dh-offer-handle-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class DHOfferHandleCommand extends Command {
}, dcNodeId);

if (response.status === 'fail') {
throw new Error(`Failed to receive replication from ${dcNodeId} for offer ${offerId}`);
if (response.message) {
throw new Error('Failed to receive replication ' +
`from ${dcNodeId} for offer ${offerId}. ` +
`Reason: ${response.message}`);
} else {
throw new Error(`Failed to receive replication from ${dcNodeId} for offer ${offerId}.`);
}
}

const bid = await Models.bids.findOne({
Expand Down
4 changes: 2 additions & 2 deletions modules/command/dv/dv-data-read-response-free-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Models = require('../../../models/index');
const Command = require('../command');
const ImportUtilities = require('../../ImportUtilities');
const Graph = require('../../Graph');
const Utilities = require('../../Utilities');

/**
* Handles data read response for free.
Expand Down Expand Up @@ -73,10 +74,9 @@ class DVDataReadResponseFreeCommand extends Command {

// Calculate root hash and check is it the same on the SC.
const { vertices, edges } = message.data;

const fingerprint = await this.blockchain.getRootHash(dataSetId);

if (!fingerprint) {
if (!fingerprint || Utilities.isZeroHash(fingerprint)) {
const errorMessage = `Couldn't not find fingerprint for Dc ${dcWallet} and import ID ${dataSetId}`;
this.logger.warn(errorMessage);
networkQuery.status = 'FAILED';
Expand Down
54 changes: 52 additions & 2 deletions modules/network/kademlia/kademlia.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const sleep = require('sleep-async')().Promise;
const leveldown = require('leveldown');
const PeerCache = require('./peer-cache');
const ip = require('ip');
const uuidv4 = require('uuid/v4');

const KadenceUtils = require('@kadenceproject/kadence/lib/utils.js');
const { IncomingMessage, OutgoingMessage } = require('./logger');

Expand Down Expand Up @@ -173,6 +175,48 @@ class Kademlia {
this.log.info('Starting OT Node...');
this.node.eclipse = this.node.plugin(kadence.eclipse());
this.node.quasar = this.node.plugin(kadence.quasar());

const quasarPublish = function (topic, contents, options = {}, callback = () => null) {
if (typeof options === 'function') {
callback = options;
options = {};
}

const publicationId = uuidv4();
const neighbors = [...this.node.router.getClosestContactsToKey(
options.routingKey || this.node.identity.toString('hex'),
kadence.constants.ALPHA * 3,
).entries()];

const errors = [];
let sentSoFar = 0;
async.eachLimit(neighbors, kadence.constants.ALPHA, (contact, done) => {
if (sentSoFar >= kadence.constants.ALPHA) {
// Achieved desired publications.
done();
return;
}
this.node.send(kadence.quasar.QuasarPlugin.PUBLISH_METHOD, {
uuid: publicationId,
topic,
contents,
publishers: [this.node.identity.toString('hex')],
ttl: kadence.constants.MAX_RELAY_HOPS,
}, contact, (error) => {
if (error) {
errors.push(error);
} else {
sentSoFar += 1;
}
done();
});
}, (error) => {
callback(error, sentSoFar);
});
};

this.node.quasar.quasarPublish = quasarPublish.bind(this.node.quasar);

this.log.info('Quasar initialised');
this.node.peercache =
this.node.plugin(PeerCache(path.join(
Expand Down Expand Up @@ -604,11 +648,17 @@ class Kademlia {
node.publish = async (topic, message, opts = {}) => new Promise((resolve, reject) => {
node.quasar.quasarPublish(
topic, message, opts,
(err, res) => {
(err, successfulPublishes) => {
if (err) {
reject(err);
} else {
resolve(res);
if (successfulPublishes.length === 0) {
// Publish failed.
reject(Error('Publish failed.'));
return;
}
this.log.debug(`Published successfully to ${successfulPublishes} peers.`);
resolve();
}
},
);
Expand Down
12 changes: 9 additions & 3 deletions modules/service/dc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ class DCService {
this.logger.info(`Request for replication of offer external ID ${offerId} received. Sender ${identity}`);

if (!offerId || !wallet) {
this.logger.warn('Asked replication without providing offer ID or wallet.');
const message = 'Asked replication without providing offer ID or wallet.';
this.logger.warn(message);
await this.transport.sendResponse(response, { status: 'fail', message });
return;
}

Expand All @@ -239,12 +241,16 @@ class DCService {
],
});
if (!offerModel) {
this.logger.warn(`Replication request for offer external ID ${offerId} that I don't know.`);
const message = `Replication request for offer external ID ${offerId} that I don't know.`;
this.logger.warn(message);
await this.transport.sendResponse(response, { status: 'fail', message });
return;
}
const offer = offerModel.get({ plain: true });
if (offer.status !== 'STARTED') {
this.logger.warn(`Replication request for offer external ${offerId} that is not in STARTED state.`);
const message = `Replication request for offer external ${offerId} that is not in STARTED state.`;
this.logger.warn(message);
await this.transport.sendResponse(response, { status: 'fail', message });
return;
}

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.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "2.0.26",
"version": "2.0.27",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand All @@ -16,8 +16,9 @@
"test:api:nocov": "mocha --exit $(find test/api -name '*.js')",
"test:protocol": "nyc mocha --exit $(find test/protocol -name '*.js')",
"test:protocol:nocov": "mocha --exit $(find test/protocol -name '*.js')",
"test:bdd": "cucumber-js --fail-fast --format progress-bar --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:bdd:cov": " nyc cucumber-js --fail-fast --format progress-bar --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:bdd": "cucumber-js --fail-fast --format progress --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:bdd:dryrun": "cucumber-js --dry-run test/bdd/ -r test/bdd/steps/",
"test:bdd:cov": " nyc cucumber-js --fail-fast --format progress --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"test:bdd:verbose": "cucumber-js --fail-fast --format event-protocol --format-options '{\"colorsEnabled\": true}' test/bdd/ -r test/bdd/steps/",
"start": "node node_version_check.js && node ot-node.js",
"debug:start": "node --nolazy --inspect-brk ot-node.js",
Expand All @@ -31,7 +32,8 @@
"setup:hard:all": "node ./scripts/setup.js --hard --all",
"debug:test:unit": "mocha --inspect-brk --exit $(find test/modules -name '*.js')",
"debug:test:api": "mocha --inspect-brk --exit $(find test/api -name '*.js')",
"debug:test:protocol": "mocha --inspect-brk --exit $(find test/protocol -name '*.js')"
"debug:test:protocol": "mocha --inspect-brk --exit $(find test/protocol -name '*.js')",
"ganache": "ganache-cli -i 5777 -p 8545 -l 10000000 >/dev/null & sleep 5 && tenderly proxy --proxy-port 7545"
},
"devDependencies": {
"babel-eslint": "^8.2.6",
Expand Down
8 changes: 3 additions & 5 deletions test/api/zkGetTrail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ describe('Check ZK by quering /api/trail for EVENT vertices', () => {
inputXmlFiles.forEach((xmlFile) => {
let queryObject;
let myTrail;
it.skip(`zero knowledge status check for EVENT in ${path.basename(xmlFile.args[0])} file`, async () => {
it(`zero knowledge status check for EVENT in ${path.basename(xmlFile.args[0])} file`, async () => {
await gs1.parseGS1(await Utilities.fileContents(xmlFile.args[0]));
switch (path.basename(xmlFile.args[0])) {
case 'Transformation.xml':
queryObject = { uid: 'CARENGINES_PROVIDER_ID:2015-03-15T00:00:00.000-04:00Z-04:00' };
queryObject = { uid: 'urn:ot:object:actor:id:Car.Engines:2015-03-15T00:00:00.000-04:00Z-04:00' };
break;
case 'GraphExample_1.xml':
queryObject = { uid: 'urn:ot:object:actor:id:Company_1:2015-04-17T00:00:00.000-04:00Z-04:00' };
break;
case 'GraphExample_2.xml':
queryObject = { uid: 'SENDER_ID:2015-03-15T00:00:00.000-04:00Z-04:00' };
queryObject = { uid: 'urn:ot:object:actor:id:Company _1:2015-03-15T00:00:00.000-04:00Z-04:00' };
break;
case 'GraphExample_3.xml':
queryObject = { uid: 'urn:ot:object:actor:id:Company_2:2015-04-17T00:00:00.000-04:00Z-04:00' };
Expand All @@ -106,8 +106,6 @@ describe('Check ZK by quering /api/trail for EVENT vertices', () => {

myTrail = await product.getTrailByQuery(queryObject);

assert.isAbove(Object.keys(myTrail).length, 0);

Object.keys(myTrail).forEach((key, index) => {
if (myTrail[key].vertex_type === 'EVENT') {
switch (path.basename(xmlFile.args[0])) {
Expand Down
Loading

0 comments on commit 0c7c630

Please sign in to comment.