Skip to content

Commit

Permalink
refactor: command-line options in typescript scripts
Browse files Browse the repository at this point in the history
Co-authored-by: Aneta Tsvetkova <anetastsvetkova@gmail.com>
  • Loading branch information
Xearty and Owliie committed Feb 29, 2024
1 parent df6cfcd commit 8f2cdec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,17 @@ import { computeEpochAt } from '../../../libs/typescript/ts-utils/ssz-utils';
import validator_commitment_constants from '../constants/validator_commitment_constants.json';
import config from "../common_config.json";
import { Validator } from '../../../relay/types/types';
import { CommandLineOptionsBuilder } from '../cmdline';

const CIRCUIT_SIZE = 8;
let TAKE: number;

(async () => {
const { ssz } = await import('@lodestar/types');

const options = yargs
.usage(
'Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>',
)
.option('redis-host ', {
alias: 'redis-host',
describe: 'The Redis host',
type: 'string',
default: config['redis-host'],
description: 'Sets a custom redis connection',
})
.option('redis-port', {
alias: 'redis-port',
describe: 'The Redis port',
type: 'number',
default: Number(config['redis-port']),
description: 'Sets a custom redis connection',
})
const options = new CommandLineOptionsBuilder()
.usage('Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>')
.withRedisOpts()
.option('beacon-node', {
alias: 'beacon-node',
describe: 'The beacon node url',
Expand Down Expand Up @@ -68,12 +54,13 @@ let TAKE: number;
default: false,
description: 'Runs the tool without doing actual calculations.',
})
.options('offset', {
.option('offset', {
alias: 'offset',
describe: 'Index offset in the validator set',
type: 'number',
default: undefined,
}).argv;
})
.build();

const redis = new RedisLocal(options['redis-host'], options['redis-port']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import { Redis as RedisLocal } from '../../../relay/implementations/redis';

import validator_commitment_constants from '../constants/validator_commitment_constants.json';
import yargs from 'yargs';
import { createProofStorage } from '../proof_storage/proof_storage';
import { CommandLineOptionsBuilder } from '../cmdline';

require('dotenv').config({ path: '../.env' });

(async () => {
const options = yargs
.usage(
'Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>',
)
.option('redis-host ', {
alias: 'redis-host',
describe: 'The Redis host',
type: 'string',
default: '127.0.0.1',
description: 'Sets a custom redis connection',
})
.option('redis-port', {
alias: 'redis-port',
describe: 'The Redis port',
type: 'number',
default: 6379,
description: 'Sets a custom redis connection',
})
const options = new CommandLineOptionsBuilder()
.usage('Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>')
.withProofStorageOpts()
.option('oldest-epoch', {
alias: 'oldest-epoch',
describe: 'The oldest epoch for which we keep data',
type: 'number',
demandOption: true,
}).argv;
})
.build();

const redis = new RedisLocal(options['redis-host'], options['redis-port']);
const proofStorage = createProofStorage(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,46 @@
import yargs from 'yargs';
import config from "../common_config.json";
import { CommandLineOptionsBuilder } from '../cmdline';
import { CommitmentMapperScheduler } from './scheduler';
import config from "../common_config.json";

(async () => {
const options = yargs
.usage(
'Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>',
)
.option('redis-host ', {
alias: 'redis-host',
describe: 'The Redis host',
type: 'string',
default: config['redis-host'],
description: 'Sets a custom redis connection',
})
.option('redis-port', {
alias: 'redis-port',
describe: 'The Redis port',
type: 'number',
default: Number(config['redis-port']),
description: 'Sets a custom redis connection',
})
const options = new CommandLineOptionsBuilder()
.usage('Usage: -redis-host <Redis host> -redis-port <Redis port> -take <number of validators>')
.withRedisOpts()
.option('beacon-node', {
alias: 'beacon-node',
describe: 'The beacon node url',
type: 'string',
default: config['beacon-node'],
description: 'Sets a custom beacon node url',
})
.option('sync-epoch', {
alias: 'sync-epoch',
describe: 'The sync epoch',
type: 'number',
default: undefined,
description: 'Starts syncing from this epoch',
})
.options('offset', {
alias: 'offset',
.option('offset', {
describe: 'Index offset in the validator set',
type: 'number',
default: undefined,
})
.option('take', {
alias: 'take',
describe: 'The number of validators to take',
type: 'number',
default: Infinity,
description: 'Sets the number of validators to take',
})
.option('mock', {
alias: 'mock',
describe: 'Runs the tool without doing actual calculations',
type: 'boolean',
default: false,
description: 'Runs the tool without doing actual calculations.',
})
.option('run-once', {
alias: 'run-once',
describe: 'Should run script for one epoch',
type: 'boolean',
default: false,
})
.argv;
.build();

const scheduler = new CommitmentMapperScheduler();
await scheduler.init(options);
Expand Down

0 comments on commit 8f2cdec

Please sign in to comment.