From cc7e15099bcbcf51e5a2e5128b5a434fe9a991a8 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 26 Nov 2024 20:23:59 +0300 Subject: [PATCH 01/11] add validators pkg readme --- plugin/evm/validators/README.md | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 plugin/evm/validators/README.md diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md new file mode 100644 index 0000000000..993e9143a8 --- /dev/null +++ b/plugin/evm/validators/README.md @@ -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. + +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. + +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. + +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. + +## 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. + +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. + +## 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. + +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. + +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. \ No newline at end of file From 8348704b673d5a2f440f19af74e7f5755e1370f9 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 27 Nov 2024 17:55:25 +0300 Subject: [PATCH 02/11] Apply suggestions from code review Co-authored-by: Meaghan FitzGerald Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index 993e9143a8..f6ef4e5f76 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -4,21 +4,23 @@ The Validators package is a collection of structs and functions to manage the st - 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. +- Manager struct: The manager struct is responsible for managing 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. +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 state manager errors and does not update the validator. -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. +For L1 validators, an `active` status implies the validator balance on the P-Chain is sufficient to cover the continuous validation fee. When an L1 validator balance is depleted, it is marked as `inactive` on the P-Chain and this information is passed to the Subnet-EVM's state. 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. -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. +The package defines how to serialize the data according to the codec. It can read and write the validator state and uptime information within the database. ## 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. +The uptime package manages the uptime tracking of the L1 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. + +The uptime package must be run on at least one L1 node, referred to in this document as the "tracker node". Uptime tracking works as follows: @@ -36,8 +38,8 @@ Uptime tracking works as follows: ## 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. +`ValidatorManager` struct is responsible for managing 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 60 seconds. 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 adds new validators and updates the existing validators in the state. This order off operations ensures that the uptimes of validators being removed and re-added under same nodeIDs are updated in the same sync operation despite having different validationIDs. -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. +P-Chain's `GetCurrentValidatorSet` can report both L1 and Subnet validators. Subnet-EVM's uptime manager also tracks both of these validator types. So even if a the Subnet has not yet been converted to an L1, the uptime and validator state tracking is still performed by Subnet-EVM. 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. \ No newline at end of file From 52ec2f79d9bd33a54829d7c9c533cf074b7fda5b Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 27 Nov 2024 17:56:05 +0300 Subject: [PATCH 03/11] Apply suggestions from code review Co-authored-by: Meaghan FitzGerald Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index f6ef4e5f76..c3db040846 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -24,17 +24,33 @@ The uptime package must be run on at least one L1 node, referred to in this docu 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. +### StartTracking -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. +Nodes can start uptime tracking with the `StartTracking` method once they're bootstrapped. This method updates the uptime of up-to-date validators by adding the duration between their last updated time and tracker node's initializing time to their uptime. This effectively adds the tracker node's offline duration to the validator's uptime and optimistically assumes that the validators are online during this period. Subnet-EVM's pausable manager does not directly modify this behavior and it also updates validators that were paused/inactive before the node initialized. The pausable uptime manager assumes peers are online and `active` when the tracker nodes are offline. -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. +### Connected -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. +The AvalancheGo uptime manager records the time when a peer is connected to the tracker node. When a paused/ `inactive` validator is connected, the pausable uptime manager does not directly invoke the `Connected` method on the AvalancheGo uptime manager, thus the connection time is not directly recorded. Instead, the pausable uptime manager waits for the validator to increase it's continuous validation fee balance and resume operation. When the validator resumes, the tracker node records the resumed time and starts 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. +Note: The 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. -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. +### Disconnected + +When a peer validator is disconnected, the AvalancheGo 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. When a validator is paused/`inactive`, the pausable uptime manager handles the `inactive` peers as if they were disconnected. Thus the uptime manager assumes that no paused peers can be disconnected again from the pausable uptime manager. + +### Pause + +The pausable uptime manager can listen for validator status changes by subscribing to the state. When the state invokes the `OnValidatorStatusChange` method, the pausable uptime manager pauses the uptime tracking of the validator if the validator is currently `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. + +### Resume + +When a paused validator peer resumes, meaning its status become `active`, the pausable uptime manager resumes the uptime tracking of the validator. It treats the peer as if it is connected to the tracker node. + +Note: The pausable uptime manager holds the set of connected peers that tracks the connected peers in the p2p layer. This set is used to start tracking the uptime of the paused/`inactive` validators when they resume; this is because the AvalancheGo uptime manager thinks that the peer is completely disconnected when it is paused. The pausable uptime manager is able to reconnect them to the inner manager by using this additional connected set. + +### CalculateUptime + +The `CalculateUptime` method calculates a node's 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 last connection time to the node's uptime and returns the updated values. ## Validator Manager Struct From da6e04d59eded37cd5f8d9962c55a1307a7378d2 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 27 Nov 2024 18:33:45 +0300 Subject: [PATCH 04/11] Apply suggestions from code review Co-authored-by: Meaghan FitzGerald Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index c3db040846..e63a890a74 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -12,7 +12,7 @@ The state package stores the validator state and uptime information. The state p For L1 validators, an `active` status implies the validator balance on the P-Chain is sufficient to cover the continuous validation fee. When an L1 validator balance is depleted, it is marked as `inactive` on the P-Chain and this information is passed to the Subnet-EVM's state. -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. +The state interface allows a listener to register state changes including validator addition, removal, and active status change. The listener always receives the full state when it first subscribes. The package defines how to serialize the data according to the codec. It can read and write the validator state and uptime information within the database. From af1f9ee8f107e5aa7d9676df906d87f55e926448 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 27 Nov 2024 18:35:36 +0300 Subject: [PATCH 05/11] nits --- plugin/evm/validators/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index e63a890a74..d27e0f6273 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -18,7 +18,7 @@ The package defines how to serialize the data according to the codec. It can rea ## Uptime Package -The uptime package manages the uptime tracking of the L1 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. +The uptime package manages the uptime tracking of the L1 validators. It wraps [AvalancheGo's uptime tracking manager](https://pkg.go.dev/github.com/ava-labs/avalanchego/snow/uptime) 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. The uptime package must be run on at least one L1 node, referred to in this document as the "tracker node". @@ -28,9 +28,9 @@ Uptime tracking works as follows: Nodes can start uptime tracking with the `StartTracking` method once they're bootstrapped. This method updates the uptime of up-to-date validators by adding the duration between their last updated time and tracker node's initializing time to their uptime. This effectively adds the tracker node's offline duration to the validator's uptime and optimistically assumes that the validators are online during this period. Subnet-EVM's pausable manager does not directly modify this behavior and it also updates validators that were paused/inactive before the node initialized. The pausable uptime manager assumes peers are online and `active` when the tracker nodes are offline. -### Connected +### Connected -The AvalancheGo uptime manager records the time when a peer is connected to the tracker node. When a paused/ `inactive` validator is connected, the pausable uptime manager does not directly invoke the `Connected` method on the AvalancheGo uptime manager, thus the connection time is not directly recorded. Instead, the pausable uptime manager waits for the validator to increase it's continuous validation fee balance and resume operation. When the validator resumes, the tracker node records the resumed time and starts tracking the uptime of the validator. +The AvalancheGo uptime manager records the time when a peer is connected to the tracker node. When a paused/ `inactive` validator is connected, the pausable uptime manager does not directly invoke the `Connected` method on the AvalancheGo uptime manager, thus the connection time is not directly recorded. Instead, the pausable uptime manager waits for the validator to increase it's continuous validation fee balance and resume operation. When the validator resumes, the tracker node records the resumed time and starts tracking the uptime of the validator. Note: The 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. @@ -44,7 +44,7 @@ The pausable uptime manager can listen for validator status changes by subscribi ### Resume -When a paused validator peer resumes, meaning its status become `active`, the pausable uptime manager resumes the uptime tracking of the validator. It treats the peer as if it is connected to the tracker node. +When a paused validator peer resumes, meaning its status become `active`, the pausable uptime manager resumes the uptime tracking of the validator. It treats the peer as if it is connected to the tracker node. Note: The pausable uptime manager holds the set of connected peers that tracks the connected peers in the p2p layer. This set is used to start tracking the uptime of the paused/`inactive` validators when they resume; this is because the AvalancheGo uptime manager thinks that the peer is completely disconnected when it is paused. The pausable uptime manager is able to reconnect them to the inner manager by using this additional connected set. From 623c3b83b1b39ea456481ea5af54fefa207c4709 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 2 Dec 2024 13:39:11 +0300 Subject: [PATCH 06/11] reviews --- plugin/evm/validators/README.md | 6 +++--- plugin/evm/vm.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index d27e0f6273..bac578b945 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -44,7 +44,7 @@ The pausable uptime manager can listen for validator status changes by subscribi ### Resume -When a paused validator peer resumes, meaning its status become `active`, the pausable uptime manager resumes the uptime tracking of the validator. It treats the peer as if it is connected to the tracker node. +When a paused validator peer resumes, meaning its status becomes `active`, the pausable uptime manager resumes the uptime tracking of the validator. It treats the peer as if it is connected to the tracker node. Note: The pausable uptime manager holds the set of connected peers that tracks the connected peers in the p2p layer. This set is used to start tracking the uptime of the paused/`inactive` validators when they resume; this is because the AvalancheGo uptime manager thinks that the peer is completely disconnected when it is paused. The pausable uptime manager is able to reconnect them to the inner manager by using this additional connected set. @@ -52,9 +52,9 @@ Note: The pausable uptime manager holds the set of connected peers that tracks t The `CalculateUptime` method calculates a node's 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 last connection time to the node's uptime and returns the updated values. -## Validator Manager Struct +## Manager Struct -`ValidatorManager` struct is responsible for managing 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 60 seconds. 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 adds new validators and updates the existing validators in the state. This order off operations ensures that the uptimes of validators being removed and re-added under same nodeIDs are updated in the same sync operation despite having different validationIDs. +`Manager` struct in `validators` pacakge, is responsible for managing 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 60 seconds. 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 adds new validators and updates the existing validators in the state. This order of operations ensures that the uptimes of validators being removed and re-added under same nodeIDs are updated in the same sync operation despite having different validationIDs. P-Chain's `GetCurrentValidatorSet` can report both L1 and Subnet validators. Subnet-EVM's uptime manager also tracks both of these validator types. So even if a the Subnet has not yet been converted to an L1, the uptime and validator state tracking is still performed by Subnet-EVM. diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 4966114884..4f48c8e234 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -879,6 +879,7 @@ func (vm *VM) Shutdown(context.Context) error { handler.Stop() } vm.eth.Stop() + vm.db.Close() log.Info("Ethereum backend stop completed") vm.shutdownWg.Wait() log.Info("Subnet-EVM Shutdown completed") From 92c7e08f7138c2f683ecf362a500077585393743 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 30 Dec 2024 21:05:20 +0300 Subject: [PATCH 07/11] Update plugin/evm/validators/README.md Co-authored-by: Darioush Jalali Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index bac578b945..20661eb243 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -18,7 +18,7 @@ The package defines how to serialize the data according to the codec. It can rea ## Uptime Package -The uptime package manages the uptime tracking of the L1 validators. It wraps [AvalancheGo's uptime tracking manager](https://pkg.go.dev/github.com/ava-labs/avalanchego/snow/uptime) 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. +The uptime package manages the uptime tracking of the L1 validators. It wraps [AvalancheGo's uptime tracking manager](https://pkg.go.dev/github.com/ava-labs/avalanchego/snow/uptime) under the hood and additionally introduces pausable uptime manager interface. The pausable uptime manager interface allows the manager to pause the uptime tracking for a specific validator when it becomes `inactive` and resume it when it becomes `active` again. The uptime package must be run on at least one L1 node, referred to in this document as the "tracker node". From 8b98c3e9006d86d1f74225583d5153e370ff97f0 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 30 Dec 2024 21:05:29 +0300 Subject: [PATCH 08/11] Update plugin/evm/validators/README.md Co-authored-by: Darioush Jalali Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index 20661eb243..3b9f15369f 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -30,7 +30,7 @@ Nodes can start uptime tracking with the `StartTracking` method once they're boo ### Connected -The AvalancheGo uptime manager records the time when a peer is connected to the tracker node. When a paused/ `inactive` validator is connected, the pausable uptime manager does not directly invoke the `Connected` method on the AvalancheGo uptime manager, thus the connection time is not directly recorded. Instead, the pausable uptime manager waits for the validator to increase it's continuous validation fee balance and resume operation. When the validator resumes, the tracker node records the resumed time and starts tracking the uptime of the validator. +The AvalancheGo uptime manager records the time when a peer is connected to the tracker node. When a paused/ `inactive` validator is connected, the pausable uptime manager does not directly invoke the `Connected` method on the AvalancheGo uptime manager, thus the connection time is not directly recorded. Instead, the pausable uptime manager waits for the validator to increase its continuous validation fee balance and resume operation. When the validator resumes, the tracker node records the resumed time and starts tracking the uptime of the validator. Note: The 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. From c16c12927c6b4a7ad5fa578d7323ea5ff203d687 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 30 Dec 2024 21:05:38 +0300 Subject: [PATCH 09/11] Update plugin/evm/validators/README.md Co-authored-by: Darioush Jalali Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index 3b9f15369f..9dee18b50e 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -40,7 +40,7 @@ When a peer validator is disconnected, the AvalancheGo uptime manager updates th ### Pause -The pausable uptime manager can listen for validator status changes by subscribing to the state. When the state invokes the `OnValidatorStatusChange` method, the pausable uptime manager pauses the uptime tracking of the validator if the validator is currently `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. +The pausable uptime manager can listen for validator status changes by subscribing to the state. When the state invokes the `OnValidatorStatusChange` method, the pausable uptime manager pauses the uptime tracking of the validator if the validator is currently `inactive`. When a validator is paused, it is treated as if it is disconnected from the tracker node; thus, its uptime is updated from the connection time to the pause time, and uptime manager stops tracking the uptime of the validator. ### Resume From 634ff7ddf96d328d360de0a1bce51d5ff81642e7 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 30 Dec 2024 21:05:46 +0300 Subject: [PATCH 10/11] Update plugin/evm/validators/README.md Co-authored-by: Darioush Jalali Signed-off-by: Ceyhun Onur --- plugin/evm/validators/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/validators/README.md b/plugin/evm/validators/README.md index 9dee18b50e..84055b04ab 100644 --- a/plugin/evm/validators/README.md +++ b/plugin/evm/validators/README.md @@ -54,7 +54,7 @@ The `CalculateUptime` method calculates a node's uptime based on its connection ## Manager Struct -`Manager` struct in `validators` pacakge, is responsible for managing 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 60 seconds. 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 adds new validators and updates the existing validators in the state. This order of operations ensures that the uptimes of validators being removed and re-added under same nodeIDs are updated in the same sync operation despite having different validationIDs. +`Manager` struct in `validators` package is responsible for managing 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 60 seconds. 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 adds new validators and updates the existing validators in the state. This order of operations ensures that the uptimes of validators being removed and re-added under same nodeIDs are updated in the same sync operation despite having different validationIDs. P-Chain's `GetCurrentValidatorSet` can report both L1 and Subnet validators. Subnet-EVM's uptime manager also tracks both of these validator types. So even if a the Subnet has not yet been converted to an L1, the uptime and validator state tracking is still performed by Subnet-EVM. From 6e56f9993c021d6af17838ce41f2ebd87b35a224 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 31 Dec 2024 00:26:01 +0300 Subject: [PATCH 11/11] remove change --- plugin/evm/vm.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 4f48c8e234..4966114884 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -879,7 +879,6 @@ func (vm *VM) Shutdown(context.Context) error { handler.Stop() } vm.eth.Stop() - vm.db.Close() log.Info("Ethereum backend stop completed") vm.shutdownWg.Wait() log.Info("Subnet-EVM Shutdown completed")