Skip to content

Commit

Permalink
Merge pull request #1523 from OriginTrail/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail Testnet Release v5.0.2
  • Loading branch information
djordjekovac authored Apr 23, 2021
2 parents 290de7b + b897bb8 commit 96bc9b9
Show file tree
Hide file tree
Showing 41 changed files with 971 additions and 123 deletions.
15 changes: 15 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@
"username": "ot_node",
"password": "origintrail",
"root_user_password": "origintrail"
},
"dataset_pruning": {
"enabled": false,
"imported_pruning_delay_in_minutes": 1440,
"replicated_pruning_delay_in_minutes": 1440
}
},
"testnet": {
Expand Down Expand Up @@ -412,6 +417,11 @@
"username": "ot_node",
"password": "origintrail",
"root_user_password": "origintrail"
},
"dataset_pruning": {
"enabled": false,
"imported_pruning_delay_in_minutes": 1440,
"replicated_pruning_delay_in_minutes": 1440
}
},
"mainnet": {
Expand Down Expand Up @@ -580,6 +590,11 @@
"username": "ot_node",
"password": "origintrail",
"root_user_password": "origintrail"
},
"dataset_pruning": {
"enabled": false,
"imported_pruning_delay_in_minutes": 1440,
"replicated_pruning_delay_in_minutes": 1440
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'testnet';
}

const environmentConfig = global_config[process.env.NODE_ENV];
const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'testnet';
}

const environmentConfig = global_config[process.env.NODE_ENV];
const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion migrations/202011261243123-update-bids-add-blockchain-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'testnet';
}

const environmentConfig = global_config[process.env.NODE_ENV];
const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'testnet';
}

const environmentConfig = global_config[process.env.NODE_ENV];
const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if (!process.env.NODE_ENV) {
// Environment not set. Use the production.
process.env.NODE_ENV = 'testnet';
}
const environmentConfig = global_config[process.env.NODE_ENV];

const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if (!process.env.NODE_ENV) {
// Environment not set. Use the production.
process.env.NODE_ENV = 'testnet';
}
const environmentConfig = global_config[process.env.NODE_ENV];

const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if (!process.env.NODE_ENV) {
// Environment not set. Use the production.
process.env.NODE_ENV = 'testnet';
}
const environmentConfig = global_config[process.env.NODE_ENV];

const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if (!process.env.NODE_ENV) {
// Environment not set. Use the production.
process.env.NODE_ENV = 'testnet';
}
const environmentConfig = global_config[process.env.NODE_ENV];

const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if (!process.env.NODE_ENV) {
// Environment not set. Use the production.
process.env.NODE_ENV = 'testnet';
}
const environmentConfig = global_config[process.env.NODE_ENV];

const environment = process.env.NODE_ENV === 'mariner' ? 'mainnet' : process.env.NODE_ENV;
if (['mainnet', 'testnet', 'development'].indexOf(environment) < 0) {
throw Error(`Unsupported node environment ${environment}`);
}
const environmentConfig = global_config[environment];
const blockchain_id = environmentConfig.blockchain.implementations[0].network_id;

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(
'offers',
'replication_start_timestamp',
{
type: Sequelize.STRING,
},
);
},
down: async (queryInterface) => {
await queryInterface.removeColumn('offers', 'replication_start_timestamp');
},
};
26 changes: 26 additions & 0 deletions migrations/202104201448124-create-pruning-history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('pruning_history', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.STRING,
},
data_set_id: {
allowNull: false,
type: Sequelize.STRING,
},
imported_timestamp: {
allowNull: false,
type: Sequelize.STRING,
},
pruned_timestamp: {
allowNull: false,
type: Sequelize.STRING,
},
});
},
down: async (queryInterface) => {
await queryInterface.dropTable('pruning_history');
},
};
1 change: 1 addition & 0 deletions models/offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = (sequelize, DataTypes) => {
price_factor_used_for_price_calculation: DataTypes.INTEGER,
offer_finalize_transaction_hash: DataTypes.STRING(128),
blockchain_id: DataTypes.STRING,
replication_start_timestamp: DataTypes.STRING,
}, {});
offers.associate = (models) => {
// associations can be defined here
Expand Down
21 changes: 21 additions & 0 deletions models/pruning_history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const uuidv4 = require('uuid/v4');

module.exports = (sequelize, DataTypes) => {
const pruning_history = sequelize.define('pruning_history', {
id: {
type: DataTypes.STRING,
defaultValue: () => uuidv4(),
primaryKey: true,
},
data_set_id: DataTypes.STRING,
imported_timestamp: DataTypes.STRING,
pruned_timestamp: DataTypes.STRING,
}, {
freezeTableName: true,
tableName: 'pruning_history',
});
pruning_history.associate = (models) => {
// associations can be defined here
};
return pruning_history;
};
84 changes: 53 additions & 31 deletions modules/Blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,26 +561,36 @@ class Blockchain {
}

const that = this;
let processingEvents = false;

const handle = setInterval(async () => {
if (!that.appState.started) {
return;
}
try {
if (!that.appState.started) {
return;
}
if (processingEvents) {
return;
}
processingEvents = true;

const where = {
event,
finished: 0,
[Op.or]: blockStartConditions,
};
const where = {
event,
finished: 0,
[Op.or]: blockStartConditions,
};

const eventData = await Models.events.findAll({ where });
if (eventData) {
eventData.forEach(async (data) => {
const dataToSend = JSON.parse(data.dataValues.data);
dataToSend.blockchain_id = data.dataValues.blockchain_id;
this.emitter.emit(`eth-${data.event}`, dataToSend);
data.finished = 1;
await data.save();
});
const eventData = await Models.events.findAll({ where });
if (eventData) {
eventData.forEach(async (data) => {
const dataToSend = JSON.parse(data.dataValues.data);
dataToSend.blockchain_id = data.dataValues.blockchain_id;
this.emitter.emit(`eth-${data.event}`, dataToSend);
data.finished = 1;
await data.save();
});
}
} finally {
processingEvents = false;
}
}, 2000);

Expand Down Expand Up @@ -704,25 +714,37 @@ class Blockchain {
async handleReceivedEvents(events, contractName, blockchain_id) {
for (let i = 0; events && i < events.length; i += 1) {
const event = events[i];
const timestamp = Date.now();

if (event.returnValues.DH_wallet) {
event.returnValues.DH_wallet = event.returnValues.DH_wallet.toLowerCase();
}
/* eslint-disable-next-line */
await Models.events.create({
id: uuidv4(),
contract: contractName,
event: event.event,
data: JSON.stringify(event.returnValues),
data_set_id: Utilities.normalizeHex(event.returnValues.dataSetId),
block: event.blockNumber,
blockchain_id,
timestamp,
finished: 0,
const eventData = JSON.stringify(event.returnValues);
// eslint-disable-next-line no-await-in-loop
const databaseEvent = await Models.events.findOne({
where: {
contract: contractName,
event: event.event,
data: eventData,
block: event.blockNumber,
blockchain_id,
},
});
if (!databaseEvent) {
const timestamp = Date.now();
/* eslint-disable-next-line */
await Models.events.create({
id: uuidv4(),
contract: contractName,
event: event.event,
data: eventData,
data_set_id: Utilities.normalizeHex(event.returnValues.dataSetId),
block: event.blockNumber,
blockchain_id,
timestamp,
finished: 0,
});
}
}


const twoWeeksAgo = new Date();
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);
// Delete old events
Expand Down
Loading

0 comments on commit 96bc9b9

Please sign in to comment.