From 07e2b9b57ab7c874efb027a1bbea93a4586f2709 Mon Sep 17 00:00:00 2001 From: Ron Date: Sun, 18 Oct 2020 11:48:33 +0300 Subject: [PATCH 1/2] revert messy fixes --- e2e/Dockerfile-app.test | 3 --- src/config.example.ts | 5 ++--- src/config.ts | 5 ++--- src/governance.test.ts | 30 ------------------------------ src/governance.ts | 22 ---------------------- src/main.ts | 3 --- 6 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 src/governance.test.ts delete mode 100644 src/governance.ts diff --git a/e2e/Dockerfile-app.test b/e2e/Dockerfile-app.test index 7768bed..9b9626e 100644 --- a/e2e/Dockerfile-app.test +++ b/e2e/Dockerfile-app.test @@ -1,7 +1,4 @@ FROM local/management-service -# Env -ENV NODE_ENV e2e - COPY ./app-config.json ./ CMD npm start -- --config /opt/orbs/app-config.json diff --git a/src/config.example.ts b/src/config.example.ts index 9858a26..7d7b144 100644 --- a/src/config.example.ts +++ b/src/config.example.ts @@ -1,11 +1,10 @@ import { ServiceConfiguration } from './config'; -import { GOVERNANCE_GANACHE_FIRST_BLOCK, GOVERNANCE_GANACHE_GENESIS_CONTRACT } from './governance'; export const exampleConfig: ServiceConfiguration = { BootstrapMode: false, Port: 8080, - EthereumGenesisContract: GOVERNANCE_GANACHE_GENESIS_CONTRACT, - EthereumFirstBlock: GOVERNANCE_GANACHE_FIRST_BLOCK, + EthereumGenesisContract: '0x5454223e3078Db87e55a15bE541cc925f3702eB0', + EthereumFirstBlock: 11050000, EthereumEndpoint: 'http://ganache:7545', DockerNamespace: 'orbsnetwork', DockerRegistry: 'https://registry.hub.docker.com', diff --git a/src/config.ts b/src/config.ts index 2526e28..7094b62 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,4 @@ import validate from 'validate.js'; -import { getEthereumFirstBlock, getGenesisContractAddress } from './governance'; export interface ServiceConfiguration { BootstrapMode: boolean; @@ -23,8 +22,8 @@ export interface ServiceConfiguration { export const defaultServiceConfiguration = { BootstrapMode: false, Port: 8080, - EthereumGenesisContract: getGenesisContractAddress(), - EthereumFirstBlock: getEthereumFirstBlock(), + EthereumGenesisContract: '0x5454223e3078Db87e55a15bE541cc925f3702eB0', + EthereumFirstBlock: 11050000, DockerNamespace: 'orbsnetwork', DockerRegistry: 'https://registry.hub.docker.com', DockerHubPollIntervalSeconds: 3 * 60, diff --git a/src/governance.test.ts b/src/governance.test.ts deleted file mode 100644 index 813e5d4..0000000 --- a/src/governance.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import test from 'ava'; -import { - applyGovernance, - GOVERNANCE_GANACHE_FIRST_BLOCK, - GOVERNANCE_GANACHE_GENESIS_CONTRACT, - GOVERNANCE_MAINNET_FIRST_BLOCK, - GOVERNANCE_MAINNET_GENESIS_CONTRACT, -} from './governance'; -import { exampleConfig } from './config.example'; - -test('sets governance params', (t) => { - const config = { ...exampleConfig }; - config.EthereumGenesisContract = ''; - config.EthereumFirstBlock = -999; - - const originalNodeEnv = process.env.NODE_ENV; - process.env.NODE_ENV = 'production'; - - applyGovernance(config); - - t.deepEqual(config.EthereumFirstBlock, GOVERNANCE_MAINNET_FIRST_BLOCK); - t.deepEqual(config.EthereumGenesisContract, GOVERNANCE_MAINNET_GENESIS_CONTRACT); - - process.env.NODE_ENV = originalNodeEnv; - - applyGovernance(config); - - t.deepEqual(config.EthereumFirstBlock, GOVERNANCE_GANACHE_FIRST_BLOCK); - t.deepEqual(config.EthereumGenesisContract, GOVERNANCE_GANACHE_GENESIS_CONTRACT); -}); diff --git a/src/governance.ts b/src/governance.ts deleted file mode 100644 index c91fa48..0000000 --- a/src/governance.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ServiceConfiguration } from './config'; - -export const GOVERNANCE_MAINNET_GENESIS_CONTRACT = '0x5454223e3078Db87e55a15bE541cc925f3702eB0'; -export const GOVERNANCE_GANACHE_GENESIS_CONTRACT = '0x5cd0D270C30EDa5ADa6b45a5289AFF1D425759b3'; - -export const GOVERNANCE_MAINNET_FIRST_BLOCK = 11050000; -export const GOVERNANCE_GANACHE_FIRST_BLOCK = 0; - -export function getGenesisContractAddress(): string { - return process.env.NODE_ENV === 'production' - ? GOVERNANCE_MAINNET_GENESIS_CONTRACT - : GOVERNANCE_GANACHE_GENESIS_CONTRACT; -} - -export function getEthereumFirstBlock(): number { - return process.env.NODE_ENV === 'production' ? GOVERNANCE_MAINNET_FIRST_BLOCK : GOVERNANCE_GANACHE_FIRST_BLOCK; -} - -export function applyGovernance(config: ServiceConfiguration) { - config.EthereumGenesisContract = getGenesisContractAddress(); - config.EthereumFirstBlock = getEthereumFirstBlock(); -} diff --git a/src/main.ts b/src/main.ts index 0551ffa..d53e87a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,6 @@ import { serve } from '.'; import { parseArgs } from './cli-args'; import * as Logger from './logger'; -import { applyGovernance } from './governance'; process.on('uncaughtException', function (err) { Logger.log('Uncaught exception on process, shutting down:'); @@ -13,8 +12,6 @@ try { Logger.log('Management service started.'); const config = parseArgs(process.argv); - applyGovernance(config); - Logger.log(`Input config: '${JSON.stringify(config)}'.`); const server = serve(config); From e91593fbe335a08b0d0737d9364028242e157842 Mon Sep 17 00:00:00 2001 From: Tal Kol Date: Sun, 18 Oct 2020 12:36:13 +0300 Subject: [PATCH 2/2] No longer pass all config recursively to myself, just the launch config --- e2e/bootstrap/expectations-status.ts | 15 +++++++++++++++ e2e/expectations-status.ts | 19 +++++++++++++++++++ src/api/render-node.test.ts | 9 ++++++++- src/api/render-node.ts | 5 ++++- src/cli-args.test.ts | 11 ++++++++--- src/cli-args.ts | 8 ++++++-- src/config.example.ts | 1 + src/config.ts | 1 + 8 files changed, 62 insertions(+), 7 deletions(-) diff --git a/e2e/bootstrap/expectations-status.ts b/e2e/bootstrap/expectations-status.ts index 324aaba..ed44e81 100644 --- a/e2e/bootstrap/expectations-status.ts +++ b/e2e/bootstrap/expectations-status.ts @@ -53,6 +53,21 @@ export const expectationStatus = { EthereumFirstBlock: 0, Verbose: true, 'node-address': 'ecfcCcbc1E54852337298c7E90f5eceE79439e67', + ExternalLaunchConfig: { + BootstrapMode: true, + Port: 8080, + EthereumGenesisContract: isValidEthereumAddress, + EthereumEndpoint: `http://ganache:7545`, + DockerNamespace: 'orbsnetwork', + DockerHubPollIntervalSeconds: 1, + RegularRolloutWindowSeconds: 2, + HotfixRolloutWindowSeconds: 2, + EthereumPollIntervalSeconds: 1, + FinalityBufferBlocks: 10, + EthereumFirstBlock: 0, + Verbose: true, + 'node-address': 'ecfcCcbc1E54852337298c7E90f5eceE79439e67', + }, }, }, }; diff --git a/e2e/expectations-status.ts b/e2e/expectations-status.ts index 1cdeb42..d141aa4 100644 --- a/e2e/expectations-status.ts +++ b/e2e/expectations-status.ts @@ -268,10 +268,29 @@ export const expectationStatus = { RegularRolloutWindowSeconds: 2, HotfixRolloutWindowSeconds: 2, EthereumPollIntervalSeconds: 1, + EthereumRequestsPerSecondLimit: 20, + ElectionsStaleUpdateSeconds: 7 * 24 * 60 * 60, FinalityBufferBlocks: 10, EthereumFirstBlock: 0, Verbose: true, 'node-address': 'ecfcCcbc1E54852337298c7E90f5eceE79439e67', + ExternalLaunchConfig: { + BootstrapMode: false, + Port: 8080, + EthereumGenesisContract: isValidEthereumAddress, + EthereumEndpoint: `http://ganache:7545`, + DockerNamespace: 'orbsnetwork', + DockerHubPollIntervalSeconds: 1, + RegularRolloutWindowSeconds: 2, + HotfixRolloutWindowSeconds: 2, + EthereumPollIntervalSeconds: 1, + EthereumRequestsPerSecondLimit: 20, + ElectionsStaleUpdateSeconds: 7 * 24 * 60 * 60, + FinalityBufferBlocks: 10, + EthereumFirstBlock: 0, + Verbose: true, + 'node-address': 'ecfcCcbc1E54852337298c7E90f5eceE79439e67', // Guardian3 (mixed case!) + }, }, }, }; diff --git a/src/api/render-node.test.ts b/src/api/render-node.test.ts index 7110d12..2b23c79 100644 --- a/src/api/render-node.test.ts +++ b/src/api/render-node.test.ts @@ -45,6 +45,10 @@ test.serial('[integration] getNodeManagement responds according to Ethereum and EthereumFirstBlock: firstBlock, RegularRolloutWindowSeconds: 1000000, HotfixRolloutWindowSeconds: 2, + ExternalLaunchConfig: { + BootstrapMode: true, + SomeExternalField: 'someExternalFieldValue', + }, }; const state = new StateManager(config); const blockSync = new BlockSync(state, config); @@ -101,7 +105,10 @@ test.serial('[integration] getNodeManagement responds according to Ethereum and Tag: 'v1.1.0', Pull: true, }); - t.deepEqual(res.services['management-service'].Config, config); + t.deepEqual(res.services['management-service'].Config, { + BootstrapMode: false, + SomeExternalField: 'someExternalFieldValue', + }); t.deepEqual(res.services['ethereum-writer'].Config, { ManagementServiceEndpoint: 'http://management-service:8080', EthereumEndpoint: config.EthereumEndpoint, diff --git a/src/api/render-node.ts b/src/api/render-node.ts index 7fb2030..dc07c2b 100644 --- a/src/api/render-node.ts +++ b/src/api/render-node.ts @@ -81,7 +81,10 @@ function getManagementService(snapshot: StateSnapshot, config: ServiceConfigurat Tag: version, Pull: true, }, - Config: { ...config, BootstrapMode: false }, // forward my own input config + defaults for what's missing + Config: { + ...config.ExternalLaunchConfig, // to avoid the defaults from config (bugfix) + BootstrapMode: false, + }, }; } diff --git a/src/cli-args.test.ts b/src/cli-args.test.ts index a48b297..ee88043 100644 --- a/src/cli-args.test.ts +++ b/src/cli-args.test.ts @@ -14,7 +14,7 @@ const minimalConfigValue = { EthereumEndpoint: 'http://localhost:7545', 'node-address': 'ecfcccbc1e54852337298c7e90f5ecee79439e67', }; -const configValue: ServiceConfiguration = { +const inputConfigValue = { ...minimalConfigValue, BootstrapMode: false, Port: -1, @@ -31,12 +31,17 @@ const configValue: ServiceConfiguration = { Verbose: true, }; +const expectedConfigValue: ServiceConfiguration = { + ...inputConfigValue, + ExternalLaunchConfig: inputConfigValue +}; + test.serial('parseOptions with file', (t) => { mock({ - [configPath]: JSON.stringify(configValue), + [configPath]: JSON.stringify(inputConfigValue), }); - t.deepEqual(parseArgs(['--config', configPath]), configValue); + t.deepEqual(parseArgs(['--config', configPath]), expectedConfigValue); }); test.serial('parseOptions with partial file (complete default values)', (t) => { diff --git a/src/cli-args.ts b/src/cli-args.ts index 4431b30..1d31cc5 100644 --- a/src/cli-args.ts +++ b/src/cli-args.ts @@ -14,11 +14,15 @@ export function parseArgs(argv: string[]): ServiceConfiguration { .exitProcess(false) .parse(); - const config = Object.assign( - defaultServiceConfiguration, + const externalLaunchConfig = Object.assign( + {}, ...options.config.map((configFile) => JSON.parse(readFileSync(configFile).toString())) ); + const config = Object.assign(defaultServiceConfiguration, externalLaunchConfig); + + config.ExternalLaunchConfig = externalLaunchConfig; + const validationErrors = validateServiceConfiguration(config); if (validationErrors) { Logger.error(`Invalid JSON config: '${JSON.stringify(config)}'.`); diff --git a/src/config.example.ts b/src/config.example.ts index 7d7b144..8d0032e 100644 --- a/src/config.example.ts +++ b/src/config.example.ts @@ -17,4 +17,5 @@ export const exampleConfig: ServiceConfiguration = { FinalityBufferBlocks: 10, Verbose: false, 'node-address': 'ecfcccbc1e54852337298c7e90f5ecee79439e67', + ExternalLaunchConfig: {}, }; diff --git a/src/config.ts b/src/config.ts index 7094b62..36f0be4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -17,6 +17,7 @@ export interface ServiceConfiguration { EthereumFirstBlock: number; Verbose: boolean; 'node-address': string; + ExternalLaunchConfig: { [key: string]: unknown }; } export const defaultServiceConfiguration = {