From c905149c9cd21ea81e3cb3bd441a589b9aaac8a9 Mon Sep 17 00:00:00 2001 From: Uros Kukic Date: Tue, 23 Mar 2021 16:36:38 +0100 Subject: [PATCH 1/4] Support database migration of nodes with NODE_ENV=mariner --- .../202010201032128-update-events-add-blockchain-id.js | 6 +++++- .../202011261221123-update-offers-add-blockchain-id.js | 6 +++++- .../202011261243123-update-bids-add-blockchain-id.js | 6 +++++- ...1416123-update-data-info-extend-data-provider-wallet.js | 6 +++++- ...02011301208123-update-data-sellers-add-blockchain-id.js | 7 ++++++- ...202011301210123-update-data-trades-add-blockchain-id.js | 7 ++++++- ...012090818123-update-purchased-data-add-blockchain-id.js | 7 ++++++- .../202012151048123-update-challenges-add-blockchain-id.js | 7 ++++++- .../202102120853043-update-commands-add-blockchain-id.js | 7 ++++++- 9 files changed, 50 insertions(+), 9 deletions(-) diff --git a/migrations/202010201032128-update-events-add-blockchain-id.js b/migrations/202010201032128-update-events-add-blockchain-id.js index b5c0a34376..d10dde7c57 100644 --- a/migrations/202010201032128-update-events-add-blockchain-id.js +++ b/migrations/202010201032128-update-events-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202011261221123-update-offers-add-blockchain-id.js b/migrations/202011261221123-update-offers-add-blockchain-id.js index 56c36141ee..cd62107df2 100644 --- a/migrations/202011261221123-update-offers-add-blockchain-id.js +++ b/migrations/202011261221123-update-offers-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202011261243123-update-bids-add-blockchain-id.js b/migrations/202011261243123-update-bids-add-blockchain-id.js index 8dbe4f5fdf..e55526c5c0 100644 --- a/migrations/202011261243123-update-bids-add-blockchain-id.js +++ b/migrations/202011261243123-update-bids-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202011261416123-update-data-info-extend-data-provider-wallet.js b/migrations/202011261416123-update-data-info-extend-data-provider-wallet.js index e740a8451f..70901de680 100644 --- a/migrations/202011261416123-update-data-info-extend-data-provider-wallet.js +++ b/migrations/202011261416123-update-data-info-extend-data-provider-wallet.js @@ -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 = { diff --git a/migrations/202011301208123-update-data-sellers-add-blockchain-id.js b/migrations/202011301208123-update-data-sellers-add-blockchain-id.js index 83ce2b698a..2df2244268 100644 --- a/migrations/202011301208123-update-data-sellers-add-blockchain-id.js +++ b/migrations/202011301208123-update-data-sellers-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202011301210123-update-data-trades-add-blockchain-id.js b/migrations/202011301210123-update-data-trades-add-blockchain-id.js index 1fc356d4da..2a1c7bd3cc 100644 --- a/migrations/202011301210123-update-data-trades-add-blockchain-id.js +++ b/migrations/202011301210123-update-data-trades-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202012090818123-update-purchased-data-add-blockchain-id.js b/migrations/202012090818123-update-purchased-data-add-blockchain-id.js index 6c0c17f1e4..4e3a4f7d1b 100644 --- a/migrations/202012090818123-update-purchased-data-add-blockchain-id.js +++ b/migrations/202012090818123-update-purchased-data-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202012151048123-update-challenges-add-blockchain-id.js b/migrations/202012151048123-update-challenges-add-blockchain-id.js index 63fcad866e..f7e47429a9 100644 --- a/migrations/202012151048123-update-challenges-add-blockchain-id.js +++ b/migrations/202012151048123-update-challenges-add-blockchain-id.js @@ -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 = { diff --git a/migrations/202102120853043-update-commands-add-blockchain-id.js b/migrations/202102120853043-update-commands-add-blockchain-id.js index ab8d638c08..fbb67a36bc 100644 --- a/migrations/202102120853043-update-commands-add-blockchain-id.js +++ b/migrations/202102120853043-update-commands-add-blockchain-id.js @@ -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 = { From 57537705341ce3737e8f36395ca4c56cc20ca5b1 Mon Sep 17 00:00:00 2001 From: Uros Kukic Date: Tue, 23 Mar 2021 16:49:41 +0100 Subject: [PATCH 2/4] Update export worker for mariner nodes --- modules/worker/export-worker.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/worker/export-worker.js b/modules/worker/export-worker.js index 919146474d..81c77f0bb4 100644 --- a/modules/worker/export-worker.js +++ b/modules/worker/export-worker.js @@ -5,7 +5,16 @@ const Utilities = require('../Utilities'); const ImportUtilities = require('../ImportUtilities'); const OtJsonUtilities = require('../OtJsonUtilities'); const fs = require('fs'); -const defaultConfig = require('../../config/config')[process.env.NODE_ENV]; + +if (!process.env.NODE_ENV) { + // Environment not set. Use the production. + process.env.NODE_ENV = 'testnet'; +} +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 defaultConfig = require('../../config/config')[environment]; process.on('message', async (data) => { const { From 02566d49d4dcfc544a57d0db0da49842f4708f47 Mon Sep 17 00:00:00 2001 From: Uros Kukic Date: Tue, 23 Mar 2021 16:53:31 +0100 Subject: [PATCH 3/4] Update Utilities modules for mariner nodes --- modules/ImportUtilities.js | 10 +++++++++- modules/OtJsonUtilities.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/ImportUtilities.js b/modules/ImportUtilities.js index 68e125d9b2..35cddd9165 100644 --- a/modules/ImportUtilities.js +++ b/modules/ImportUtilities.js @@ -13,7 +13,15 @@ const OtJsonUtilities = require('./OtJsonUtilities'); const DataIntegrityResolver = require('./service/data-integrity/data-integrity-resolver'); // TODO Is this safe to read, IE will it always be the same, // (could the node somehow change this in runtime? ) -const defaultConfig = require('../config/config')[process.env.NODE_ENV]; +if (!process.env.NODE_ENV) { + // Environment not set. Use the production. + process.env.NODE_ENV = 'testnet'; +} +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 defaultConfig = require('../config/config')[environment]; const data_constants = { vertexType: { diff --git a/modules/OtJsonUtilities.js b/modules/OtJsonUtilities.js index d7e4bcc32d..63a0cfd16a 100644 --- a/modules/OtJsonUtilities.js +++ b/modules/OtJsonUtilities.js @@ -1,6 +1,15 @@ const Utilities = require('./Utilities'); const { sha3_256 } = require('js-sha3'); -const defaultConfig = require('../config/config')[process.env.NODE_ENV]; + +if (!process.env.NODE_ENV) { + // Environment not set. Use the production. + process.env.NODE_ENV = 'testnet'; +} +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 defaultConfig = require('../config/config')[environment]; class OtJsonUtilities { From 0fa552114954ceaa2ed6098f3a60e6b615bc9483 Mon Sep 17 00:00:00 2001 From: Uros Kukic Date: Tue, 23 Mar 2021 16:55:26 +0100 Subject: [PATCH 4/4] Update logger module for mariner nodes --- modules/logger.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/logger.js b/modules/logger.js index db34f478c3..d76a257238 100644 --- a/modules/logger.js +++ b/modules/logger.js @@ -5,7 +5,15 @@ require('winston-papertrail').Papertrail; require('winston-loggly-bulk'); const util = require('util'); -const runtimeConfigJson = require('../config/config.json')[process.env.NODE_ENV]; +if (!process.env.NODE_ENV) { + // Environment not set. Use the production. + process.env.NODE_ENV = 'testnet'; +} +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 runtimeConfigJson = require('../config/config.json')[environment]; const colors = require('colors/safe'); const pjson = require('../package.json');