rpc: add more nil checks in the status end point (#8287)

This commit is contained in:
Sam Kleinman
2022-04-08 14:04:43 -04:00
committed by GitHub
parent 90b951af72
commit 3e3a934818
+18 -4
View File
@@ -77,14 +77,25 @@ func (env *Environment) Status(ctx context.Context) (*coretypes.ResultStatus, er
EarliestAppHash: earliestAppHash,
EarliestBlockHeight: earliestBlockHeight,
EarliestBlockTime: time.Unix(0, earliestBlockTimeNano),
MaxPeerBlockHeight: env.BlockSyncReactor.GetMaxPeerBlockHeight(),
CatchingUp: env.ConsensusReactor.WaitSync(),
TotalSyncedTime: env.BlockSyncReactor.GetTotalSyncedTime(),
RemainingTime: env.BlockSyncReactor.GetRemainingSyncTime(),
// this should start as true, if consensus
// hasn't started yet, and then flip to false
// (or true,) depending on what's actually
// happening.
CatchingUp: true,
},
ValidatorInfo: validatorInfo,
}
if env.ConsensusReactor != nil {
result.SyncInfo.CatchingUp = env.ConsensusReactor.WaitSync()
}
if env.BlockSyncReactor != nil {
result.SyncInfo.MaxPeerBlockHeight = env.BlockSyncReactor.GetMaxPeerBlockHeight()
result.SyncInfo.TotalSyncedTime = env.BlockSyncReactor.GetTotalSyncedTime()
result.SyncInfo.RemainingTime = env.BlockSyncReactor.GetRemainingSyncTime()
}
if env.StateSyncMetricer != nil {
result.SyncInfo.TotalSnapshots = env.StateSyncMetricer.TotalSnapshots()
result.SyncInfo.ChunkProcessAvgTime = env.StateSyncMetricer.ChunkProcessAvgTime()
@@ -103,6 +114,9 @@ func (env *Environment) validatorAtHeight(h int64) *types.Validator {
if err != nil {
return nil
}
if env.ConsensusState == nil {
return nil
}
if env.PubKey == nil {
return nil
}