Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- EXECUTION_NODE=${EXECUTION_NODE}
- CONSENSUS_NODE=${CONSENSUS_NODE}
- LOCATOR_ADDRESS=${LOCATOR_ADDRESS}
- EJECTOR_SCOPE
- STAKING_MODULE_ID=${STAKING_MODULE_ID}
- OPERATOR_ID=${OPERATOR_ID}
- MESSAGES_LOCATION=${MESSAGES_LOCATION}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- EXECUTION_NODE=${EXECUTION_NODE}
- CONSENSUS_NODE=${CONSENSUS_NODE}
- LOCATOR_ADDRESS=${LOCATOR_ADDRESS}
- EJECTOR_SCOPE
- STAKING_MODULE_ID=${STAKING_MODULE_ID}
- OPERATOR_ID=${OPERATOR_ID}
- MESSAGES_LOCATION=${MESSAGES_LOCATION}
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ LOGGER_FORMAT=simple
LOGGER_SECRETS=["MESSAGES_PASSWORD","EXECUTION_NODE", "CONSENSUS_NODE"]

DRY_RUN=false
TRUST_MODE=false
1 change: 1 addition & 0 deletions sample.infra.env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ LOGGER_FORMAT=json
LOGGER_SECRETS=["MESSAGES_PASSWORD","EXECUTION_NODE", "CONSENSUS_NODE"]

DRY_RUN=true
TRUST_MODE=false
8 changes: 8 additions & 0 deletions src/lib/validator/deep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ describe('deep data casting', () => {
}
})

test('json object custom error message', () => {
const value = '{'
const cast = () =>
json_obj(value, (value) => value, 'Please, setup JSON config')

expect(cast).toThrowError('Please, setup JSON config')
})

