Skip to content

Commit

Permalink
Merge pull request #1279 from OriginTrail/prerelease/mainnet
Browse files Browse the repository at this point in the history
OriginTrail Mainnet Release v4.1.3
  • Loading branch information
djordjekovac authored Jun 10, 2020
2 parents b60aca5 + 05f1638 commit 91c8113
Show file tree
Hide file tree
Showing 25 changed files with 330 additions and 142 deletions.
5 changes: 4 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"provider": "arangodb",
"username": "root",
"password": "root",
"password_file_name": "arango.txt",
"port": 8529,
"database": "origintrail-develop",
"host": "localhost",
Expand Down Expand Up @@ -152,6 +153,7 @@
"provider": "arangodb",
"username": "root",
"password": "root",
"password_file_name": "arango.txt",
"port": 8529,
"database": "origintrail",
"host": "localhost",
Expand Down Expand Up @@ -222,7 +224,7 @@
"dc_choose_time": 300000,
"requireApproval": false,
"litigationEnabled": true,
"commandExecutorVerboseLoggingEnabled": true,
"commandExecutorVerboseLoggingEnabled": false,
"reputationWindowInMinutes": 129600
},
"mainnet": {
Expand Down Expand Up @@ -267,6 +269,7 @@
"provider": "arangodb",
"username": "root",
"password": "root",
"password_file_name": "arango.txt",
"port": 8529,
"database": "origintrail",
"host": "localhost",
Expand Down
2 changes: 1 addition & 1 deletion modules/ImportUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ class ImportUtilities {
* Fill in dataset header
* @private
*/
static createDatasetHeader(config, transpilationInfo = null, datasetTags = [], datasetTitle = '', datasetDescription = '', OTJSONVersion = '1.0') {
static createDatasetHeader(config, transpilationInfo = null, datasetTags = [], datasetTitle = '', datasetDescription = '', OTJSONVersion = '1.1') {
const header = {
OTJSONVersion,
datasetCreationTimestamp: new Date().toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion modules/OtJsonUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OtJsonUtilities {
static _getDatasetVersion(dataset) {
if (!dataset || !dataset.datasetHeader ||
!dataset.datasetHeader.OTJSONVersion) {
return '1.0';
return '1.1';
// throw new Error('Could not determine dataset ot-json version!');
}
return dataset.datasetHeader.OTJSONVersion;
Expand Down
6 changes: 3 additions & 3 deletions modules/command/dh/dh-offer-finalized-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DhOfferFinalizedCommand extends Command {
await bid.save({ fields: ['status'] });
this.logger.important(`I've been chosen for offer ${offerId}.`);

await this.remoteControl.onCompletedBids();
// await this.remoteControl.onCompletedBids();

if (this.config.disableAutoPayouts !== true) {
const scheduledTime =
Expand All @@ -79,7 +79,7 @@ class DhOfferFinalizedCommand extends Command {
bid.status = 'NOT_CHOSEN';
await bid.save({ fields: ['status'] });
this.logger.important(`I haven't been chosen for offer ${offerId}.`);
await this.remoteControl.onCompletedBids();
// await this.remoteControl.onCompletedBids();
return Command.empty();
}
}
Expand All @@ -97,7 +97,7 @@ class DhOfferFinalizedCommand extends Command {
const bid = await Models.bids.findOne({ where: { offer_id: offerId } });
bid.status = 'NOT_CHOSEN';
await bid.save({ fields: ['status'] });
await this.remoteControl.onCompletedBids();
// await this.remoteControl.onCompletedBids();
return Command.empty();
}

Expand Down
50 changes: 50 additions & 0 deletions modules/controller/info-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const pjson = require('../../package.json');

class InfoController {
constructor(ctx) {
this.logger = ctx.logger;
this.transport = ctx.transport;
this.config = ctx.config;
this.graphStorage = ctx.graphStorage;
}

async getNodeInfo(req, res) {
this.logger.api('GET: Node information request received.');

try {
const network = await this.transport.getNetworkInfo();

const basicConfig = {
version: pjson.version,
blockchain: this.config.blockchain.blockchain_title,
network,
is_bootstrap: this.config.is_bootstrap_node,
};

if (!this.config.is_bootstrap_node) {
const numberOfVertices = await this.graphStorage.getDocumentsCount('ot_vertices');
const numberOfEdges = await this.graphStorage.getDocumentsCount('ot_edges');
Object.assign(basicConfig, {
node_wallet: this.config.node_wallet,
erc_725_identity: this.config.erc725Identity,
graph_size: {
number_of_vertices: numberOfVertices,
number_of_edges: numberOfEdges,
},
});
}

res.status(200);
res.send(basicConfig);
} catch (error) {
this.logger.error(`Failed to process /api/info route. ${error}`);
res.status(500);
res.send({
message: error,
});
}
}
}

module.exports = InfoController;

36 changes: 36 additions & 0 deletions modules/migration/m5-arango-password-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Utilities = require('../Utilities');
const { execSync } = require('child_process');

const fs = require('fs');
const path = require('path');

/**
* Changes the arango password to a randomly generated one
*/
class M5ArangoPasswordMigration {
constructor({
config, log,
}) {
this.config = config;
this.log = log;
}

/**
* Run migration
*/
async run() {
try {
execSync('cp ./scripts/update-arango-password.sh ./');
execSync('chmod +x update-arango-password.sh');
execSync(`./update-arango-password.sh ${this.config.appDataPath} ${this.config.database.host} ${this.config.database.port}`, { stdio: 'inherit' });
execSync('rm ./update-arango-password.sh');
return 0;
} catch (error) {
this.log.error('Arango password update migration failed!');
this.log.error(error);
return -1;
}
}
}

module.exports = M5ArangoPasswordMigration;
22 changes: 14 additions & 8 deletions modules/network/kademlia/kademlia.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,14 @@ class Kademlia {
if (err) {
reject(Error(`Failed to find contact ${contactId}. ${err}`));
}
if (result && Array.isArray(result)) {
const contact = result[0];
if (contact && Array.isArray(contact) && contact.length === 2
const contact = this._getContactFromInterativeFindNodeResult(result);
if (contact && Array.isArray(contact) && contact.length === 2
&& contact[1].hostname && contact[1].port
&& contact[0] === contact[1].identity) {
this.log.debug(`Found proxy contact in routing table. ${contact[0]} - ${contact[1].hostname}:${contact[1].port}`);
accept({ contact, header });
}
reject(Error(`Unknown contact ${contactId}.`));
this.log.debug(`Found proxy contact in routing table. ${contact[0]} - ${contact[1].hostname}:${contact[1].port}`);
accept({ contact, header });
}
reject(Error(`Failed to find contact ${contactId}. Not array: ${result}`));
reject(Error(`Unknown contact ${contactId}.`));
});
});
};
Expand Down Expand Up @@ -845,6 +842,15 @@ class Kademlia {
proof,
}));
}

_getContactFromInterativeFindNodeResult(result) {
for (const contact of result) {
if (contact[0] !== this.config.identity) {
return contact;
}
}
return null;
}
}

module.exports = Kademlia;
2 changes: 1 addition & 1 deletion modules/network/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Transport {
halt(err);
return;
}
this.logger.debug(`Calling ${fn} operation failed at ${iteration} iteration. Contact ${contactId}, ${err}.\n${err.stack}`);
this.logger.debug(`Calling ${fn} operation failed at ${iteration} iteration. Contact ${contactId}, ${err}.}`);
throw err;
}
}, opts);
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 {
transactional: false,
});

