Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
ce36343
add validator state
ceyonur Sep 16, 2024
549d319
add pausable uptime manager
ceyonur Sep 16, 2024
9987248
remove stuttering name
ceyonur Sep 16, 2024
e1ef744
Merge branch 'master' into validator-state
ceyonur Sep 16, 2024
b33ffbe
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Sep 16, 2024
0f16af2
rename state listener
ceyonur Sep 16, 2024
df3ce63
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Sep 16, 2024
5f64be3
add uptime tracking to VM
ceyonur Sep 16, 2024
6ff4954
remove unused param
ceyonur Sep 16, 2024
55927b2
add wg for update validators
ceyonur Sep 16, 2024
92fba2e
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Sep 16, 2024
bdc2cc3
update state before network shutdown
ceyonur Sep 16, 2024
657e542
restart bootstrapping status in test
ceyonur Sep 16, 2024
9d6d40e
Merge branch 'uptime-tracking' of https://github.com/ava-labs/subnet-…
ceyonur Sep 16, 2024
9eaa3f3
add get validator to state
ceyonur Sep 17, 2024
66747f8
rename uptime to validator
ceyonur Sep 17, 2024
86a68c8
fix mock state
ceyonur Sep 17, 2024
f43bae2
tests
ceyonur Sep 18, 2024
92f6b7e
Update plugin/evm/validators/state.go
ceyonur Sep 19, 2024
0db2041
use update enum
ceyonur Sep 19, 2024
c5520bc
Update plugin/evm/validators/state.go
ceyonur Sep 19, 2024
dea94af
Update plugin/evm/validators/state.go
ceyonur Sep 19, 2024
c0f6ff4
respond to comments
ceyonur Sep 19, 2024
b7de0f6
Merge branch 'validator-state' of https://github.com/ava-labs/subnet-…
ceyonur Sep 19, 2024
b566103
update avalanchego dep branch
ceyonur Sep 19, 2024
66ab74b
update avalanchego dep branch
ceyonur Sep 19, 2024
ad3a35a
reviews
ceyonur Sep 19, 2024
64fe238
reword errs
ceyonur Sep 19, 2024
33d24d1
Merge branch 'pausable-uptime-manager' of https://github.com/ava-labs…
ceyonur Sep 19, 2024
d7338da
fix test changes
ceyonur Sep 19, 2024
8eab611
Merge branch 'master' into uptime-tracking-base
ceyonur Sep 19, 2024
9ad5528
fix upgrades after deactivating latest in context
ceyonur Sep 19, 2024
4536590
Merge branch 'uptime-tracking-base' into validator-state
ceyonur Sep 19, 2024
fc71949
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Sep 19, 2024
4304ac5
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Sep 19, 2024
3225a32
use test branch from avalanchego
ceyonur Sep 20, 2024
df6ad02
use branch commit for ava version
ceyonur Sep 20, 2024
738003f
update e2e ava version
ceyonur Sep 20, 2024
29a501d
update avago dep
ceyonur Sep 20, 2024
71c7de0
remove extra line...
ceyonur Sep 20, 2024
cc6ce95
Merge branch 'master' into uptime-tracking-base
ceyonur Sep 20, 2024
bcd4c9c
Merge branch 'uptime-tracking-base' into validator-state
ceyonur Sep 20, 2024
a49dd8d
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Sep 20, 2024
27884f4
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Sep 20, 2024
b9d6336
export struct
ceyonur Sep 26, 2024
734b201
Merge branch 'master' into validator-state
ceyonur Oct 28, 2024
3e94861
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Oct 28, 2024
cab1ddf
reviews
ceyonur Oct 29, 2024
d1a0ae8
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Oct 29, 2024
5f8bf5b
conflict fix
ceyonur Oct 29, 2024
0ba2869
custom err msg
ceyonur Oct 29, 2024
374d885
add listener mock
ceyonur Oct 29, 2024
1fcca58
Merge branch 'master' into validator-state
ceyonur Oct 29, 2024
c41f39c
Merge branch 'validator-state' into pausable-uptime-manager
ceyonur Oct 29, 2024
f828d53
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Oct 29, 2024
9e707ad
bump avago test branch
ceyonur Oct 29, 2024
cc73266
remove config
ceyonur Oct 29, 2024
8ef763f
remove api changes
ceyonur Oct 29, 2024
2a9da82
Revert "remove api changes"
ceyonur Oct 29, 2024
9a50ee8
use non-version db for validatorsDB
ceyonur Oct 29, 2024
58b9c35
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Oct 29, 2024
af39b2c
remove errs from resume and pause
ceyonur Oct 30, 2024
d5d3545
check after stopping
ceyonur Oct 30, 2024
6fffc2b
use expectedTime in tests
ceyonur Oct 31, 2024
4625f7c
reviews
ceyonur Oct 31, 2024
e1975cf
Update plugin/evm/vm.go
ceyonur Oct 31, 2024
74bd249
fix len
ceyonur Oct 31, 2024
e5ab9f2
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Oct 31, 2024
7c33221
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Oct 31, 2024
733da4c
Merge branch 'master' into pausable-uptime-manager
ceyonur Nov 5, 2024
347055c
Merge branch 'pausable-uptime-manager' into uptime-tracking
ceyonur Nov 5, 2024
335d8bc
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 5, 2024
2aebfe6
remove log
ceyonur Nov 5, 2024
25076c3
disable validators api by default
ceyonur Nov 5, 2024
d737c11
Merge branch 'master' into uptime-tracking
ceyonur Nov 5, 2024
6468d36
use interfaces from pkgs
ceyonur Nov 5, 2024
10c4bd4
improve comments
ceyonur Nov 6, 2024
9490aae
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 6, 2024
fd462c5
Merge branch 'uptime-tracking-api' of https://github.com/ava-labs/sub…
ceyonur Nov 6, 2024
5974170
new fields and refactorings
ceyonur Nov 8, 2024
0388e84
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 8, 2024
7dca70e
add new fields
ceyonur Nov 8, 2024
48ef70f
Merge branch 'master' into uptime-tracking
ceyonur Nov 8, 2024
424e7a7
fix linter
ceyonur Nov 8, 2024
4fa19b9
clarify comments
ceyonur Nov 8, 2024
4559ab9
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 8, 2024
3d5261d
update comment
ceyonur Nov 8, 2024
a80c028
bump to poc branch
ceyonur Nov 9, 2024
a417614
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 9, 2024
c39c7e0
enable validators API by default
ceyonur Nov 12, 2024
15886c1
reviews
ceyonur Nov 13, 2024
bf9b962
Merge branch 'master' into uptime-tracking
ceyonur Nov 13, 2024
ebaaefc
update comment
ceyonur Nov 13, 2024
3283e36
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 13, 2024
a943b6f
update to avago master
ceyonur Nov 13, 2024
a8abbc3
Merge branch 'uptime-tracking' into uptime-tracking-api
ceyonur Nov 13, 2024
09c4401
Merge branch 'master' into uptime-tracking-api
ceyonur Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions plugin/evm/api.go
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
}
11 changes: 7 additions & 4 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
defaultStateSyncMinBlocks = 300_000
defaultStateSyncRequestSize = 1024 // the number of key/values to ask peers for per request
defaultDBType = pebbledb.Name
defaultValidatorAPIEnabled = true
)

