Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use startimestamp #1386

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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"`
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
Loading