This repository was archived by the owner on Dec 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
add validators pkg readme #1398
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cc7e150
add validators pkg readme
ceyonur 8348704
Apply suggestions from code review
ceyonur 52ec2f7
Apply suggestions from code review
ceyonur da6e04d
Apply suggestions from code review
ceyonur af1f9ee
nits
ceyonur 623c3b8
reviews
ceyonur 7f195e4
Merge branch 'master' into add-uptime-readme
meaghanfitzgerald 92c7e08
Update plugin/evm/validators/README.md
ceyonur 8b98c3e
Update plugin/evm/validators/README.md
ceyonur c16c129
Update plugin/evm/validators/README.md
ceyonur 634ff7d
Update plugin/evm/validators/README.md
ceyonur 324764b
Merge branch 'master' into add-uptime-readme
ceyonur 6e56f99
remove change
ceyonur 0ca1a73
Merge branch 'add-uptime-readme' of github.com:ava-labs/subnet-evm in…
ceyonur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,43 @@ | ||
| # Validators | ||
|
|
||
| The Validators package is a collection of structs and functions to manage the state and uptime of validators in the Subnet-EVM. It consists of the following components: | ||
|
|
||
| - State package : The state package stores the validator state and uptime information. | ||
| - Uptime package: The uptime package manages the uptime tracking of the validators. | ||
| - Manager struct: The manager struct is responsible to manage the state and uptime of the validators. | ||
|
|
||
| ## State Package | ||
|
|
||
| The state package stores the validator state and uptime information. The state package implements a CRUD interface for validators. The implementation tracks validators by their validationIDs and assumes they're unique per node and their validation period. The state implementation also assumes NodeIDs are unique in the tracked set. The state implementation only allows existing validator's `weight` and `IsActive` fields to be updated; all other fields should be constant and if any other field changes, the the state manager errors and does not update the validator. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For L1 validators active status equals if the validator has enough balance on P-chain to cover continuous fees. When a L1 validator goes out of balance, it is marked as inactive in P-chain and this information is passed to the Subnet-EVM's state. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The State interface allows a listener to register to the state changes including validator addition, removal and active status change. The listener always receives the full state when it first subscribes. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The package defines how to serialize the data with a codec and it can write and read the validator state and uptime information to/from the database. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Uptime Package | ||
|
|
||
| Uptime package manages the uptime tracking of the validators. It wraps AvalancheGo's uptime tracking manager under the hood and additionally introduces pausable uptime manager interface. The pausable uptime manager interface allows the manager to pause and resume the uptime tracking for a specific validator. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Uptime tracking works as follows: | ||
|
|
||
| 1- StartTracking: Nodes can start uptime tracking with `StartTracking` method when they're bootstrapped. This method updates the uptime of up-to-date validators by adding the duration between their last updated and tracker node's initializing time to their uptimes. This effectively adds the offline duration of tracker node's to the uptime of validators and optimistically assumes that the validators are online during this period. Subnet-EVM's Pausable manager does not directly modifies this behaviour and it also updates validators that were paused/inactive before the node initialized. Pausable Uptime Manager assumes peers are online and active (has enough fees) when tracker nodes are offline. | ||
|
|
||
| 2- Connected: Avalanche Uptime manager records the time when a peer is connected to the tracker node (the node running the uptime tracking). When a paused (inactive) validator is connected, pausable uptime manager does not directly invokes the `Connected` on Avalanche Uptime manager, thus the connection time is not directly recorded. Instead, pausable uptime manager waits for the validator to be resumed (top-up fee balance). When the validator is resumed, the tracker records the resumed time and starts tracking the uptime of the validator. Note: Uptime manager does not check if the connected peer is a validator or not. It records the connection time assuming that a non-validator peer can become a validator whilst they're connected to the uptime manager. | ||
|
|
||
| 3- Disconnected: When a peer validator is disconnected, Avalanche Uptime manager updates the uptime of the validator by adding the duration between the connection time and the disconnection time to the uptime of the validator. The pausable uptime manager handles the inactive peers as if they were disconnected when they are paused, thus it assumes that no paused peers can be disconnected again from the pausable uptime manager. | ||
|
|
||
| 4- Pause: Pausable Uptime Manager can listen the validator status change via subscribing to the state. When state invokes the `OnValidatorStatusChange` method, pausable uptime manager pauses the uptime tracking of the validator if the validator is inactive. When a validator is paused, it is treated as if it is disconnected from the tracker node; thus it's uptime is updated from the connection time to the pause time and uptime manager stops tracking the uptime of the validator. | ||
|
|
||
| 5- Resume: When a paused validator peer resumes (status become active), pausable uptime manager resumes the uptime tracking of the validator. It basically treat the peer as if it is connected to the tracker node. Note: Pausable uptime manager holds the set of connected peers that does track the connected peer in p2p layer. The set is used to start tracking the uptime of the paused validators when they resume; this is because the inner AvalancheGo manager thinks that the peer is completely disconnected when it is paused. Pausable uptime manager is able to re-connect them to the inner manager by using this additional connected set. | ||
|
|
||
| 6- CalculateUptime: The CalculateUptime method calculates a node's updated uptime based on its connection status, connected time and the current time. It first retrieves the node's current uptime and last update time from the state, returning an error if retrieval fails. If tracking hasn’t started, it assumes the node has been online since the last update, adding this duration to its uptime. If the node is not connected and tracking is active, uptime remains unchanged and returned. For connected nodes, the method ensures the connection time does not predate the last update to avoid double-counting. Finally, it adds the duration since the connection time to the node's uptime and returns the updated values. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Validator Manager Struct | ||
|
|
||
| Validator Manager struct is responsible to manage the state of the validators by fetching the information from P-chain state (via `GetCurrentValidatorSet` in chain context) and updating the state accordingly. It dispatches a goroutine to sync the validator state every 1 minute. The manager fetches the up-to-date validator set from P-Chain and performs the sync operation. The sync operation first performs removing the validators from the state that are not in the P-Chain validator set. Then it performs adding new validators or updating the existing validators in the state. This ordering ensures that the uptimes of validators being removed for the validators that are removed and readded under same nodeIDs but different validation IDs in the same sync operation. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| P-Chain's `GetCurrentValidatorSet` can report both L1 and permissioned subnet validators. Subnet-EVM's manager also tracks both of these types. So even the subnet is not a converted L1, uptime and validator state tracking is still performed. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Validator Manager persists the state to disk at the end of every sync operation. The VM also persists the validator database when the node is shutting down. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.