From ffccad916d8d33b7ce3046763e43f372a366667b Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Wed, 25 Dec 2019 18:37:28 +0100 Subject: [PATCH 1/8] Default config updated (#1090) (#1091) (#1092) --- config/config.json | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/config/config.json b/config/config.json index a451438b39..1b4764482e 100644 --- a/config/config.json +++ b/config/config.json @@ -215,7 +215,7 @@ "node_rpc_port": 8900, "remote_control_enabled": true, "node_remote_control_port": 3000, - "is_bootstrap_node": true, + "is_bootstrap_node": false, "send_logs": false, "logs_level_debug": true, "reverse_tunnel_address": "diglet.origintrail.io", @@ -257,8 +257,8 @@ "gas_limit": "2000000", "gas_price": "20000000000", "max_allowed_gas_price" : "50000000000", - "dc_price_factor" : "3", - "dh_price_factor" : "2", + "dc_price_factor" : "6", + "dh_price_factor" : "5", "trac_price_in_eth" : "0.00005", "hub_contract_address": "0x89777F4D16F0a263F47EaD07cbCAb9497861aa79", "plugins": [ @@ -280,9 +280,11 @@ "hostname": "127.0.0.1", "id": "MainnetV4.0", "bootstraps": [ - "https://rinkeby-mariner-bootstrap-01.origin-trail.network:5278/#f4092d1795e2fd442308911db2c1df31faf4fe2f", - "https://rinkeby-mariner-bootstrap-02.origin-trail.network:5278/#d3951837f8100e6ea4a74417d560bcc8c6d4ffe5", - "https://rinkeby-mariner-bootstrap-03.origin-trail.network:5278/#ad3c3325e50c3bedcb5c6ee6a73592b2ca7e07aa" + "https://mainnet-bootstrap-wm-monica-borer-21.origin-trail.network:5278/#61a8b70d373c8c64a1cecf2602b9176399ace9ca", + "https://mainnet-bootstrap-wm-wilbert-bode-41.origin-trail.network:5278/#a9a53281f99538c3e23cf0b2726cfd5901611ff5", + "https://mainnet-bootstrap-wm-dortha-metz-70.origin-trail.network:5278/#5d462772267b8ae0e4fdf52397a370439f338c9d", + "https://mainnet-bootstrap-wm-domenick-goldner-5.origin-trail.network:5278/#ae3896d7cf0a52f3dddeef80b5243695dce88cdf", + "https://mainnet-bootstrap-wm-kaleigh-schaefer-47.origin-trail.network:5278/#95f54eb6bc713706e2ec76881ea11db390cad51d" ], "remoteWhitelist": ["127.0.0.1"], "solutionDifficulty": 14, @@ -305,7 +307,7 @@ "dc_holding_time_in_minutes": 262800, "dc_litigation_interval_in_minutes": 5, "dh_max_holding_time_in_minutes": 5256000, - "dh_maximum_dataset_filesize_in_mb": 1000, + "dh_maximum_dataset_filesize_in_mb": 3, "dh_min_litigation_interval_in_minutes": 5, "dc_choose_time": 1200000, "requireApproval": false, From be79c8c089a8fac3a7de0602f36331ca3052c0c9 Mon Sep 17 00:00:00 2001 From: Uros Kukic <33048701+Kuki145@users.noreply.github.com> Date: Thu, 26 Dec 2019 16:18:08 +0100 Subject: [PATCH 2/8] Freedom-Gemini v4.0.0 (#1098) * Default config updated (#1090) (#1091) * Pricing bug fix and version update to 4.0.0 (#1095) * Default config updated (#1090) * gas price rounded (#1093) * bumped version to 4.0.0 (#1094) * Add challenge retry and delay on failed send (#1096) * Add delay and retry when failing to send challenge * Add retries and delay when failing to send challenge response * Reduce blacklist reset time * Added configuration parameter for challenge retry delay. Resolved bug with printing whole configuration Co-authored-by: djordjekovac Co-authored-by: Uros Kukic <33048701+Kuki145@users.noreply.github.com> Co-authored-by: djordjekovac --- config/config.json | 12 +++++++++--- modules/RemoteControl.js | 6 +++++- modules/command/command-executor.js | 2 +- modules/command/dc/dc-challenge-command.js | 3 ++- modules/command/dc/dc-challenges-command.js | 1 + modules/command/dh/dh-challenge-command.js | 18 ++++++++++++------ modules/service/dh-service.js | 1 + modules/service/pricing-service.js | 6 ++++-- package.json | 2 +- test/modules/utilities.test.js | 2 +- 10 files changed, 37 insertions(+), 16 deletions(-) diff --git a/config/config.json b/config/config.json index 1b4764482e..b492b3fafe 100644 --- a/config/config.json +++ b/config/config.json @@ -78,7 +78,7 @@ "churnPlugin": { "cooldownBaseTimeout": "5m", "cooldownMultiplier": 2, - "cooldownResetTime": "60m" + "cooldownResetTime": "1s" } }, "bugSnag": { @@ -92,6 +92,8 @@ "dataSetStorage": "data_set_storage", "dc_holding_time_in_minutes": 60, "dc_litigation_interval_in_minutes": 5, + "dc_challenge_retry_delay_in_millis": 1000, + "dh_challenge_retry_delay_in_millis": 1000, "dh_max_holding_time_in_minutes": 10080, "dh_maximum_dataset_filesize_in_mb": 1000, "dh_min_litigation_interval_in_minutes": 5, @@ -184,7 +186,7 @@ "churnPlugin": { "cooldownBaseTimeout": "5m", "cooldownMultiplier": 2, - "cooldownResetTime": "60m" + "cooldownResetTime": "1s" } }, "bugSnag": { @@ -198,6 +200,8 @@ "dataSetStorage": "data_set_storage", "dc_holding_time_in_minutes": 60, "dc_litigation_interval_in_minutes": 5, + "dc_challenge_retry_delay_in_millis": 600000, + "dh_challenge_retry_delay_in_millis": 600000, "dh_max_holding_time_in_minutes": 10080, "dh_maximum_dataset_filesize_in_mb": 1000, "dh_min_litigation_interval_in_minutes": 5, @@ -292,7 +296,7 @@ "churnPlugin": { "cooldownBaseTimeout": "5m", "cooldownMultiplier": 2, - "cooldownResetTime": "60m" + "cooldownResetTime": "1s" } }, "bugSnag": { @@ -306,6 +310,8 @@ "dataSetStorage": "data_set_storage", "dc_holding_time_in_minutes": 262800, "dc_litigation_interval_in_minutes": 5, + "dc_challenge_retry_delay_in_millis": 600000, + "dh_challenge_retry_delay_in_millis": 600000, "dh_max_holding_time_in_minutes": 5256000, "dh_maximum_dataset_filesize_in_mb": 3, "dh_min_litigation_interval_in_minutes": 5, diff --git a/modules/RemoteControl.js b/modules/RemoteControl.js index 899d883291..186844b5d2 100644 --- a/modules/RemoteControl.js +++ b/modules/RemoteControl.js @@ -93,7 +93,11 @@ class RemoteControl { }); this.socket.on('config-update', async (data) => { - this.log.important(`Updating config.\n${JSON.stringify(data, null, 4)}`); + const configClean = Object.assign({}, data); + configClean.node_private_key = '*** MASKED ***'; + configClean.houston_password = '*** MASKED ***'; + configClean.database.password = '*** MASKED ***'; + this.log.important(`Updating config.\n${JSON.stringify(configClean, null, 4)}`); deepExtend(this.config, data); await this.socket.emit('updateComplete'); }); diff --git a/modules/command/command-executor.js b/modules/command/command-executor.js index a44c3d7871..521732cb98 100644 --- a/modules/command/command-executor.js +++ b/modules/command/command-executor.js @@ -252,7 +252,7 @@ class CommandExecutor { await CommandExecutor._update(command, { retries: command.retries - 1, }); - await this.add(command, 0, false); + await this.add(command, command.delay ? command.delay : 0, false); } else { try { await CommandExecutor._update(command, { diff --git a/modules/command/dc/dc-challenge-command.js b/modules/command/dc/dc-challenge-command.js index 7356bbfa5b..2553af8dc2 100644 --- a/modules/command/dc/dc-challenge-command.js +++ b/modules/command/dc/dc-challenge-command.js @@ -48,7 +48,8 @@ class DCChallengeCommand extends Command { }, }, challenge.dh_id); } catch (e) { - this.logger.info(`Peer with ID ${challenge.dh_id} could not be reached.`); + command.delay = this.config.dc_challenge_retry_delay_in_millis; + throw new Error(`Peer with ID ${challenge.dh_id} could not be reached on challenge attempt ${5 - command.retries}`); } const checkCommandDelay = constants.DEFAULT_CHALLENGE_RESPONSE_TIME_MILLS; diff --git a/modules/command/dc/dc-challenges-command.js b/modules/command/dc/dc-challenges-command.js index f6548f4e98..f63dda35c9 100644 --- a/modules/command/dc/dc-challenges-command.js +++ b/modules/command/dc/dc-challenges-command.js @@ -58,6 +58,7 @@ class DCChallengesCommand extends Command { litigationPrivateKey: challenged.litigation_private_key, }, transactional: false, + retries: 4, }); }); } catch (e) { diff --git a/modules/command/dh/dh-challenge-command.js b/modules/command/dh/dh-challenge-command.js index 2d084eb5bb..d4dfa0a3ab 100644 --- a/modules/command/dh/dh-challenge-command.js +++ b/modules/command/dh/dh-challenge-command.js @@ -37,6 +37,7 @@ class DHChallengeCommand extends Command { }); if (holdingData == null) { + command.retries = 0; throw new Error(`Failed to find holding data for offer ${offerId}`); } @@ -51,12 +52,17 @@ class DHChallengeCommand extends Command { const answer = this.challengeService.answerChallengeQuestion(blockIndex, otObject); this.logger.info(`Calculated answer for dataset ${datasetId}, color ${color}, object index ${objectIndex}, and block index ${blockIndex} is ${answer}`); - await this.transport.challengeResponse({ - payload: { - answer, - challenge_id: challengeId, - }, - }, litigatorNodeId); + try { + await this.transport.challengeResponse({ + payload: { + answer, + challenge_id: challengeId, + }, + }, litigatorNodeId); + } catch (e) { + command.delay = this.config.dh_challenge_retry_delay_in_millis; + throw new Error(`Failed to send challenge response to litigator with ID ${litigatorNodeId} on attempt ${5 - command.retries}`); + } this.logger.info(`Challenge answer ${answer} sent to ${litigatorNodeId}.`); return Command.empty(); diff --git a/modules/service/dh-service.js b/modules/service/dh-service.js index ae0bba65ce..03e7450d47 100644 --- a/modules/service/dh-service.js +++ b/modules/service/dh-service.js @@ -370,6 +370,7 @@ class DHService { this.logger.info(`Challenge arrived: Object index ${objectIndex}, Block index ${blockIndex}, Data set ID ${datasetId}`); await this.commandExecutor.add({ name: 'dhChallengeCommand', + retries: 4, data: { objectIndex, blockIndex, diff --git a/modules/service/pricing-service.js b/modules/service/pricing-service.js index 4af41c3d02..bcd42fc845 100644 --- a/modules/service/pricing-service.js +++ b/modules/service/pricing-service.js @@ -52,11 +52,13 @@ class PricingService { + constants.GAS_PRICE_VALIDITY_TIME_IN_MILLS > now) { return this.config.blockchain.gas_price; } - const gasStationGasPrice = await this.gasStationService.getGasPrice() + let gasStationGasPrice = await this.gasStationService.getGasPrice() .catch((err) => { this.logger.warn(err); }) * constants.AVERAGE_GAS_PRICE_MULTIPLIER; + gasStationGasPrice = Math.round(gasStationGasPrice); - const web3GasPrice = await this.web3.eth.getGasPrice() + let web3GasPrice = await this.web3.eth.getGasPrice() .catch((err) => { this.logger.warn(err); }) * constants.AVERAGE_GAS_PRICE_MULTIPLIER; + web3GasPrice = Math.round(web3GasPrice); if (gasStationGasPrice && web3GasPrice) { const gasPrice = ( diff --git a/package.json b/package.json index 8419f1e705..d10952fa06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "3.5.0", + "version": "4.0.0", "description": "OriginTrail node", "main": ".eslintrc.js", "config": { diff --git a/test/modules/utilities.test.js b/test/modules/utilities.test.js index 246676ba74..9ec0b321fb 100644 --- a/test/modules/utilities.test.js +++ b/test/modules/utilities.test.js @@ -21,7 +21,7 @@ describe('Utilities module', () => { 'embedded_peercache_path', 'onion_virtual_port', 'traverse_nat_enabled', 'traverse_port_forward_ttl', 'verbose_logging', 'control_port_enabled', 'control_port', 'control_sock_enabled', 'control_sock', 'onion_enabled', 'ssl_authority_paths', 'node_rpc_port', - 'remote_control_enabled', + 'remote_control_enabled', 'dc_challenge_retry_delay_in_millis', 'dh_challenge_retry_delay_in_millis', 'read_stake_factor', 'send_logs_to_origintrail', 'dh_min_reputation', 'dh_min_stake_amount', 'is_bootstrap_node', 'houston_password', 'reverse_tunnel_address', 'reverse_tunnel_port', From 255af476d6586a7b7253d7d732db54e7772a3224 Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Thu, 26 Dec 2019 17:03:46 +0100 Subject: [PATCH 3/8] Identity migration fixed (#1102) * Fix migrating persistant old identity file --- .../m3-network-identity-migration.js | 17 ++++++++----- ot-node.js | 24 +++++++------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/modules/migration/m3-network-identity-migration.js b/modules/migration/m3-network-identity-migration.js index 102ffbc65b..4d3daaa5f1 100644 --- a/modules/migration/m3-network-identity-migration.js +++ b/modules/migration/m3-network-identity-migration.js @@ -30,17 +30,22 @@ class M3NetworkIdentityMigration { const backupPath = path.join(this.config.appDataPath, 'Node_2_0_59_Identity_Backup'); const { xprivkey, index } = identityFileContent; - if ((xprivkey || index) - && this.config.autoUpdater.enabled - && !fs.existsSync(backupPath)) { + if ((xprivkey || index) && this.config.autoUpdater.enabled) { this.logger.info('Old network identity detected, running code migrations...'); // Backup data - execSync(`mkdir ${backupPath}`); + if (!fs.existsSync(backupPath)) { + execSync(`mkdir ${backupPath}`); + + try { + execSync(`/bin/mv ${path.join(this.config.appDataPath, 'peercache')} ${backupPath}/`); + execSync(`/bin/mv ${path.join(this.config.appDataPath, 'kadence.dht')} ${backupPath}/`); + } catch (e) { + this.logger.debug('peercache and kadence.dht not found'); + } + } execSync(`/bin/mv ${identityFilePath} ${backupPath}/`); - execSync(`/bin/mv ${path.join(this.config.appDataPath, 'peercache')} ${backupPath}/`); - execSync(`/bin/mv ${path.join(this.config.appDataPath, 'kadence.dht')} ${backupPath}/`); } } } diff --git a/ot-node.js b/ot-node.js index 8f49b7572e..a2404d9ccc 100644 --- a/ot-node.js +++ b/ot-node.js @@ -498,22 +498,14 @@ class OTNode { async _runNetworkIdentityMigration(config) { const migrationsStartedMills = Date.now(); - const migrationDir = path.join(config.appDataPath, 'migrations'); - const m3NetworkIdentityMigrationFilename = '3_m3NetworkIdentityMigrationFile'; - const migrationFilePath = path.join(migrationDir, m3NetworkIdentityMigrationFilename); - if (!fs.existsSync(migrationFilePath)) { - const migration = new M3NetowrkIdentityMigration({ logger: log, config }); - try { - await migration.run(); - log.notify(`One-time network identity migration completed. Lasted ${Date.now() - migrationsStartedMills} millisecond(s)`); - - await Utilities.writeContentsToFile(migrationDir, m3NetworkIdentityMigrationFilename, 'PROCESSED'); - } catch (e) { - log.error(`Failed to run code migrations. Lasted ${Date.now() - migrationsStartedMills} millisecond(s). ${e.message}`); - console.log(e); - notifyBugsnag(e); - process.exit(1); - } + const migration = new M3NetowrkIdentityMigration({ logger: log, config }); + try { + await migration.run(); + } catch (e) { + log.error(`Failed to run code migrations. Lasted ${Date.now() - migrationsStartedMills} millisecond(s). ${e.message}`); + console.log(e); + notifyBugsnag(e); + process.exit(1); } } From 07bb88b1638bdbe6627e3c06d79eed7726868854 Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Wed, 3 Feb 2021 12:35:10 +0100 Subject: [PATCH 4/8] Bug fixed when offer id is not returned correctly on export request (#1440) --- modules/command/common/export-data-command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }, From f2b583d09247592d855ea49a73114f9f6a9e181d Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Thu, 11 Feb 2021 15:11:33 +0100 Subject: [PATCH 5/8] Resolved issue when trying to replicate big datasets (#1448) * Resolved issue when trying to replicate big datasets --- modules/worker/create-replication-data-worker.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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}` }); From cccb841f20639e22a004faee828359d898a3161d Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Tue, 23 Feb 2021 09:08:23 +0100 Subject: [PATCH 6/8] Skip autoupdate if next version is 5.0.0 (#1454) * Skip autoupdate if next version is 5.0.0 --- modules/command/common/autoupdater-command.js | 5 +++++ 1 file changed, 5 insertions(+) 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 }, From 442114e77222216a8629752c9546bcfd472ec9d5 Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Thu, 25 Feb 2021 10:25:59 +0100 Subject: [PATCH 7/8] Version bumped to 4.1.17 (#1457) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From bbc5c9937f0be9bae7b23a05f372091642ac7675 Mon Sep 17 00:00:00 2001 From: djordjekovac Date: Thu, 25 Feb 2021 11:42:47 +0100 Subject: [PATCH 8/8] Adding ot-node version 5 migration scripts (#1455) * Added migration scripts --- scripts/generate_v5_configuration.js | 38 ++++++++++++++++++ scripts/migrate_to_v5.sh | 60 ++++++++++++++++++++++++++++ scripts/start_v5_update.js | 44 ++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 scripts/generate_v5_configuration.js create mode 100755 scripts/migrate_to_v5.sh create mode 100644 scripts/start_v5_update.js 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);