test('json array numbers', () => {
const value = '[1'
const cast = () => json_arr(value, (array) => array.map(num))
Expand Down
8 changes: 7 additions & 1 deletion src/lib/validator/makers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ export const makeJson = <T>(
throw new ValidationEmptyError(errorMessage || 'Empty value', input)
if (typeof input !== 'string')
throw new ValidationError(errorMessage || 'Input must be a string', input)
let parsed: unknown
try {
return cb(parseFn(JSON.parse(input), errorMessage))
parsed = JSON.parse(input)
} catch (error) {
throw new ValidationError(errorMessage || error.message, input)
}
try {
return cb(parseFn(parsed, errorMessage))
} catch (error) {
throw new ValidationError(error.message, input)
}
Expand Down
26 changes: 26 additions & 0 deletions src/services/config/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ describe('config module', () => {
expect(makeConf).not.toThrow()
})

test('invalid optional bool config includes env var name', () => {
const config = {
...configBase,
TRUST_MODE: '',
}

const makeConf = () =>
makeConfig({ logger, env: config as unknown as NodeJS.ProcessEnv })

expect(makeConf).toThrow('Invalid TRUST_MODE value: expected true or false')
})

test('defaults validators batch size', () => {
const config = { ...configBase, MESSAGES_LOCATION: 'messages' }

Expand Down Expand Up @@ -350,6 +362,20 @@ describe('logger config module', () => {
expect(config.LOGGER_SECRETS).toEqual(['secret'])
})

test('invalid logger secrets config', () => {
const env = {
LOGGER_LEVEL: 'info',
LOGGER_FORMAT: 'simple',
LOGGER_SECRETS: `["secret"`,
} as NodeJS.ProcessEnv

const makeConf = () => makeLoggerConfig({ env })

expect(makeConf).toThrowError(
'Please, setup LOGGER_SECRETS. Example: ["EXECUTION_NODE","CONSENSUS_NODE"]'
)
})

test('dynamic secret values', () => {
const env = {
LOGGER_LEVEL: 'info',
Expand Down
45 changes: 38 additions & 7 deletions src/services/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,45 @@ export const makeConfig = ({
JOB_INTERVAL: optional(() => num(env.JOB_INTERVAL)) ?? 384000, // 1 epoch

HTTP_PORT: optional(() => num(env.HTTP_PORT)) ?? 8989,
RUN_METRICS: optional(() => bool(env.RUN_METRICS)) ?? false,
RUN_HEALTH_CHECK: optional(() => bool(env.RUN_HEALTH_CHECK)) ?? true,
RUN_METRICS:
optional(() =>
bool(
env.RUN_METRICS,
'Invalid RUN_METRICS value: expected true or false'
)
) ?? false,
RUN_HEALTH_CHECK:
optional(() =>
bool(
env.RUN_HEALTH_CHECK,
'Invalid RUN_HEALTH_CHECK value: expected true or false'
)
) ?? true,

DRY_RUN: optional(() => bool(env.DRY_RUN)) ?? false,
DRY_RUN:
optional(() =>
bool(env.DRY_RUN, 'Invalid DRY_RUN value: expected true or false')
) ?? false,
TRUST_MODE:
optional(() => bool(env.TRUST_MODE)) ??
optional(() => bool(env.DISABLE_SECURITY_DONT_USE_IN_PRODUCTION)) ??
optional(() =>
bool(env.TRUST_MODE, 'Invalid TRUST_MODE value: expected true or false')
) ??
optional(() =>
bool(
env.DISABLE_SECURITY_DONT_USE_IN_PRODUCTION,
'Invalid DISABLE_SECURITY_DONT_USE_IN_PRODUCTION value: expected true or false'
)
) ??
false,
PROM_PREFIX: optional(() => str(env.PROM_PREFIX)),

FORCE_DENCUN_FORK_MODE:
optional(() => bool(env.FORCE_DENCUN_FORK_MODE)) ?? false,
optional(() =>
bool(
env.FORCE_DENCUN_FORK_MODE,
'Invalid FORCE_DENCUN_FORK_MODE value: expected true or false'
)
) ?? false,

CAPELLA_FORK_VERSION: optional(() => str(env.CAPELLA_FORK_VERSION)),

Expand Down Expand Up @@ -179,7 +206,11 @@ export const makeLoggerConfig = ({ env }: { env: NodeJS.ProcessEnv }) => {
LOGGER_FORMAT: optional(() => log_format(env.LOGGER_FORMAT)) ?? 'simple',
LOGGER_SECRETS:
optional(() =>
json_arr(env.LOGGER_SECRETS, (secrets) => secrets.map(str))
json_arr(
env.LOGGER_SECRETS,
(secrets) => secrets.map(str),
'Please, setup LOGGER_SECRETS. Example: ["EXECUTION_NODE","CONSENSUS_NODE"]'
)
) ?? [],
}

Expand Down
1 change: 1 addition & 0 deletions src/services/exit-logs/fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('makeConsensusApi logs', () => {
expect(oracleValidatorExitRequestEvents.isDone()).to.be.true
expect(votingValidatorExitRequestEvents.isDone()).to.be.false
expect(res.length).toBe(1)
expect(res[0].stakingModuleId).toBe(1)
expect(res[0].validatorIndex).toBe('351636')
expect(res[0].validatorPubkey).toBe(
'0xab50ef06a0e48d9edf43e052f20dc912e0ba8d5b3f07051b6f2a13b094087f791af79b2780d395444a57e258d838083a'
Expand Down
20 changes: 14 additions & 6 deletions src/services/exit-logs/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ export const makeExitLogsFetcherService = (

const events = logs.map((log) => {
const parsedLog = iface.parseLog(log)
const { validatorIndex, validatorPubkey, nodeOperatorId } =
parsedLog.args as unknown as {
validatorIndex: ethers.BigNumber
validatorPubkey: string
nodeOperatorId: ethers.BigNumber
}
const {
stakingModuleId,
validatorIndex,
validatorPubkey,
nodeOperatorId,
} = parsedLog.args as unknown as {
stakingModuleId: ethers.BigNumber
validatorIndex: ethers.BigNumber
validatorPubkey: string
nodeOperatorId: ethers.BigNumber
}

return {
stakingModuleId,
validatorIndex: validatorIndex.toString(),
validatorPubkey,
nodeOperatorId,
Expand Down Expand Up @@ -202,6 +208,7 @@ export const makeExitLogsFetcherService = (
)

const {
stakingModuleId,
validatorIndex,
validatorPubkey,
nodeOperatorId,
Expand Down Expand Up @@ -237,6 +244,7 @@ export const makeExitLogsFetcherService = (
validatorIndex,
validatorPubkey,
blockNumber: blockNumber,
stakingModuleId: stakingModuleId.toNumber(),
nodeOperatorId: nodeOperatorId.toNumber(),
acknowledged: false,
ack() {
Expand Down
1 change: 1 addition & 0 deletions src/services/exit-logs/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ValidatorsToEject {
stakingModuleId: number
validatorIndex: string
validatorPubkey: string
blockNumber: number
Expand Down
2 changes: 2 additions & 0 deletions src/services/job-processor/job-processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('JobProcessor', () => {

const getLogsSpy = vi.spyOn(exitLogs, 'getLogs').mockResolvedValue([
{
stakingModuleId: 1,
validatorIndex: '12345',
validatorPubkey: 'pubkey1',
blockNumber: 1000,
Expand All @@ -103,6 +104,7 @@ describe('JobProcessor', () => {
ack: ackSpy12345,
},
{
stakingModuleId: 1,
validatorIndex: '67890',
validatorPubkey: 'pubkey2',
blockNumber: 950,
Expand Down
Loading