gitlab.com/gpdionisio/tendermint@v0.34.19-dev2/rpc/core/status.go (about) 1 package core 2 3 import ( 4 "time" 5 6 tmbytes "github.com/tendermint/tendermint/libs/bytes" 7 "github.com/tendermint/tendermint/p2p" 8 ctypes "github.com/tendermint/tendermint/rpc/core/types" 9 rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" 10 "github.com/tendermint/tendermint/types" 11 ) 12 13 // Status returns Tendermint status including node info, pubkey, latest block 14 // hash, app hash, block height and time. 15 // More: https://docs.tendermint.com/master/rpc/#/Info/status 16 func 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 := validatorAtHeight(latestUncommittedHeight()); val != nil { 51 votingPower = val.VotingPower 52 } 53 54 result := &ctypes.ResultStatus{ 55 NodeInfo: env.P2PTransport.NodeInfo().(p2p.DefaultNodeInfo), 56 SyncInfo: ctypes.SyncInfo{ 57 LatestBlockHash: latestBlockHash, 58 LatestAppHash: latestAppHash, 59 LatestBlockHeight: latestHeight, 60 LatestBlockTime: time.Unix(0, latestBlockTimeNano), 61 EarliestBlockHash: earliestBlockHash, 62 EarliestAppHash: earliestAppHash, 63 EarliestBlockHeight: earliestBlockHeight, 64 EarliestBlockTime: time.Unix(0, earliestBlockTimeNano), 65 CatchingUp: env.ConsensusReactor.WaitSync(), 66 }, 67 ValidatorInfo: ctypes.ValidatorInfo{ 68 Address: env.PubKey.Address(), 69 PubKey: env.PubKey, 70 VotingPower: votingPower, 71 }, 72 } 73 74 return result, nil 75 } 76 77 func validatorAtHeight(h int64) *types.Validator { 78 vals, err := env.StateStore.LoadValidators(h) 79 if err != nil { 80 return nil 81 } 82 privValAddress := env.PubKey.Address() 83 _, val := vals.GetByAddress(privValAddress) 84 return val 85 }