Skip to content

Commit

Permalink
Merge pull request #5554 from filecoin-project/feat/uptime
Browse files Browse the repository at this point in the history
feat: Add node uptime rpc
  • Loading branch information
diwufeiwen authored Dec 9, 2022
2 parents dfbc433 + ceb743d commit 35df6cd
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/submodule/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ type CommonModule struct { // nolint
chainModule *chain2.ChainSubmodule
netModule *network.NetworkSubmodule
blockDelaySecs uint64
start time.Time
}

func NewCommonModule(chainModule *chain2.ChainSubmodule, netModule *network.NetworkSubmodule, blockDelaySecs uint64) *CommonModule {
return &CommonModule{
chainModule: chainModule,
netModule: netModule,
blockDelaySecs: blockDelaySecs,
start: time.Now(),
}
}

Expand Down Expand Up @@ -113,6 +115,10 @@ func (cm *CommonModule) NodeStatus(ctx context.Context, inclChainStatus bool) (s
return status, nil
}

func (cm *CommonModule) StartTime(ctx context.Context) (time.Time, error) {
return cm.start, nil
}

func (cm *CommonModule) API() v1api.ICommon {
return cm
}
Expand Down
19 changes: 13 additions & 6 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ var infoCmd = &cmds.Command{
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
ctx := req.Context
chainapi := env.(*node.Env).ChainAPI
chainAPI := env.(*node.Env).ChainAPI
commonAPI := env.(*node.Env).CommonAPI
buf := new(bytes.Buffer)
writer := NewSilentWriter(buf)

netParams, err := chainapi.StateGetNetworkParams(ctx)
netParams, err := chainAPI.StateGetNetworkParams(ctx)
if err != nil {
return err
}
writer.Printf("Network: %s\n", netParams.NetworkName)

if err := SyncBasefeeCheck(ctx, chainapi, int64(netParams.BlockDelaySecs), writer); err != nil {
start, err := commonAPI.StartTime(ctx)
if err != nil {
return err
}
writer.Printf("StartTime: %s (started at %s)\n", time.Since(start).Truncate(time.Second), start.Truncate(time.Second))

if err := SyncBasefeeCheck(ctx, chainAPI, int64(netParams.BlockDelaySecs), writer); err != nil {
return err
}
status, err := env.(*node.Env).CommonAPI.NodeStatus(ctx, true)
status, err := commonAPI.NodeStatus(ctx, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -117,8 +124,8 @@ var infoCmd = &cmds.Command{
},
}

func SyncBasefeeCheck(ctx context.Context, chainapi v1.IChain, blockDelaySecs int64, writer *SilentWriter) error {
head, err := chainapi.ChainHead(ctx)
func SyncBasefeeCheck(ctx context.Context, chainAPI v1.IChain, blockDelaySecs int64, writer *SilentWriter) error {
head, err := chainAPI.ChainHead(ctx)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion venus-shared/api/chain/v0/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package v0

import "github.com/filecoin-project/venus/venus-shared/api"
import (
"context"
"time"

"github.com/filecoin-project/venus/venus-shared/api"
)

type ICommon interface {
api.Version
// StartTime returns node start time
StartTime(context.Context) (time.Time, error) //perm:read
}
11 changes: 11 additions & 0 deletions venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* [StateWaitMsgLimited](#statewaitmsglimited)
* [VerifyEntry](#verifyentry)
* [Common](#common)
* [StartTime](#starttime)
* [Version](#version)
* [Market](#market)
* [StateMarketParticipants](#statemarketparticipants)
Expand Down Expand Up @@ -1829,6 +1830,16 @@ Response: `true`

## Common

### StartTime
StartTime returns node start time


Perms: read

Inputs: `[]`

Response: `"0001-01-01T00:00:00Z"`

### Version
Version provides information about API provider

Expand Down
15 changes: 15 additions & 0 deletions venus-shared/api/chain/v0/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion venus-shared/api/chain/v0/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions venus-shared/api/chain/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1

import (
"context"
"time"

"github.com/filecoin-project/venus/venus-shared/api"
"github.com/filecoin-project/venus/venus-shared/types"
Expand All @@ -11,4 +12,6 @@ type ICommon interface {
api.Version

NodeStatus(ctx context.Context, inclChainStatus bool) (types.NodeStatus, error) //perm:read
// StartTime returns node start time
StartTime(context.Context) (time.Time, error) //perm:read
}
11 changes: 11 additions & 0 deletions venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* [VerifyEntry](#verifyentry)
* [Common](#common)
* [NodeStatus](#nodestatus)
* [StartTime](#starttime)
* [Version](#version)
* [Market](#market)
* [StateMarketParticipants](#statemarketparticipants)
Expand Down Expand Up @@ -1836,6 +1837,16 @@ Response:
}
```

### StartTime
StartTime returns node start time


Perms: read

Inputs: `[]`

Response: `"0001-01-01T00:00:00Z"`

### Version
Version provides information about API provider

Expand Down
15 changes: 15 additions & 0 deletions venus-shared/api/chain/v1/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions venus-shared/api/chain/v1/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c
+ SetConcurrent
+ SetPassword
- Shutdown
+ StartTime
- StateAllMinerFaults
- StateChangedActors
- StateCompute
Expand Down Expand Up @@ -197,6 +198,7 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
+ SetConcurrent
+ SetPassword
- Shutdown
+ StartTime
- StateCompute
> StateGetNetworkParams {[func(context.Context) (*types.NetworkParams, error) <> func(context.Context) (*api.NetworkParams, error)] base=func out type: #0 input; nested={[*types.NetworkParams <> *api.NetworkParams] base=pointed type; nested={[types.NetworkParams <> api.NetworkParams] base=struct field; nested={[types.NetworkParams <> api.NetworkParams] base=exported field type: #5 field named ForkUpgradeParams; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=struct field; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=exported fields count: 21 != 22; nested=nil}}}}}}
+ StateMinerSectorSize
Expand Down
2 changes: 2 additions & 0 deletions venus-shared/compatible-checks/api-perm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v0: github.com/filecoin-project/venus/venus-shared/api/chain/v0 <> github.com/fi
- IChainInfo.VerifyEntry
- IMinerState.StateMinerSectorSize
- IMinerState.StateMinerWorkerAddress
- ICommon.StartTime
- ICommon.Version
- IMessagePool.GasBatchEstimateMessageGas
- IMessagePool.MpoolDeleteByAdress
Expand Down Expand Up @@ -68,6 +69,7 @@ v1: github.com/filecoin-project/venus/venus-shared/api/chain/v1 <> github.com/fi
- IChainInfo.VerifyEntry
- IMinerState.StateMinerSectorSize
- IMinerState.StateMinerWorkerAddress
- ICommon.StartTime
- IMessagePool.GasBatchEstimateMessageGas
- IMessagePool.MpoolDeleteByAdress
- IMessagePool.MpoolPublishByAddr
Expand Down

0 comments on commit 35df6cd

Please sign in to comment.