Skip to content

Commit

Permalink
Merge pull request #64 from orbs-network/fix_config_mess
Browse files Browse the repository at this point in the history
Fix config mess
  • Loading branch information
talkol authored Oct 18, 2020
2 parents 7defc79 + e91593f commit 80b5498
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 71 deletions.
3 changes: 0 additions & 3 deletions e2e/Dockerfile-app.test
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions e2e/bootstrap/expectations-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},
};
19 changes: 19 additions & 0 deletions e2e/expectations-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
},
},
},
};
9 changes: 8 additions & 1 deletion src/api/render-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/api/render-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
}

Expand Down
11 changes: 8 additions & 3 deletions src/cli-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const minimalConfigValue = {
EthereumEndpoint: 'http://localhost:7545',
'node-address': 'ecfcccbc1e54852337298c7e90f5ecee79439e67',
};
const configValue: ServiceConfiguration = {
const inputConfigValue = {
...minimalConfigValue,
BootstrapMode: false,
Port: -1,
Expand All @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions src/cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'.`);
Expand Down
6 changes: 3 additions & 3 deletions src/config.example.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -18,4 +17,5 @@ export const exampleConfig: ServiceConfiguration = {
FinalityBufferBlocks: 10,
Verbose: false,
'node-address': 'ecfcccbc1e54852337298c7e90f5ecee79439e67',
ExternalLaunchConfig: {},
};
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import validate from 'validate.js';
import { getEthereumFirstBlock, getGenesisContractAddress } from './governance';

export interface ServiceConfiguration {
BootstrapMode: boolean;
Expand All @@ -18,13 +17,14 @@ export interface ServiceConfiguration {
EthereumFirstBlock: number;
Verbose: boolean;
'node-address': string;
ExternalLaunchConfig: { [key: string]: unknown };
}

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,
Expand Down
30 changes: 0 additions & 30 deletions src/governance.test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/governance.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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:');
Expand All @@ -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);

Expand Down

0 comments on commit 80b5498

Please sign in to comment.