Skip to content

Commit

Permalink
Merge pull request #1459 from OriginTrail/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail Testnet Release v4.1.17
  • Loading branch information
djordjekovac authored Feb 25, 2021
2 parents 71f6baa + 206b2e9 commit ee01207
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 6 deletions.
5 changes: 5 additions & 0 deletions modules/command/common/autoupdater-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class AutoupdaterCommand extends Command {
if (semver.lt(currentVersion, remoteVersion)) {
this.logger.info('New version found');

if (remoteVersion === '5.0.0') {
this.logger.trace('New version available is 5.0.0. Please run update process manually.');
return Command.repeat();
}

if (this.config.high_availability_setup) {
const activeNode = await Models.node_status.findOne({
where: { hostname: this.config.high_availability.private_ip_address },
Expand Down
2 changes: 1 addition & 1 deletion modules/command/common/export-data-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExportDataCommand extends Command {
);

const dataInfo = await Models.data_info.findOne({ where: { data_set_id: datasetId } });
const offer = await Models.offers.findOne({ where: { data_set_id: datasetId } });
const offer = await Models.offers.findOne({ where: { data_set_id: datasetId, status: 'FINALIZED' } });

const handler = await Models.handler_ids.findOne({
where: { handler_id: handlerId },
Expand Down
6 changes: 2 additions & 4 deletions modules/worker/create-replication-data-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ process.on('message', async (data) => {

await Utilities.writeContentsToFile(cacheDirectoryPath, handler_id, JSON.stringify(otJson));

const writeFilePromises = [];
const hashes = {};
const colors = ['red', 'blue', 'green'];
for (let i = 0; i < 3; i += 1) {
Expand Down Expand Up @@ -70,14 +69,13 @@ process.on('message', async (data) => {
distributionEpk: distEpk,
};

writeFilePromises.push(Utilities.writeContentsToFile(cacheDirectoryPath, `${color}.json`, JSON.stringify(replication)));

const fullPath = path.join(cacheDirectoryPath, `${color}.json`);
fs.writeFileSync(fullPath, JSON.stringify(replication));

hashes[`${color}LitigationHash`] = litRootHash;
hashes[`${color}DistributionHash`] = distRootHash;
}

await Promise.all(writeFilePromises);
process.send({ hashes });
} catch (error) {
process.send({ error: `${error.message}` });
Expand Down
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": "4.1.16",
"version": "4.1.17",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand Down
38 changes: 38 additions & 0 deletions scripts/generate_v5_configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');
require('dotenv').config();
const defaultConfigJson = require('../config/config.json');

const nodercConfigPath = '/ot-node/.origintrail_noderc';
const v5ConfigPath = '/ot-node/data/.v5_configuration';

try {
console.log('Starting configuration update');
const defaultConfig = defaultConfigJson[process.env.NODE_ENV];
const configFile = fs.readFileSync(nodercConfigPath);
const config = JSON.parse(configFile);
const { blockchain } = config;
blockchain.blockchain_title = defaultConfig.blockchain.blockchain_title;
blockchain.network_id = defaultConfig.blockchain.network_id;
blockchain.node_wallet = config.node_wallet;
delete config.node_wallet;
blockchain.node_private_key = config.node_private_key;
delete config.node_private_key;
blockchain.management_wallet = config.management_wallet;
delete config.management_wallet;
if (config.erc725_identity_filepath) {
blockchain.identity_filepath = config.erc725_identity_filepath;
delete config.erc725_identity_filepath;
} else {
blockchain.identity_filepath = defaultConfig.erc725_identity_filepath;
}
delete config.blockchain;

config.blockchain = {
implementations: [blockchain],
};
fs.writeFileSync(v5ConfigPath, JSON.stringify(config, null, 4));
console.log('Configuration version 5 generated in data/.v5_configuration');
} catch (error) {
console.log('Failed to generate configuration version 5', error.message);
process.exit(1);
}
60 changes: 60 additions & 0 deletions scripts/migrate_to_v5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function printUsage() {
echo ""
echo "Usage:"
echo " migrate_to_v5.sh [--node_rc_path=<path_to_node_rc_configuration_file>] [--node_container_name=<node_docker_container_name>]"
echo "Options:"
echo " --node_rc_path=<path_to_node_rc_configuration_file>
Specify the path to the node rc configuration file. If node_rc_path option is not passed default one will be used: .origintrail_noderc"
echo " --node_container_name=<node_docker_container_name>
Specify the name of docker container running ot-node. If node_container_name option is not passed default one will be used: otnode"
echo ""
}

NODE_RC_PATH=".origintrail_noderc"
DOCKER_CONTAINER_NAME="otnode"

while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
printUsage
exit 0
;;
--node_rc_path=*)
NODE_RC_PATH="${1#*=}"
;;
--node_container_name=*)
DOCKER_CONTAINER_NAME="${1#*=}"
;;
esac
shift
done

if [ ! -f "$NODE_RC_PATH" ]; then
echo "$NODE_RC_PATH does not exist. Please check file path provided. Use -h for help."
exit 0
fi

if [ ! "$(docker ps -a --filter status=running | grep $DOCKER_CONTAINER_NAME)" ]; then
echo "Docker container with name: $DOCKER_CONTAINER_NAME, not running or doesn't exists. Use -h for help."
exit 0
fi

docker exec ${DOCKER_CONTAINER_NAME} node /ot-node/current/scripts/generate_v5_configuration.js
if [ ! $? -eq 0 ]; then
echo "Failed to generate v5 configuration file"
exit 0
fi

cp ${NODE_RC_PATH} .origintrail_noderc_v4_backup
echo "Old configuration saved as .origintrail_noderc_v4_backup."
docker cp ${DOCKER_CONTAINER_NAME}:/ot-node/data/.v5_configuration ./${NODE_RC_PATH}
echo "Starting manual node update to version 5. Please be patient this can take up to 10 minutes."
docker exec ${DOCKER_CONTAINER_NAME} node /ot-node/current/scripts/start_v5_update.js
if [ ! $? -eq 0 ]; then
echo "Failed to manually start v5 update. Restoring old configuration"
mv .origintrail_noderc_v4_backup ${NODE_RC_PATH}
exit 0
fi
echo "Manual update finalized. Restarting otnode node..."
docker restart ${DOCKER_CONTAINER_NAME}
echo "Update completed successfully!"
44 changes: 44 additions & 0 deletions scripts/start_v5_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const { fork } = require('child_process');

const rc = require('rc');
const pjson = require('../package.json');
const configjson = require('../config/config.json');

const defaultConfig = configjson[process.env.NODE_ENV];
const config = rc(pjson.name, defaultConfig);

const updateFilepath = '/ot-node/current/UPDATE';
const destinationBasedir = '/ot-node/';

const updater = fork(path.join(__dirname, '..', 'testnet', 'prepare-update.js'), [], {
stdio: [0, 1, 2, 'ipc'],
});

updater.on('message', async (result) => {
if (result.status !== 'completed') {
// Something went wrong.
console.log(`Failed to prepare update. Status: ${result.status}.`);
process.exit(1);
}

console.log(`Update ready for version ${result.version}.`);
fs.writeFileSync(updateFilepath, JSON.stringify({
version: result.version,
path: result.installDir,
configPath: config.appDataPath,
}));
}).on('error', (error) => {
console.log(`Failed to check prepare update. ${error}`);
process.exit(1);
});


const options = {
archiveUrl: config.autoUpdater.archiveUrl,
destinationBaseDir: destinationBasedir,
};

updater.send(options);

0 comments on commit ee01207

Please sign in to comment.