jito-foundation / stakenet

Jito StakeNet
https://www.jito.network/stakenet/
Apache License 2.0
40 stars 17 forks source link

REFACTOR: Simplified keeper bot #36

Closed coachchucksol closed 2 months ago

coachchucksol commented 2 months ago

The goal of this refactor is to reduce number of transactions sent and reduce complexity by:

It accomplishes these things by running a single forever loop and keeping track of a global KeeperState.

Keeper State

The KeeperState keeps track of:

Note: All maps are key'd by the vote_account

Program

Initialize

Gather all needed arguments, and initialize the global KeeperState.

Loop

The forever loop consists of three parts: Fetch, Fire and Emit. There is only ever one Fetch and Emit section, and there can be several Fire sections.

The Fire sections can run on independent cadences - say we want the Validator History functions to run every 300sec and we want to emit metrics every 60sec.

The Fetch section is run before and Fire section. The Emit section is one tick after any Fire section.

Fetch

The Fetch section is in charge of three operations:

This is accomplished is by running three functions within the Fetch section

Since this is run before every FIRE section, some accounts will be fetched that are not needed. This may seem wasteful but the simplicity of having a synchronized global is worth the cost.

Notes:

Fire

There are several Fire sections running at their own cadence. Before any Fire section is run, the Fetch section will be called.

Each Fire is a call to operations::operation_name::fire which will fire off the operation and return the new count of runs and errors for that operation to be saved in the KeeperState

Notes:

Emit

This section emits the state of the Keeper one tick after any operation has been called. This is because we want to emit a failure of any Fetch operation, which on failure advances the tick.