-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: misc * fix: daemon * chore: logs and exit * fix: contracts * feat: progress bar -> spinner * chore: refactor prover service * feat: cli
- Loading branch information
1 parent
37191a4
commit 30b8bd4
Showing
20 changed files
with
361 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
# CLI working mode | ||
ETH_NETWORK=1 | ||
EL_RPC_URLS=https://mainnet.infura.io/v3/... | ||
CL_API_URLS=https://quiknode.pro/... | ||
CSM_ADDRESS=0x9D4AF1Ee19Dad8857db3a45B0374c81c8A1C6320 | ||
VERIFIER_ADDRESS=0x9D4AF1Ee19Dad8857db3a45B0374c81c8A1C6321 | ||
TX_SIGNER_PRIVATE_KEY=0x... | ||
|
||
# Daemon working mode | ||
ETH_NETWORK=1 | ||
EL_RPC_URLS=https://mainnet.infura.io/v3/... | ||
CL_API_URLS=https://quiknode.pro/... | ||
KEYSAPI_API_URLS=https://keys-api.lido.fi/ | ||
CSM_ADDRESS=0x9D4AF1Ee19Dad8857db3a45B0374c81c8A1C6320 | ||
VERIFIER_ADDRESS=0x9D4AF1Ee19Dad8857db3a45B0374c81c8A1C6321 | ||
TX_SIGNER_PRIVATE_KEY=0x... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { CliService } from './cli.service'; | ||
import { ProveCommand } from './commands/prove.command'; | ||
import { ProofInputQuestion } from './questions/proof-input.question'; | ||
import { TxExecutionQuestion } from './questions/tx-execution.question'; | ||
import { ConfigModule } from '../common/config/config.module'; | ||
import { ContractsModule } from '../common/contracts/contracts.module'; | ||
import { LoggerModule } from '../common/logger/logger.module'; | ||
import { ProverModule } from '../common/prover/prover.module'; | ||
import { ProvidersModule } from '../common/providers/providers.module'; | ||
|
||
@Module({ | ||
imports: [LoggerModule, ConfigModule, ProvidersModule, ProverModule], | ||
providers: [CliService], | ||
imports: [LoggerModule, ConfigModule, ContractsModule, ProvidersModule, ProverModule], | ||
providers: [CliService, ProveCommand, ProofInputQuestion, TxExecutionQuestion], | ||
exports: [CliService, ProveCommand, ProofInputQuestion, TxExecutionQuestion], | ||
}) | ||
export class CliModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; | ||
import { Inject, Injectable, LoggerService, OnApplicationBootstrap } from '@nestjs/common'; | ||
import { Inject, Injectable, LoggerService, OnModuleInit } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class CliService implements OnApplicationBootstrap { | ||
export class CliService implements OnModuleInit { | ||
constructor(@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService) {} | ||
async onApplicationBootstrap() { | ||
async onModuleInit() { | ||
this.logger.log('Working mode: CLI'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; | ||
import { Inject, LoggerService } from '@nestjs/common'; | ||
import { Command as Commander } from 'commander'; | ||
import { Command, CommandRunner, InjectCommander, InquirerService, Option } from 'nest-commander'; | ||
|
||
import { CsmContract } from '../../common/contracts/csm-contract.service'; | ||
import { ProverService } from '../../common/prover/prover.service'; | ||
import { KeyInfoFn } from '../../common/prover/types'; | ||
import { Consensus } from '../../common/providers/consensus/consensus'; | ||
import { Execution } from '../../common/providers/execution/execution'; | ||
|
||
type ProofOptions = { | ||
nodeOperatorId: string; | ||
keyIndex: string; | ||
validatorIndex: string; | ||
block: string; | ||
}; | ||
|
||
@Command({ | ||
name: 'prove', | ||
description: 'Prove a withdrawal or slashing', | ||
arguments: '<withdrawal|slashing>', | ||
argsDescription: { | ||
withdrawal: 'Prove a withdrawal', | ||
slashing: 'Prove a slashing', | ||
}, | ||
}) | ||
export class ProveCommand extends CommandRunner { | ||
private options: ProofOptions; | ||
private pubkey: string; | ||
|
||
constructor( | ||
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService, | ||
@InjectCommander() private readonly commander: Commander, | ||
protected readonly inquirerService: InquirerService, | ||
protected readonly csm: CsmContract, | ||
protected readonly consensus: Consensus, | ||
protected readonly execution: Execution, | ||
protected readonly prover: ProverService, | ||
) { | ||
super(); | ||
} | ||
|
||
async run(inputs: string[], options?: ProofOptions) { | ||
try { | ||
this.options = await this.inquirerService.ask('proof-input', options); | ||
this.logger.debug!(this.options); | ||
this.pubkey = await this.csm.getNodeOperatorKey(this.options.nodeOperatorId, this.options.keyIndex); | ||
this.logger.debug!(`Validator public key: ${this.pubkey}`); | ||
const header = await this.consensus.getBeaconHeader('finalized'); | ||
this.logger.debug!(`Finalized slot [${header.header.message.slot}]. Root [${header.root}]`); | ||
const { root: blockRootToProcess } = await this.consensus.getBeaconHeader(this.options.block); | ||
const blockInfoToProcess = await this.consensus.getBlockInfo(this.options.block); | ||
this.logger.debug!(`Block to process [${this.options.block}]`); | ||
|
||
switch (inputs[0]) { | ||
case 'withdrawal': | ||
await this.prover.handleWithdrawalsInBlock(blockRootToProcess, blockInfoToProcess, header, this.keyInfoFn); | ||
break; | ||
case 'slashing': | ||
await this.prover.handleSlashingsInBlock(blockInfoToProcess, header, this.keyInfoFn); | ||
break; | ||
} | ||
} catch (e) { | ||
this.commander.error(e); | ||
} | ||
} | ||
|
||
@Option({ | ||
flags: '--node-operator-id <nodeOperatorId>', | ||
description: 'Node Operator ID from the CSM', | ||
}) | ||
parseNodeOperatorId(val: string) { | ||
return val; | ||
} | ||
|
||
@Option({ | ||
flags: '--key-index <keyIndex>', | ||
description: 'Key Index from the CSM', | ||
}) | ||
parseKeyIndex(val: string) { | ||
return val; | ||
} | ||
|
||
@Option({ | ||
flags: '--validator-index <validatorIndex>', | ||
description: 'Validator Index from the Consensus Layer', | ||
}) | ||
parseValidatorIndex(val: string) { | ||
return val; | ||
} | ||
|
||
@Option({ | ||
flags: '--block <block>', | ||
description: 'Block from the Consensus Layer with validator withdrawal. Might be a block root or a slot number', | ||
}) | ||
parseBlock(val: string) { | ||
return val; | ||
} | ||
|
||
keyInfoFn: KeyInfoFn = (valIndex: number) => { | ||
if (valIndex === Number(this.options.validatorIndex)) { | ||
return { | ||
operatorId: Number(this.options.nodeOperatorId), | ||
keyIndex: Number(this.options.keyIndex), | ||
pubKey: this.pubkey, | ||
}; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Question, QuestionSet } from 'nest-commander'; | ||
|
||
@QuestionSet({ name: 'proof-input' }) | ||
export class ProofInputQuestion { | ||
@Question({ | ||
message: 'Node operator ID:', | ||
name: 'nodeOperatorId', | ||
}) | ||
parseNodeOperatorId(val: string) { | ||
return val; | ||
} | ||
@Question({ | ||
message: 'Key index:', | ||
name: 'keyIndex', | ||
}) | ||
parseKeyIndex(val: string) { | ||
return val; | ||
} | ||
|
||
@Question({ | ||
message: 'Validator index:', | ||
name: 'validatorIndex', | ||
}) | ||
parseValidatorIndex(val: string) { | ||
return val; | ||
} | ||
|
||
@Question({ | ||
message: 'Block (root or slot number):', | ||
name: 'block', | ||
}) | ||
parseBlock(val: string) { | ||
return val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Question, QuestionSet } from 'nest-commander'; | ||
|
||
@QuestionSet({ name: 'tx-execution' }) | ||
export class TxExecutionQuestion { | ||
@Question({ | ||
type: 'confirm', | ||
askAnswered: true, | ||
message: 'Are you sure you want to send this transaction?', | ||
name: 'sendingConfirmed', | ||
}) | ||
parseSendingConfirmed(val: boolean) { | ||
return val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.