github.com/number571/tendermint@v0.34.11-gost/rpc/core/status.go (about) 1 package core 2 3 import ( 4 "bytes" 5 "time" 6 7 tmbytes "github.com/number571/tendermint/libs/bytes" 8 ctypes "github.com/number571/tendermint/rpc/core/types" 9 rpctypes "github.com/number571/tendermint/rpc/jsonrpc/types" 10 "github.com/number571/tendermint/types" 11 ) 12 13 // Status returns Tendermint status including node info, pubkey, latest block 14 // hash, app hash, block height, current max peer block height, and time. 15 // More: https://docs.tendermint.com/master/rpc/#/Info/status 16 func (env *Environment) Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { 17 var ( 18 earliestBlockHeight int64 19 earliestBlockHash tmbytes.HexBytes 20 earliestAppHash tmbytes.HexBytes 21 earliestBlockTimeNano int64 22 ) 23 24 if earliestBlockMeta := env.BlockStore.LoadBaseMeta(); earliestBlockMeta != nil { 25 earliestBlockHeight = earliestBlockMeta.Header.Height 26 earliestAppHash = earliestBlockMeta.Header.AppHash 27 earliestBlockHash = earliestBlockMeta.BlockID.Hash 28 earliestBlockTimeNano = earliestBlockMeta.Header.Time.UnixNano() 29 } 30 31 var ( 32 latestBlockHash tmbytes.HexBytes 33 latestAppHash tmbytes.HexBytes 34 latestBlockTimeNano int64 35 36 latestHeight = env.BlockStore.Height() 37 ) 38 39 if latestHeight != 0 { 40 if latestBlockMeta := env.BlockStore.LoadBlockMeta(latestHeight); latestBlockMeta != nil { 41 latestBlockHash = latestBlockMeta.BlockID.Hash 42 latestAppHash = latestBlockMeta.Header.AppHash 43 latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano() 44 } 45 } 46 47 // Return the very last voting power, not the voting power of this validator 48 // during the last block. 49 var votingPower int64 50 if val := env.validatorAtHeight(env.latestUncommittedHeight()); val != nil { 51 votingPower = val.VotingPower 52 } 53 validatorInfo := ctypes.ValidatorInfo{} 54 if env.PubKey != nil { 55 validatorInfo = ctypes.ValidatorInfo{ 56 Address: env.PubKey.Address(), 57 PubKey: env.PubKey, 58 VotingPower: votingPower, 59 } 60 } 61 result := &ctypes.ResultStatus{ 62 NodeInfo: env.P2PTransport.NodeInfo(), 63 SyncInfo: ctypes.SyncInfo{ 64 LatestBlockHash: latestBlockHash, 65 LatestAppHash: latestAppHash, 66 LatestBlockHeight: latestHeight, 67 LatestBlockTime: time.Unix(0, latestBlockTimeNano), 68 EarliestBlockHash: earliestBlockHash, 69 EarliestAppHash: earliestAppHash, 70 EarliestBlockHeight: earliestBlockHeight, 71 EarliestBlockTime: time.Unix(0, earliestBlockTimeNano), 72 MaxPeerBlockHeight: env.FastSyncReactor.GetMaxPeerBlockHeight(), 73 CatchingUp: env.ConsensusReactor.WaitSync(), 74 TotalSyncedTime: env.FastSyncReactor.GetTotalSyncedTime(), 75 RemainingTime: env.FastSyncReactor.GetRemainingSyncTime(), 76 }, 77 ValidatorInfo: validatorInfo, 78 } 79 80 return result, nil 81 } 82 83 func (env *Environment) validatorAtHeight(h int64) *types.Validator { 84 valsWithH, err := env.StateStore.LoadValidators(h) 85 if err != nil { 86 return nil 87 } 88 if env.PubKey == nil { 89 return nil 90 } 91 privValAddress := env.PubKey.Address() 92 93 // If we're still at height h, search in the current validator set. 94 lastBlockHeight, vals := env.ConsensusState.GetValidators() 95 if lastBlockHeight == h { 96 for _, val := range vals { 97 if bytes.Equal(val.Address, privValAddress) { 98 return val 99 } 100 } 101 } 102 103 _, val := valsWithH.GetByAddress(privValAddress) 104 return val 105 }