Skip to content

Commit 862e7c8

Browse files
Remove validators package and use AvalancheGo uptimetracker (#1823)
Signed-off-by: Jonathan Oppenheimer <147infiniti@gmail.com> Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
1 parent b9a99b3 commit 862e7c8

26 files changed

+204
-2151
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
- name: Setup Contracts
9595
run: ./scripts/run_task.sh setup-contracts
9696
- name: Run Warp E2E Tests
97-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@8564a57d3ca61f976c90b4ad96e41640a2a3cdc4
97+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@7d60acaddc22ff5341eca103cb50041ae7890dc3
9898
with:
9999
run: ./scripts/run_task.sh test-e2e-warp-ci
100100
artifact_prefix: warp
@@ -116,7 +116,7 @@ jobs:
116116
with:
117117
fetch-depth: 0
118118
- name: Run E2E Load Tests
119-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@8564a57d3ca61f976c90b4ad96e41640a2a3cdc4
119+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@7d60acaddc22ff5341eca103cb50041ae7890dc3
120120
with:
121121
run: ./scripts/run_task.sh test-e2e-load-ci
122122
artifact_prefix: load

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.9
55
require (
66
github.com/VictoriaMetrics/fastcache v1.12.1
77
github.com/antithesishq/antithesis-sdk-go v0.3.8
8-
github.com/ava-labs/avalanchego v1.13.6-rc.1
8+
github.com/ava-labs/avalanchego v1.13.6-0.20251023135656-7d60acaddc22
99
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.13
1010
github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2
1111
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl
2828
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
2929
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
3030
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
31-
github.com/ava-labs/avalanchego v1.13.6-rc.1 h1:O4qeGhxRVO5O8vfu2LMpwU5AdES/8bB2MeDPcrHmYIc=
32-
github.com/ava-labs/avalanchego v1.13.6-rc.1/go.mod h1:27SGpJ0L+3jVMfjY8X5nmgkZ3sFSc7vGeJj+SFjAKL0=
31+
github.com/ava-labs/avalanchego v1.13.6-0.20251023135656-7d60acaddc22 h1:XyM8irB7PK1lDDyuodQgg+OG8oudp+TgDkugv18PYow=
32+
github.com/ava-labs/avalanchego v1.13.6-0.20251023135656-7d60acaddc22/go.mod h1:wEiDa5Lc3oKm9l2AxJOXmLz00Wg7b3hUttgkfzgRoDA=
3333
github.com/ava-labs/coreth v0.15.4-rc.4 h1:ze7/IwDptWG1u2d32uUZz9Ix9ycVUtlB8JufuSKSSS4=
3434
github.com/ava-labs/coreth v0.15.4-rc.4/go.mod h1:yVwuMyPkZ48xzZ0y2OdIwaoUqvSsgPYoodyX9BZJ2uo=
3535
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.13 h1:obPwnVCkF5+B2f8WbTepHj0ZgiW21vKUgFCtATuAYNY=

plugin/evm/service.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,65 @@ type ValidatorsAPI struct {
1818
vm *VM
1919
}
2020

21-
func (api *ValidatorsAPI) GetCurrentValidators(_ *http.Request, req *client.GetCurrentValidatorsRequest, reply *client.GetCurrentValidatorsResponse) error {
21+
func (api *ValidatorsAPI) GetCurrentValidators(httpReq *http.Request, req *client.GetCurrentValidatorsRequest, reply *client.GetCurrentValidatorsResponse) error {
2222
api.vm.vmLock.RLock()
2323
defer api.vm.vmLock.RUnlock()
24+
ctx := httpReq.Context()
2425

25-
var vIDs set.Set[ids.ID]
26+
validatorSet, _, err := api.vm.ctx.ValidatorState.GetCurrentValidatorSet(ctx, api.vm.ctx.SubnetID)
27+
if err != nil {
28+
return fmt.Errorf("failed to get current validator set: %w", err)
29+
}
30+
31+
// Filter by requested nodeIDs if specified
32+
requestedNodeIDs := set.NewSet[ids.NodeID](len(req.NodeIDs))
2633
if len(req.NodeIDs) > 0 {
27-
vIDs = set.NewSet[ids.ID](len(req.NodeIDs))
2834
for _, nodeID := range req.NodeIDs {
29-
vID, err := api.vm.validatorsManager.GetValidationID(nodeID)
30-
if err != nil {
31-
return fmt.Errorf("couldn't find validator with node ID %s", nodeID)
32-
}
33-
vIDs.Add(vID)
35+
requestedNodeIDs.Add(nodeID)
3436
}
35-
} else {
36-
vIDs = api.vm.validatorsManager.GetValidationIDs()
3737
}
3838

39-
reply.Validators = make([]client.CurrentValidator, 0, vIDs.Len())
40-
41-
for _, vID := range vIDs.List() {
42-
validator, err := api.vm.validatorsManager.GetValidator(vID)
43-
if err != nil {
44-
return fmt.Errorf("couldn't find validator with validation ID %s", vID)
39+
reply.Validators = make([]client.CurrentValidator, 0, len(validatorSet))
40+
for validationID, validator := range validatorSet {
41+
// Skip if specific nodeIDs were requested and this isn't one of them
42+
if requestedNodeIDs.Len() > 0 && !requestedNodeIDs.Contains(validator.NodeID) {
43+
continue
4544
}
4645

47-
isConnected := api.vm.validatorsManager.IsConnected(validator.NodeID)
48-
49-
upDuration, lastUpdated, err := api.vm.validatorsManager.CalculateUptime(validator.NodeID)
46+
upDuration, lastUpdated, found, err := api.vm.uptimeTracker.GetUptime(validationID)
5047
if err != nil {
51-
return err
48+
return fmt.Errorf("failed to get uptime for validation ID %s: %w", validationID, err)
5249
}
50+
if !found {
51+
return fmt.Errorf("validator not found for validation ID %s", validationID)
52+
}
53+
5354
var uptimeFloat float64
54-
startTime := time.Unix(int64(validator.StartTimestamp), 0)
55+
56+
startTime := time.Unix(int64(validator.StartTime), 0)
5557
bestPossibleUpDuration := lastUpdated.Sub(startTime)
5658
if bestPossibleUpDuration == 0 {
5759
uptimeFloat = 1
5860
} else {
5961
uptimeFloat = float64(upDuration) / float64(bestPossibleUpDuration)
6062
}
61-
6263
// Transform this to a percentage (0-100) to make it consistent
6364
// with currentValidators in PlatformVM API
6465
uptimePercentage := float32(uptimeFloat * 100)
66+
uptimeSeconds := uint64(upDuration.Seconds())
67+
68+
isConnected := api.vm.P2PValidators().Has(ctx, validator.NodeID)
6569

6670
reply.Validators = append(reply.Validators, client.CurrentValidator{
67-
ValidationID: validator.ValidationID,
71+
ValidationID: validationID,
6872
NodeID: validator.NodeID,
69-
StartTimestamp: validator.StartTimestamp,
73+
StartTimestamp: validator.StartTime,
7074
Weight: validator.Weight,
7175
IsActive: validator.IsActive,
7276
IsL1Validator: validator.IsL1Validator,
7377
IsConnected: isConnected,
7478
UptimePercentage: uptimePercentage,
75-
UptimeSeconds: uint64(upDuration.Seconds()),
79+
UptimeSeconds: uptimeSeconds,
7680
})
7781
}
7882
return nil

plugin/evm/validators/README.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

plugin/evm/validators/interfaces/interfaces.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

plugin/evm/validators/locked_reader.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)