Skip to content

Commit

Permalink
Use startimestamp (#1386)
Browse files Browse the repository at this point in the history
* fix start timestamp

* add client
  • Loading branch information
ceyonur authored Nov 14, 2024
1 parent f1d549c commit f4e6b05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
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"`
IsSoV bool `json:"isSoV"`
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,
IsSoV: validator.IsSoV,
IsConnected: isConnected,
Uptime: time.Duration(uptime.Seconds()),
})
}
return nil
Expand Down

0 comments on commit f4e6b05

Please sign in to comment.