From f4e6b05fc665ccd116cfa944523b3ff424f8b3d2 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 15 Nov 2024 00:46:57 +0300 Subject: [PATCH] Use startimestamp (#1386) * fix start timestamp * add client --- plugin/evm/client.go | 25 +++++++++++++++++-------- plugin/evm/service.go | 36 ++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/plugin/evm/client.go b/plugin/evm/client.go index b91618fc4c..f87507da56 100644 --- a/plugin/evm/client.go +++ b/plugin/evm/client.go @@ -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...) } @@ -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 +} diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 3b6959ee59..1a7b285bfe 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -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"` + IsSoV bool `json:"isSoV"` + IsConnected bool `json:"isConnected"` + Uptime time.Duration `json:"uptime"` } func (api *ValidatorsAPI) GetCurrentValidators(_ *http.Request, _ *struct{}, reply *GetCurrentValidatorsResponse) error { @@ -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, + IsSoV: validator.IsSoV, + IsConnected: isConnected, + Uptime: time.Duration(uptime.Seconds()), }) } return nil