await this.remoteControl.getPendingBids();
// await this.remoteControl.getPendingBids();
}

/**
Expand Down
49 changes: 4 additions & 45 deletions modules/service/rest-api-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RestApiController {
this.logger = ctx.logger;
this.apiUtilities = ctx.apiUtilities;
this.emitter = ctx.emitter;

this.infoController = ctx.infoController;
this.version_id = 'controller';

this.restApis = [new RestApiV2(ctx, true)];
Expand Down Expand Up @@ -140,7 +140,9 @@ class RestApiController {
}

_exposeBootstrapAPIRoutes(server) {
this._registerNodeInfoRoute(server, true);
server.get('/api/info', async (req, res) => {
await this.infoController.getNodeInfo(req, res);
});
}

_exposeAPIRoutes(server) {
Expand All @@ -157,49 +159,6 @@ class RestApiController {
});
});
}

/**
* Register common info route
* @param server - Server instance
* @param isBootstrap - Is this a bootstrap node?
* @private
*/
_registerNodeInfoRoute(server, isBootstrap) {
const {
transport,
config,
} = this.ctx;

server.get('/api/info', async (req, res) => {
this.logger.api('GET: Node information request received.');

try {
const network = await transport.getNetworkInfo();
const basicConfig = {
version: pjson.version,
blockchain: config.blockchain.blockchain_title,
network,
is_bootstrap: isBootstrap,
};

if (!isBootstrap) {
Object.assign(basicConfig, {
node_wallet: config.node_wallet,
erc_725_identity: config.erc725Identity,
});
}

res.status(200);
res.send(basicConfig);
} catch (error) {
this.logger.error(`Failed to process /api/info route. ${error}`);
res.status(500);
res.send({
message: error,
});
}
});
}
}

