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 3 commits
Commits
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
25 changes: 17 additions & 8 deletions plugin/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@ type Client interface {
LockProfile(ctx context.Context, options ...rpc.Option) error
SetLogLevel(ctx context.Context, level slog.Level, options ...rpc.Option) error
GetVMConfig(ctx context.Context, options ...rpc.Option) (*Config, error)
GetCurrentValidators(ctx context.Context, options ...rpc.Option) ([]CurrentValidator, error)
}

// Client implementation for interacting with EVM [chain]
type client struct {
adminRequester rpc.EndpointRequester
adminRequester rpc.EndpointRequester
validatorsRequester rpc.EndpointRequester
}

// NewClient returns a Client for interacting with EVM [chain]
func NewClient(uri, chain string) Client {
requestUri := fmt.Sprintf("%s/ext/bc/%s", uri, chain)
return &client{
adminRequester: rpc.NewEndpointRequester(fmt.Sprintf("%s/ext/bc/%s/admin", uri, chain)),
adminRequester: rpc.NewEndpointRequester(
requestUri + "/admin",
),
validatorsRequester: rpc.NewEndpointRequester(
requestUri + "/validators",
),
}
}

// NewCChainClient returns a Client for interacting with the C Chain
func NewCChainClient(uri string) Client {
// TODO: Update for Subnet-EVM compatibility
return NewClient(uri, "C")
}

func (c *client) StartCPUProfiler(ctx context.Context, options ...rpc.Option) error {
return c.adminRequester.SendRequest(ctx, "admin.startCPUProfiler", struct{}{}, &api.EmptyReply{}, options...)
}
Expand Down Expand Up @@ -73,3 +75,10 @@ func (c *client) GetVMConfig(ctx context.Context, options ...rpc.Option) (*Confi
err := c.adminRequester.SendRequest(ctx, "admin.getVMConfig", struct{}{}, res, options...)
return res.Config, err
}

// GetCurrentValidators returns the current validators
func (c *client) GetCurrentValidators(ctx context.Context, options ...rpc.Option) ([]CurrentValidator, error) {
res := &GetCurrentValidatorsResponse{}
err := c.validatorsRequester.SendRequest(ctx, "validators.getCurrentValidators", struct{}{}, res, options...)
return res.Validators, err
}
36 changes: 16 additions & 20 deletions plugin/evm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ type ValidatorsAPI struct {
vm *VM
}

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

type GetCurrentValidatorsResponse struct {
Validators []CurrentValidator `json:"validators"`
}

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"`
ValidationID ids.ID `json:"validationID"`
NodeID ids.NodeID `json:"nodeID"`
Weight uint64 `json:"weight"`
StartTimestamp uint64 `json:"startTimestamp"`
IsActive bool `json:"isActive"`
IsL1Validator bool `json:"isL1Validator"`
IsConnected bool `json:"isConnected"`
Uptime time.Duration `json:"uptime"`
}

func (api *ValidatorsAPI) GetCurrentValidators(_ *http.Request, _ *struct{}, reply *GetCurrentValidatorsResponse) error {
Expand All @@ -55,14 +51,14 @@ func (api *ValidatorsAPI) GetCurrentValidators(_ *http.Request, _ *struct{}, rep
}

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()),
ValidationID: validator.ValidationID,
NodeID: validator.NodeID,
StartTimestamp: validator.StartTimestamp,
Weight: validator.Weight,
IsActive: validator.IsActive,
IsL1Validator: validator.IsL1Validator,
IsConnected: isConnected,
Uptime: time.Duration(uptime.Seconds()),
})
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/validators/interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Validator struct {
Weight uint64 `json:"weight"`
StartTimestamp uint64 `json:"startTimestamp"`
IsActive bool `json:"isActive"`
IsSoV bool `json:"isSoV"`
IsL1Validator bool `json:"isL1Validator"`
}

func (v *Validator) StartTime() time.Time { return time.Unix(int64(v.StartTimestamp), 0) }
34 changes: 17 additions & 17 deletions plugin/evm/validators/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const (
)