type PBool bool
Expand Down Expand Up @@ -91,10 +92,11 @@ type Config struct {
AirdropFile string `json:"airdrop"`

// Subnet EVM APIs
SnowmanAPIEnabled bool `json:"snowman-api-enabled"`
AdminAPIEnabled bool `json:"admin-api-enabled"`
AdminAPIDir string `json:"admin-api-dir"`
WarpAPIEnabled bool `json:"warp-api-enabled"`
SnowmanAPIEnabled bool `json:"snowman-api-enabled"`
ValidatorsAPIEnabled bool `json:"validators-api-enabled"`
AdminAPIEnabled bool `json:"admin-api-enabled"`
AdminAPIDir string `json:"admin-api-dir"`
WarpAPIEnabled bool `json:"warp-api-enabled"`

// EnabledEthAPIs is a list of Ethereum services that should be enabled
// If none is specified, then we use the default list [defaultEnabledAPIs]
Expand Down Expand Up @@ -297,6 +299,7 @@ func (c *Config) SetDefaults() {
c.AllowUnprotectedTxHashes = defaultAllowUnprotectedTxHashes
c.AcceptedCacheSize = defaultAcceptedCacheSize
c.DatabaseType = defaultDBType
c.ValidatorsAPIEnabled = defaultValidatorAPIEnabled
}

func (d *Duration) UnmarshalJSON(data []byte) (err error) {
Expand Down
75 changes: 53 additions & 22 deletions plugin/evm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,66 @@
package evm

import (
"context"
"math/big"
"net/http"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ava-labs/avalanchego/ids"
)

// SnowmanAPI introduces snowman specific functionality to the evm
type SnowmanAPI struct{ vm *VM }
type ValidatorsAPI struct {
vm *VM
}

type GetCurrentValidatorsRequest struct {
NodeIDs []ids.NodeID `json:"nodeIDs"`
}

// 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"`
type GetCurrentValidatorsResponse struct {
Validators []CurrentValidator `json:"validators"`
}

// 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
type CurrentValidator struct {
ValidationID ids.ID `json:"validationID"`
NodeID ids.NodeID `json:"nodeID"`
Weight uint64 `json:"weight"`
StartTime time.Time `json:"startTime"`
IsActive bool `json:"isActive"`
IsSoV bool `json:"isSoV"`
IsConnected bool `json:"isConnected"`
Uptime time.Duration `json:"uptime"`
}

// IssueBlock to the chain
func (api *SnowmanAPI) IssueBlock(ctx context.Context) error {
log.Info("Issuing a new block")
api.vm.builder.signalTxsReady()
func (api *ValidatorsAPI) GetCurrentValidators(_ *http.Request, _ *struct{}, reply *GetCurrentValidatorsResponse) error {
api.vm.ctx.Lock.RLock()
defer api.vm.ctx.Lock.RUnlock()

vIDs := api.vm.validatorState.GetValidationIDs()

reply.Validators = make([]CurrentValidator, 0, vIDs.Len())

for _, vID := range vIDs.List() {
validator, err := api.vm.validatorState.GetValidator(vID)
if err != nil {
return err
}

isConnected := api.vm.uptimeManager.IsConnected(validator.NodeID)

uptime, _, err := api.vm.uptimeManager.CalculateUptime(validator.NodeID)
if err != nil {
return err
}

reply.Validators = append(reply.Validators, CurrentValidator{
ValidationID: validator.ValidationID,
NodeID: validator.NodeID,
StartTime: validator.StartTime(),
Weight: validator.Weight,
IsActive: validator.IsActive,
IsSoV: validator.IsSoV,
IsConnected: isConnected,
Uptime: time.Duration(uptime.Seconds()),
})
}
return nil
}
11 changes: 11 additions & 0 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const (
adminEndpoint = "/admin"
ethRPCEndpoint = "/rpc"
ethWSEndpoint = "/ws"
validatorsEndpoint = "/validators"
ethTxGossipNamespace = "eth_tx_gossip"
)

Expand Down Expand Up @@ -1087,6 +1088,16 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error) {
enabledAPIs = append(enabledAPIs, "subnet-evm-admin")
}

if vm.config.ValidatorsAPIEnabled {
validatorsAPI, err := newHandler("validators", &ValidatorsAPI{vm})
if err != nil {
return nil, fmt.Errorf("failed to register service for validators API due to %w", err)
}
apis[validatorsEndpoint] = validatorsAPI
enabledAPIs = append(enabledAPIs, "validators")
}

// RPC APIs
if vm.config.SnowmanAPIEnabled {
if err := handler.RegisterName("snowman", &SnowmanAPI{vm}); err != nil {
return nil, err
Expand Down
Loading