module.exports = RestApiController;
54 changes: 4 additions & 50 deletions modules/service/rest-api-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RestAPIServiceV2 {
this.dcController = ctx.dcController;
this.dhController = ctx.dhController;
this.dvController = ctx.dvController;
this.infoController = ctx.infoController;

this.exportController = ctx.exportController;
this.remoteControl = ctx.remoteControl;
Expand Down Expand Up @@ -53,14 +54,10 @@ class RestAPIServiceV2 {
transport, emitter, blockchain, web3, config,
} = this.ctx;

this._registerNodeInfoRoute(server, false);
server.get(`/api/${this.version_id}/info`, async (req, res) => {
await this.infoController.getNodeInfo(req, res);
});

/**
* Data import route
* @param file - file or text data
* @param standard_id - ID of file standard
* (supported standards are listed in this.standards array)
*/
server.post(`/api/${this.version_id}/import`, async (req, res) => {
await this._importDataset(req, res);
});
Expand Down Expand Up @@ -390,49 +387,6 @@ class RestAPIServiceV2 {
});
}

/**
* Register common info route
* @param server - Server instance
* @param isBootstrap - Is this a bootstrap node?
* @private
*/
_registerNodeInfoRoute(server, isBootstrap) {
const {
transport,
config,
} = this.ctx;

server.get(`/api/${this.version_id}/info`, async (req, res) => {
this.logger.api('GET: Node information request received.');

try {
const network = await transport.getNetworkInfo();
const basicConfig = {
version: pjson.version,
blockchain: config.blockchain.blockchain_title,
network,
is_bootstrap: isBootstrap,
};

if (!isBootstrap) {
Object.assign(basicConfig, {
node_wallet: config.node_wallet,
erc_725_identity: config.erc725Identity,
});
}

res.status(200);
res.send(basicConfig);
} catch (error) {
this.logger.error(`Failed to process /api/info route. ${error}`);
res.status(500);
res.send({
message: error,
});
}
});
}

async _getTrail(req, res) {
this.logger.api('POST: Trail request received.');

Expand Down
2 changes: 1 addition & 1 deletion modules/transpiler/epcis/epcis-otjson-transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ class EpcisOtJsonTranspiler {
return {
transpilationInfo: {
transpilerType: 'GS1-EPCIS',
transpilerVersion: '1.0',
transpilerVersion: '1.1',
sourceMetadata: {
created: created.toISOString(),
modified: created.toISOString(),
Expand Down
Loading

0 comments on commit 91c8113

Please sign in to comment.