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
Refactor uptime tracking #1388
Merged
Merged
Refactor uptime tracking #1388
Changes from 149 commits
Commits
Show all changes
152 commits
Select commit
Hold shift + click to select a range
c2da67d
Bump avalanchego to master
33466ce
always sign uptime messages (testing branch)
964e193
nits
a5cde37
cleanup
c363886
assign to correct `err`
0bf1de6
fix handler
dd66fa7
Merge branches 'always-sign-uptime' and 'master' of github.com:ava-la…
8b3fb1c
move ValidatorUptime type to subnet-evm
008bc37
disable always signing
48f0ab7
implement on the type itself
991ff46
remove unneeded code
fe05d33
fix ut
0747262
Merge branch 'master' into always-sign-uptime-types
c1074a5
Merge branch 'master' into always-sign-uptime-types
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 2841bdb
Merge branch 'master' into always-sign-uptime-types
ceyonur beea962
implement acp118 signer and verifier
ceyonur 701e2ec
avoid revalidating in sign
ceyonur 1c98afa
refactor warp backend to use acp118 handler
ceyonur 8851256
prune warp db before backend init
ceyonur 1a75f6c
add cache tests
ceyonur 7143fc5
remove uptime msg type
ceyonur 243fe5f
add cache test
ceyonur 02eb89b
fix linter
ceyonur f3554f6
Merge branch 'master' into use-acp-118-handler
ceyonur aced003
add validator uptimes
ceyonur 752a5d9
Merge branch 'use-acp-118-handler' of github.com:ava-labs/subnet-evm …
ceyonur 557ea62
Merge branch 'use-acp-118-handler' into validator-uptime-warp-msg
ceyonur 1e46030
bump avago getcurrentvalidators branch
ceyonur 6133246
rename get validator IDs to NodeIDs
ceyonur 72bba65
sign uptime warp msg base on uptime calculator
ceyonur 4db9689
add tests
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 1e1c4c7
Merge branch 'uptime-tracking' into sign-validator-uptime-warp-msg
ceyonur 46c3316
remove wrapped cache
ceyonur 9a50ee8
use non-version db for validatorsDB
ceyonur 58b9c35
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur b45725d
Merge branch 'uptime-tracking' into sign-validator-uptime-warp-msg
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 e00a059
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 0a98101
fix tests
ceyonur 52b83e2
update avago branch
ceyonur 93bedf3
use ctx from utils
ceyonur 2ebf56b
add empty check for source address
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 967765c
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 33a30f0
nits
ceyonur 2aebfe6
remove log
ceyonur 25076c3
disable validators api by default
ceyonur 9d3a1b3
fix test context
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 3912f84
Uptime validation nits (#1378)
ceyonur 2e7f70e
Update plugin/evm/validators/state.go
ceyonur 3b69173
pass locker
ceyonur fd462c5
Merge branch 'uptime-tracking-api' of https://github.com/ava-labs/sub…
ceyonur 1b3b7c9
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 8c7f8d3
rename addresscall verifier fn
ceyonur 5974170
new fields and refactorings
ceyonur 0388e84
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 7dca70e
add new fields
ceyonur 4632c72
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 85db94f
merge nits
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 341006f
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 3d5261d
update comment
ceyonur b5db9ae
remove getnodeID
ceyonur 9f80c5d
Merge branch 'sign-validator-uptime-warp-msg' of https://github.com/a…
ceyonur a80c028
bump to poc branch
ceyonur a417614
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur 6fdeeec
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur c39c7e0
enable validators API by default
ceyonur 64eb51c
Merge branch 'uptime-tracking-api' into sign-validator-uptime-warp-msg
ceyonur 07205f4
refactor uptime tracking
ceyonur d82a29c
Merge branch 'master' into refactor-uptime-tracking
ceyonur 377a22f
Remove unused var
ceyonur 8390b5f
regen mocks
ceyonur 42532d1
add GetValidatorAndUptime to validator manager
ceyonur c881884
Update plugin/evm/validators/interfaces/interfaces.go
ceyonur c91b3a7
Update plugin/evm/validators/manager.go
ceyonur 5793d25
Merge branch 'master' into refactor-uptime-tracking
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package interfaces | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/avalanchego/ids" | ||
| avalancheuptime "github.com/ava-labs/avalanchego/snow/uptime" | ||
| stateinterfaces "github.com/ava-labs/subnet-evm/plugin/evm/validators/state/interfaces" | ||
| ) | ||
|
|
||
| type ValidatorReader interface { | ||
| // GetValidatorUptime returns the uptime of the validator specified by validationID | ||
| GetValidatorAndUptime(validationID ids.ID) (stateinterfaces.Validator, time.Duration, time.Time, error) | ||
| } | ||
|
|
||
| type Manager interface { | ||
| stateinterfaces.State | ||
| avalancheuptime.Manager | ||
| ValidatorReader | ||
|
|
||
| // Sync updates the validator set managed | ||
| // by the manager | ||
| Sync(ctx context.Context) error | ||
| // DispatchSync starts the sync process | ||
| DispatchSync(ctx context.Context) | ||
| } | ||
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,161 @@ | ||
| // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package validators | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/avalanchego/database" | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/snow" | ||
| avalancheuptime "github.com/ava-labs/avalanchego/snow/uptime" | ||
| avalanchevalidators "github.com/ava-labs/avalanchego/snow/validators" | ||
| "github.com/ava-labs/avalanchego/utils/timer/mockable" | ||
| "github.com/ava-labs/subnet-evm/plugin/evm/validators/interfaces" | ||
| validators "github.com/ava-labs/subnet-evm/plugin/evm/validators/state" | ||
| stateinterfaces "github.com/ava-labs/subnet-evm/plugin/evm/validators/state/interfaces" | ||
| "github.com/ava-labs/subnet-evm/plugin/evm/validators/uptime" | ||
| uptimeinterfaces "github.com/ava-labs/subnet-evm/plugin/evm/validators/uptime/interfaces" | ||
|
|
||
| "github.com/ethereum/go-ethereum/log" | ||
| ) | ||
|
|
||
| const ( | ||
| SyncFrequency = 1 * time.Minute | ||
| ) | ||
|
|
||
| type manager struct { | ||
| chainCtx *snow.Context | ||
| stateinterfaces.State | ||
| uptimeinterfaces.PausableManager | ||
| } | ||
|
|
||
| // NewManager returns a new validator manager | ||
| // that manages the validator state and the uptime manager. | ||
| func NewManager( | ||
| ctx *snow.Context, | ||
| db database.Database, | ||
| clock *mockable.Clock, | ||
| ) (interfaces.Manager, error) { | ||
| validatorState, err := validators.NewState(db) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to initialize validator state: %w", err) | ||
| } | ||
|
|
||
| // Initialize uptime manager | ||
| uptimeManager := uptime.NewPausableManager(avalancheuptime.NewManager(validatorState, clock)) | ||
| validatorState.RegisterListener(uptimeManager) | ||
|
|
||
| return &manager{ | ||
| chainCtx: ctx, | ||
| State: validatorState, | ||
| PausableManager: uptimeManager, | ||
| }, nil | ||
| } | ||
|
|
||
| // GetValidatorUptime returns the calculated uptime of the validator specified by validationID | ||
| // and the last updated time. | ||
| // GetValidatorUptime holds the chain context lock while performing the operation and can be called concurrently. | ||
ceyonur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func (m *manager) GetValidatorAndUptime(validationID ids.ID) (stateinterfaces.Validator, time.Duration, time.Time, error) { | ||
| // lock the state | ||
| m.chainCtx.Lock.RLock() | ||
| defer m.chainCtx.Lock.RUnlock() | ||
|
|
||
| // Get validator first | ||
| vdr, err := m.GetValidator(validationID) | ||
| if err != nil { | ||
| return stateinterfaces.Validator{}, 0, time.Time{}, fmt.Errorf("failed to get validator: %w", err) | ||
| } | ||
|
|
||
| uptime, lastUpdated, err := m.CalculateUptime(vdr.NodeID) | ||
| if err != nil { | ||
| return stateinterfaces.Validator{}, 0, time.Time{}, fmt.Errorf("failed to get uptime: %w", err) | ||
| } | ||
|
|
||
| return vdr, uptime, lastUpdated, nil | ||
| } | ||
|
|
||
| // DispatchSync starts the sync process | ||
| // DispatchSync holds the chain context lock while performing the sync. | ||
| func (m *manager) DispatchSync(ctx context.Context) { | ||
| ticker := time.NewTicker(SyncFrequency) | ||
| defer ticker.Stop() | ||
|
|
||
| for { | ||
| select { | ||
| case <-ticker.C: | ||
| m.chainCtx.Lock.Lock() | ||
darioush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err := m.Sync(ctx); err != nil { | ||
| log.Error("failed to sync validators", "error", err) | ||
| } | ||
| m.chainCtx.Lock.Unlock() | ||
| case <-ctx.Done(): | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Sync synchronizes the validator state with the current validator set | ||
| // and writes the state to the database. | ||
| // Sync is not safe to call concurrently and should be called with the chain context locked. | ||
| func (m *manager) Sync(ctx context.Context) error { | ||
| now := time.Now() | ||
| log.Debug("performing validator sync") | ||
| // get current validator set | ||
| currentValidatorSet, _, err := m.chainCtx.ValidatorState.GetCurrentValidatorSet(ctx, m.chainCtx.SubnetID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get current validator set: %w", err) | ||
| } | ||
|
|
||
| // load the current validator set into the validator state | ||
| if err := loadValidators(m.State, currentValidatorSet); err != nil { | ||
| return fmt.Errorf("failed to load current validators: %w", err) | ||
| } | ||
|
|
||
| // write validators to the database | ||
| if err := m.State.WriteState(); err != nil { | ||
| return fmt.Errorf("failed to write validator state: %w", err) | ||
| } | ||
|
|
||
| // TODO: add metrics | ||
| log.Debug("validator sync complete", "duration", time.Since(now)) | ||
| return nil | ||
| } | ||
|
|
||
| // loadValidators loads the [validators] into the validator state [validatorState] | ||
| func loadValidators(validatorState stateinterfaces.State, newValidators map[ids.ID]*avalanchevalidators.GetCurrentValidatorOutput) error { | ||
| currentValidationIDs := validatorState.GetValidationIDs() | ||
| // first check if we need to delete any existing validators | ||
| for vID := range currentValidationIDs { | ||
| // if the validator is not in the new set of validators | ||
| // delete the validator | ||
| if _, exists := newValidators[vID]; !exists { | ||
| validatorState.DeleteValidator(vID) | ||
| } | ||
| } | ||
|
|
||
| // then load the new validators | ||
| for newVID, newVdr := range newValidators { | ||
| currentVdr := stateinterfaces.Validator{ | ||
| ValidationID: newVID, | ||
| NodeID: newVdr.NodeID, | ||
| Weight: newVdr.Weight, | ||
| StartTimestamp: newVdr.StartTime, | ||
| IsActive: newVdr.IsActive, | ||
| IsSoV: newVdr.IsSoV, | ||
| } | ||
| if currentValidationIDs.Contains(newVID) { | ||
| if err := validatorState.UpdateValidator(currentVdr); err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| if err := validatorState.AddValidator(currentVdr); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
| 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.