type validatorData struct {
UpDuration time.Duration `serialize:"true"`
LastUpdated uint64 `serialize:"true"`
NodeID ids.NodeID `serialize:"true"`
Weight uint64 `serialize:"true"`
StartTime uint64 `serialize:"true"`
IsActive bool `serialize:"true"`
IsSoV bool `serialize:"true"`
UpDuration time.Duration `serialize:"true"`
LastUpdated uint64 `serialize:"true"`
NodeID ids.NodeID `serialize:"true"`
Weight uint64 `serialize:"true"`
StartTime uint64 `serialize:"true"`
IsActive bool `serialize:"true"`
IsL1Validator bool `serialize:"true"`

validationID ids.ID // database key
}
Expand Down Expand Up @@ -105,14 +105,14 @@ func (s *state) GetStartTime(nodeID ids.NodeID) (time.Time, error) {
// the new validator is marked as updated and will be written to the disk when WriteState is called
func (s *state) AddValidator(vdr interfaces.Validator) error {
data := &validatorData{
NodeID: vdr.NodeID,
validationID: vdr.ValidationID,
IsActive: vdr.IsActive,
StartTime: vdr.StartTimestamp,
UpDuration: 0,
LastUpdated: vdr.StartTimestamp,
IsSoV: vdr.IsSoV,
Weight: vdr.Weight,
NodeID: vdr.NodeID,
validationID: vdr.ValidationID,
IsActive: vdr.IsActive,
StartTime: vdr.StartTimestamp,
UpDuration: 0,
LastUpdated: vdr.StartTimestamp,
IsL1Validator: vdr.IsL1Validator,
Weight: vdr.Weight,
}
if err := s.addData(vdr.ValidationID, data); err != nil {
return err
Expand Down Expand Up @@ -251,7 +251,7 @@ func (s *state) GetValidator(vID ids.ID) (interfaces.Validator, error) {
StartTimestamp: data.StartTime,
IsActive: data.IsActive,
Weight: data.Weight,
IsSoV: data.IsSoV,
IsL1Validator: data.IsL1Validator,
}, nil
}

Expand Down Expand Up @@ -345,6 +345,6 @@ func (v *validatorData) getStartTime() time.Time {
func (v *validatorData) constantsAreUnmodified(u interfaces.Validator) bool {
return v.validationID == u.ValidationID &&
v.NodeID == u.NodeID &&
v.IsSoV == u.IsSoV &&
v.IsL1Validator == u.IsL1Validator &&
v.StartTime == u.StartTimestamp
}
56 changes: 28 additions & 28 deletions plugin/evm/validators/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestState(t *testing.T) {
Weight: 1,
StartTimestamp: uint64(startTime.Unix()),
IsActive: true,
IsSoV: true,
IsL1Validator: true,
}
state.AddValidator(vdr)

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestState(t *testing.T) {
require.ErrorIs(state.UpdateValidator(vdr), ErrImmutableField)

// set SoV should fail
vdr.IsSoV = false
vdr.IsL1Validator = false
require.ErrorIs(state.UpdateValidator(vdr), ErrImmutableField)

// set validation ID should result in not found
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestWriteValidator(t *testing.T) {
Weight: 1,
StartTimestamp: uint64(startTime.Unix()),
IsActive: true,
IsSoV: true,
IsL1Validator: true,
}))

// write state, should reflect to DB
Expand Down Expand Up @@ -177,29 +177,29 @@ func TestParseValidator(t *testing.T) {
name: "nil",
bytes: nil,
expected: &validatorData{
LastUpdated: 0,
StartTime: 0,
validationID: ids.Empty,
NodeID: ids.EmptyNodeID,
UpDuration: 0,
Weight: 0,
IsActive: false,
IsSoV: false,
LastUpdated: 0,
StartTime: 0,
validationID: ids.Empty,
NodeID: ids.EmptyNodeID,
UpDuration: 0,
Weight: 0,
IsActive: false,
IsL1Validator: false,
},
expectedErr: nil,
},
{
name: "empty",
bytes: []byte{},
expected: &validatorData{
LastUpdated: 0,
StartTime: 0,
validationID: ids.Empty,
NodeID: ids.EmptyNodeID,
UpDuration: 0,
Weight: 0,
IsActive: false,
IsSoV: false,
LastUpdated: 0,
StartTime: 0,
validationID: ids.Empty,
NodeID: ids.EmptyNodeID,
UpDuration: 0,
Weight: 0,
IsActive: false,
IsL1Validator: false,
},
expectedErr: nil,
},
Expand All @@ -226,13 +226,13 @@ func TestParseValidator(t *testing.T) {
0x01,
},
expected: &validatorData{
UpDuration: time.Duration(6000000),
LastUpdated: 900000,
NodeID: testNodeID,
StartTime: 6000000,
IsActive: true,
Weight: 1,
IsSoV: true,
UpDuration: time.Duration(6000000),
LastUpdated: 900000,
NodeID: testNodeID,
StartTime: 6000000,
IsActive: true,
Weight: 1,
IsL1Validator: true,
},
},
{
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestStateListener(t *testing.T) {
Weight: 1,
StartTimestamp: uint64(initialStartTime.Unix()),
IsActive: true,
IsSoV: true,
IsL1Validator: true,
}))

// register listener
Expand All @@ -315,7 +315,7 @@ func TestStateListener(t *testing.T) {
Weight: 1,
StartTimestamp: uint64(expectedStartTime.Unix()),
IsActive: true,
IsSoV: true,
IsL1Validator: true,
}
require.NoError(state.AddValidator(vdr))

Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ func loadValidators(validatorState validatorsinterfaces.State, newValidators map
Weight: newVdr.Weight,
StartTimestamp: newVdr.StartTime,
IsActive: newVdr.IsActive,
IsSoV: newVdr.IsSoV,
IsL1Validator: newVdr.IsSoV,
}
if currentValidationIDs.Contains(newVID) {
if err := validatorState.UpdateValidator(currentVdr); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/vm_validators_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestLoadNewValidators(t *testing.T) {
Weight: validator.Weight,
StartTimestamp: validator.StartTime,
IsActive: validator.IsActive,
IsSoV: validator.IsSoV,
IsL1Validator: validator.IsSoV,
})
require.NoError(err)
}
Expand All @@ -356,7 +356,7 @@ func TestLoadNewValidators(t *testing.T) {
require.Equal(validator.Weight, v.Weight)
require.Equal(validator.StartTime, v.StartTimestamp)
require.Equal(validator.IsActive, v.IsActive)
require.Equal(validator.IsSoV, v.IsSoV)
require.Equal(validator.IsSoV, v.IsL1Validator)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion warp/verifier_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func TestUptimeSignatures(t *testing.T) {
Weight: 1,
StartTimestamp: clk.Unix(),
IsActive: true,
IsSoV: true,
IsL1Validator: true,
}))
protoBytes, _ = getUptimeMessageBytes([]byte{}, validationID, 80)
_, appErr = handler.AppRequest(context.Background(), nodeID, time.Time{}, protoBytes)
Expand Down