Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ Available metrics:
- Node requests are repeated on error or timeouts
- Amount of messages left to send out can be checked using metrics
- Dry run mode to test setup

## TODO

1. check sync blocksLoop and JOB_INTERVAL
2. check message validation in real time as fork could be changed during app working time
3. remove typechain
2 changes: 2 additions & 0 deletions src/app/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const bootstrap = async () => {

const metrics = makeMetrics()

// TODO: 5 sec is not enough. set 0.5 - 1 min
const executionApi = makeExecutionApi(
makeRequest([
retry(3),
Expand All @@ -57,6 +58,7 @@ export const bootstrap = async () => {
config
)

// TODO: 5 sec is not enough. 0.5 - 1 min
const consensusApi = makeConsensusApi(
makeRequest([
retry(3),
Expand Down
5 changes: 4 additions & 1 deletion src/services/consensus-api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const makeConsensusApi = (
logger: ReturnType<typeof makeLogger>,
{ CONSENSUS_NODE, DRY_RUN }: { CONSENSUS_NODE: string; DRY_RUN: boolean }
) => {
// TODO: check url node normalization
// https://nodejs.org/dist/latest-v19.x/docs/api/url.html
const normalizedUrl = CONSENSUS_NODE.endsWith('/')
? CONSENSUS_NODE.slice(0, -1)
: CONSENSUS_NODE
Expand Down Expand Up @@ -52,7 +54,7 @@ export const makeConsensusApi = (
const req = await request(
`${normalizedUrl}/eth/v1/beacon/states/finalized/validators/${id}`
)

// TODO: refactoring
if (!req.ok) {
const { message } = (await req.json()) as { message: string }
throw new Error(message)
Expand All @@ -65,6 +67,7 @@ export const makeConsensusApi = (
const status = result.data.status

let isExiting: boolean
// TODO: use exit_epoch != far_future_epoch check instead
switch (status) {
case 'active_exiting':
case 'exited_unslashed':
Expand Down
5 changes: 5 additions & 0 deletions src/services/execution-api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const makeExecutionApi = (
}
}

// TODO: describe params
const latestBlockNumber = async () => {
const res = await request(normalizedUrl, {
method: 'POST',
Expand All @@ -64,16 +65,20 @@ export const makeExecutionApi = (
result: { number },
} = lastBlockNumberDTO(json)
logger.debug('fetched latest block number')
// TODO: simplify if possible
return ethers.BigNumber.from(number).toNumber()
}

const logs = async (fromBlock: number, toBlock: number) => {
// TODO: move event to const
// TODO: check abi relevance
const event = ethers.utils.Fragment.from(
'event ValidatorExitRequest(uint256 indexed stakingModuleId, uint256 indexed nodeOperatorId, uint256 indexed validatorIndex, bytes validatorPubkey, uint256 timestamp)'
)
const iface = new ethers.utils.Interface([event])
const eventTopic = iface.getEventTopic(event.name)

// TODO: use ethers encoding func?
const res = await request(normalizedUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand Down
3 changes: 2 additions & 1 deletion src/services/messages-processor/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const makeMessagesProcessor = ({
)
return
}

// TODO: extra request, add index as func arg
const validatorIndex = (await consensusApi.validatorInfo(pubKey)).index
const message = messages.find(
(msg) => msg.message.validator_index === validatorIndex
Expand All @@ -216,6 +216,7 @@ export const makeMessagesProcessor = ({
}

try {
// TODO: could 1 key be sent twice ?
await consensusApi.exitRequest(message)
logger.info('Message sent successfully to exit', pubKey)
metrics.exitActions.inc({ result: 'success' })
Expand Down
4 changes: 4 additions & 0 deletions src/services/prom/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const register = new client.Registry()

export type MetricsService = ReturnType<typeof makeMetrics>

// TODO: prefix false for general metrics
// TODO: add metrics for last block (timestamp) for EL CL
// TODO: default metrics operator_id, version app etc
// TODO: alerts for rem exit messages number ?
const PREFIX = 'validator_ejector_'

export const makeMetrics = () => {
Expand Down