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
Uptime tracking api #1374
Merged
Merged
Uptime tracking api #1374
Changes from 61 commits
Commits
Show all changes
97 commits
Select commit
Hold shift + click to select a range
ce36343
add validator state
ceyonur 549d319
add pausable uptime manager
ceyonur 9987248
remove stuttering name
ceyonur e1ef744
Merge branch 'master' into validator-state
ceyonur b33ffbe
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur 0f16af2
rename state listener
ceyonur df3ce63
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur 5f64be3
add uptime tracking to VM
ceyonur 6ff4954
remove unused param
ceyonur 55927b2
add wg for update validators
ceyonur 92fba2e
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur bdc2cc3
update state before network shutdown
ceyonur 657e542
restart bootstrapping status in test
ceyonur 9d6d40e
Merge branch 'uptime-tracking' of https://github.com/ava-labs/subnet-…
ceyonur 9eaa3f3
add get validator to state
ceyonur 66747f8
rename uptime to validator
ceyonur 86a68c8
fix mock state
ceyonur f43bae2
tests
ceyonur 92f6b7e
Update plugin/evm/validators/state.go
ceyonur 0db2041
use update enum
ceyonur c5520bc
Update plugin/evm/validators/state.go
ceyonur dea94af
Update plugin/evm/validators/state.go
ceyonur c0f6ff4
respond to comments
ceyonur b7de0f6
Merge branch 'validator-state' of https://github.com/ava-labs/subnet-…
ceyonur b566103
update avalanchego dep branch
ceyonur 66ab74b
update avalanchego dep branch
ceyonur ad3a35a
reviews
ceyonur 64fe238
reword errs
ceyonur 33d24d1
Merge branch 'pausable-uptime-manager' of https://github.com/ava-labs…
ceyonur d7338da
fix test changes
ceyonur 8eab611
Merge branch 'master' into uptime-tracking-base
ceyonur 9ad5528
fix upgrades after deactivating latest in context
ceyonur 4536590
Merge branch 'uptime-tracking-base' into validator-state
ceyonur fc71949
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur 4304ac5
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur 3225a32
use test branch from avalanchego
ceyonur df6ad02
use branch commit for ava version
ceyonur 738003f
update e2e ava version
ceyonur 29a501d
update avago dep
ceyonur 71c7de0
remove extra line...
ceyonur cc6ce95
Merge branch 'master' into uptime-tracking-base
ceyonur bcd4c9c
Merge branch 'uptime-tracking-base' into validator-state
ceyonur a49dd8d
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur 27884f4
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur b9d6336
export struct
ceyonur 734b201
Merge branch 'master' into validator-state
ceyonur 3e94861
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur cab1ddf
reviews
ceyonur d1a0ae8
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur 5f8bf5b
conflict fix
ceyonur 0ba2869
custom err msg
ceyonur 374d885
add listener mock
ceyonur 1fcca58
Merge branch 'master' into validator-state
ceyonur c41f39c
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur f828d53
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur 9e707ad
bump avago test branch
ceyonur cc73266
remove config
ceyonur 8ef763f
remove api changes
ceyonur 2a9da82
Revert "remove api changes"
ceyonur 9a50ee8
use non-version db for validatorsDB
ceyonur 58b9c35
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur af39b2c
remove errs from resume and pause
ceyonur d5d3545
check after stopping
ceyonur 6fffc2b
use expectedTime in tests
ceyonur 4625f7c
reviews
ceyonur e1975cf
Update plugin/evm/vm.go
ceyonur 74bd249
fix len
ceyonur e5ab9f2
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 7c33221
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur 733da4c
Merge branch 'master' into pausable-uptime-manager
ceyonur 347055c
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur 335d8bc
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 2aebfe6
remove log
ceyonur 25076c3
disable validators api by default
ceyonur d737c11
Merge branch 'master' into uptime-tracking
ceyonur 6468d36
use interfaces from pkgs
ceyonur 10c4bd4
improve comments
ceyonur 9490aae
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur fd462c5
Merge branch 'uptime-tracking-api' of https://github.com/ava-labs/sub…
ceyonur 5974170
new fields and refactorings
ceyonur 0388e84
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 7dca70e
add new fields
ceyonur 48ef70f
Merge branch 'master' into uptime-tracking
ceyonur 424e7a7
fix linter
ceyonur 4fa19b9
clarify comments
ceyonur 4559ab9
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 3d5261d
update comment
ceyonur a80c028
bump to poc branch
ceyonur a417614
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur c39c7e0
enable validators API by default
ceyonur 15886c1
reviews
ceyonur bf9b962
Merge branch 'master' into uptime-tracking
ceyonur ebaaefc
update comment
ceyonur 3283e36
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur a943b6f
update to avago master
ceyonur a8abbc3
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 09c4401
Merge branch 'master' into uptime-tracking-api
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
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
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,38 @@ | ||
| // (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package evm | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| ) | ||
|
|
||
| // SnowmanAPI introduces snowman specific functionality to the evm | ||
| type SnowmanAPI struct{ vm *VM } | ||
|
|
||
| // GetAcceptedFrontReply defines the reply that will be sent from the | ||
| // GetAcceptedFront API call | ||
| type GetAcceptedFrontReply struct { | ||
| Hash common.Hash `json:"hash"` | ||
| Number *big.Int `json:"number"` | ||
| } | ||
|
|
||
| // GetAcceptedFront returns the last accepted block's hash and height | ||
| func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontReply, error) { | ||
| blk := api.vm.blockChain.LastConsensusAcceptedBlock() | ||
| return &GetAcceptedFrontReply{ | ||
| Hash: blk.Hash(), | ||
| Number: blk.Number(), | ||
| }, nil | ||
| } | ||
|
|
||
| // IssueBlock to the chain | ||
| func (api *SnowmanAPI) IssueBlock(ctx context.Context) error { | ||
| log.Info("Issuing a new block") | ||
| api.vm.builder.signalTxsReady() | ||
| return nil | ||
| } | ||
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
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
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
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
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
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,156 @@ | ||
| // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package uptime | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/ava-labs/subnet-evm/plugin/evm/validators" | ||
| "github.com/ethereum/go-ethereum/log" | ||
|
|
||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/snow/uptime" | ||
| "github.com/ava-labs/avalanchego/utils/set" | ||
| ) | ||
|
|
||
| var _ validators.StateCallbackListener = &pausableManager{} | ||
|
|
||
| var ( | ||
| errPausedDisconnect = errors.New("paused node cannot be disconnected") | ||
| errAlreadyPaused = errors.New("node is already paused") | ||
| errNotPaused = errors.New("node is not paused") | ||
| ) | ||
|
|
||
| type PausableManager interface { | ||
| uptime.Manager | ||
| validators.StateCallbackListener | ||
| IsPaused(nodeID ids.NodeID) bool | ||
| } | ||
|
|
||
| type pausableManager struct { | ||
| uptime.Manager | ||
| pausedVdrs set.Set[ids.NodeID] | ||
| // connectedVdrs is a set of nodes that are connected to the manager. | ||
| // This is used to immediately connect nodes when they are unpaused. | ||
| connectedVdrs set.Set[ids.NodeID] | ||
| } | ||
|
|
||
| // NewPausableManager takes an uptime.Manager and returns a PausableManager | ||
| func NewPausableManager(manager uptime.Manager) PausableManager { | ||
| return &pausableManager{ | ||
| pausedVdrs: make(set.Set[ids.NodeID]), | ||
| connectedVdrs: make(set.Set[ids.NodeID]), | ||
| Manager: manager, | ||
| } | ||
| } | ||
|
|
||
| // Connect connects the node with the given ID to the uptime.Manager | ||
| // If the node is paused, it will not be connected | ||
| func (p *pausableManager) Connect(nodeID ids.NodeID) error { | ||
| p.connectedVdrs.Add(nodeID) | ||
| if !p.IsPaused(nodeID) && !p.Manager.IsConnected(nodeID) { | ||
| return p.Manager.Connect(nodeID) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Disconnect disconnects the node with the given ID from the uptime.Manager | ||
| // If the node is paused, it will not be disconnected | ||
| // Invariant: we should never have a connected paused node that is disconnecting | ||
| func (p *pausableManager) Disconnect(nodeID ids.NodeID) error { | ||
| p.connectedVdrs.Remove(nodeID) | ||
| if p.Manager.IsConnected(nodeID) { | ||
| if p.IsPaused(nodeID) { | ||
| // We should never see this case | ||
| return errPausedDisconnect | ||
| } | ||
| return p.Manager.Disconnect(nodeID) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // StartTracking starts tracking uptime for the nodes with the given IDs | ||
| // If a node is paused, it will not be tracked | ||
| func (p *pausableManager) StartTracking(nodeIDs []ids.NodeID) error { | ||
| var activeNodeIDs []ids.NodeID | ||
| for _, nodeID := range nodeIDs { | ||
| if !p.IsPaused(nodeID) { | ||
| activeNodeIDs = append(activeNodeIDs, nodeID) | ||
| } | ||
| } | ||
| return p.Manager.StartTracking(activeNodeIDs) | ||
| } | ||
|
|
||
| // OnValidatorAdded is called when a validator is added. | ||
| // If the node is inactive, it will be paused. | ||
| func (p *pausableManager) OnValidatorAdded(vID ids.ID, nodeID ids.NodeID, startTime uint64, isActive bool) { | ||
| if !isActive { | ||
| err := p.pause(nodeID) | ||
| if err != nil { | ||
| log.Error("failed to handle added validator %s: %s", nodeID, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // OnValidatorRemoved is called when a validator is removed. | ||
| // If the node is already paused, it will be resumed. | ||
| func (p *pausableManager) OnValidatorRemoved(vID ids.ID, nodeID ids.NodeID) { | ||
| if p.IsPaused(nodeID) { | ||
| err := p.resume(nodeID) | ||
| if err != nil { | ||
| log.Error("failed to handle validator removed %s: %s", nodeID, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // OnValidatorStatusUpdated is called when the status of a validator is updated. | ||
| // If the node is active, it will be resumed. If the node is inactive, it will be paused. | ||
| func (p *pausableManager) OnValidatorStatusUpdated(vID ids.ID, nodeID ids.NodeID, isActive bool) { | ||
| var err error | ||
| if isActive { | ||
| err = p.resume(nodeID) | ||
| } else { | ||
| err = p.pause(nodeID) | ||
| } | ||
| if err != nil { | ||
| log.Error("failed to update status for node %s: %s", nodeID, err) | ||
| } | ||
| } | ||
|
|
||
| // IsPaused returns true if the node with the given ID is paused. | ||
| func (p *pausableManager) IsPaused(nodeID ids.NodeID) bool { | ||
| return p.pausedVdrs.Contains(nodeID) | ||
| } | ||
|
|
||
| // pause pauses uptime tracking for the node with the given ID | ||
| // pause can disconnect the node from the uptime.Manager if it is connected. | ||
| // Returns an error if the node is already paused. | ||
| func (p *pausableManager) pause(nodeID ids.NodeID) error { | ||
| if p.IsPaused(nodeID) { | ||
| return errAlreadyPaused | ||
| } | ||
| p.pausedVdrs.Add(nodeID) | ||
| if p.Manager.IsConnected(nodeID) { | ||
| // If the node is connected, then we need to disconnect it from | ||
| // manager | ||
| // This should be fine in case tracking has not started yet since | ||
| // the inner manager should handle disconnects accordingly | ||
| return p.Manager.Disconnect(nodeID) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // resume resumes uptime tracking for the node with the given ID | ||
| // resume can connect the node to the uptime.Manager if it was connected. | ||
| // Returns an error if the node is not paused. | ||
| func (p *pausableManager) resume(nodeID ids.NodeID) error { | ||
| if !p.IsPaused(nodeID) { | ||
| return errNotPaused | ||
| } | ||
| p.pausedVdrs.Remove(nodeID) | ||
| if p.connectedVdrs.Contains(nodeID) && !p.Manager.IsConnected(nodeID) { | ||
| return p.Manager.Connect(nodeID) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
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.