From ac786a74b0669193fcdcc30c17e9a0b1511bbee7 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 4 Aug 2024 14:31:44 +0800 Subject: [PATCH] Support RPC GetDeploymentsInfo --- rpc/client.go | 12 ++++++++++++ types/stats.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/rpc/client.go b/rpc/client.go index d1dc1338..a67b3e3c 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -186,6 +186,9 @@ type Client interface { //GetCellsCapacity returns the live cells capacity by the lock or type script. GetCellsCapacity(ctx context.Context, searchKey *indexer.SearchKey) (*indexer.Capacity, error) + // GetDeploymentsInfo returns statistics about the chain. + GetDeploymentsInfo(ctx context.Context) (*types.DeploymentsInfo, error) + // Close close client Close() @@ -764,6 +767,15 @@ func (cli *client) GetCellsCapacity(ctx context.Context, searchKey *indexer.Sear return &result, nil } +func (cli *Client) GetDeploymentsInfo(ctx context.Context) (*types.DeploymentsInfo, error) { + var result types.DeploymentsInfo + err := cli.c.CallContext(ctx, &result, "get_deployments_info") + if err != nil { + return nil, err + } + return &result, nil +} + func (cli *client) GetCells(ctx context.Context, searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error) { var ( result indexer.LiveCells diff --git a/types/stats.go b/types/stats.go index e688ea44..b5748e9c 100644 --- a/types/stats.go +++ b/types/stats.go @@ -17,3 +17,48 @@ type BlockchainInfo struct { IsInitialBlockDownload bool `json:"is_initial_block_download"` MedianTime uint64 `json:"median_time"` } + +// DeploymentState represents the possible states of a deployment. +type DeploymentState int + +const ( + // Defined is the first state that each softfork starts. + Defined DeploymentState = iota + // Started is the state for epochs past the `start` epoch. + Started + // LockedIn is the state for epochs after the first epoch period with STARTED epochs of which at least `threshold` has the associated bit set in `version`. + LockedIn + // Active is the state for all epochs after the LOCKED_IN epoch. + Active + // Failed is the state for epochs past the `timeout_epoch`, if LOCKED_IN was not reached. + Failed +) + +// DeploymentPos represents the possible positions for deployments. +type DeploymentPos int + +const ( + // Testdummy represents a dummy deployment. + Testdummy DeploymentPos = iota + // LightClient represents the light client protocol deployment. + LightClient +) + +// DeploymentInfo represents information about a deployment. +type DeploymentInfo struct { + Bit uint8 + Start uint64 + Timeout uint64 + MinActivationEpoch uint64 + Period uint64 + Threshold RationalU256 + Since uint64 + State DeploymentState +} + +// DeploymentsInfo represents information about multiple deployments. +type DeploymentsInfo struct { + Hash Hash + Epoch uint64 + Deployments map[DeploymentPos]DeploymentInfo +}