diff --git a/modules/command/common/autoupdater-command.js b/modules/command/common/autoupdater-command.js index 65f4819e08..8a825c1961 100644 --- a/modules/command/common/autoupdater-command.js +++ b/modules/command/common/autoupdater-command.js @@ -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 }, diff --git a/modules/command/common/export-data-command.js b/modules/command/common/export-data-command.js index eb8c25f8f6..fc155dc9f4 100644 --- a/modules/command/common/export-data-command.js +++ b/modules/command/common/export-data-command.js @@ -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 }, diff --git a/modules/worker/create-replication-data-worker.js b/modules/worker/create-replication-data-worker.js index 21e0ba2118..1b3310409f 100644 --- a/modules/worker/create-replication-data-worker.js +++ b/modules/worker/create-replication-data-worker.js @@ -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) { @@ -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}` }); diff --git a/package.json b/package.json index 3064f1f7f2..1e886b56e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "4.1.16", + "version": "4.1.17", "description": "OriginTrail node", "main": ".eslintrc.js", "config": { diff --git a/scripts/generate_v5_configuration.js b/scripts/generate_v5_configuration.js new file mode 100644 index 0000000000..eeef397f21 --- /dev/null +++ b/scripts/generate_v5_configuration.js @@ -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); +} diff --git a/scripts/migrate_to_v5.sh b/scripts/migrate_to_v5.sh new file mode 100755 index 0000000000..1fb60fb586 --- /dev/null +++ b/scripts/migrate_to_v5.sh @@ -0,0 +1,60 @@ +function printUsage() { + echo "" + echo "Usage:" + echo " migrate_to_v5.sh [--node_rc_path=] [--node_container_name=]" + echo "Options:" + echo " --node_rc_path= + 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= + 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!" diff --git a/scripts/start_v5_update.js b/scripts/start_v5_update.js new file mode 100644 index 0000000000..d29e2fe7ca --- /dev/null +++ b/scripts/start_v5_update.js @@ -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);