mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
116 lines
3.8 KiB
Go
116 lines
3.8 KiB
Go
package core
|
|
|
|
import (
|
|
"bytes"
|
|
"time"
|
|
|
|
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
|
"github.com/tendermint/tendermint/rpc/coretypes"
|
|
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// Status returns Tendermint status including node info, pubkey, latest block
|
|
// hash, app hash, block height, current max peer block height, and time.
|
|
// More: https://docs.tendermint.com/master/rpc/#/Info/status
|
|
func (env *Environment) Status(ctx *rpctypes.Context) (*coretypes.ResultStatus, error) {
|
|
var (
|
|
earliestBlockHeight int64
|
|
earliestBlockHash tmbytes.HexBytes
|
|
earliestAppHash tmbytes.HexBytes
|
|
earliestBlockTimeNano int64
|
|
)
|
|
|
|
if earliestBlockMeta := env.BlockStore.LoadBaseMeta(); earliestBlockMeta != nil {
|
|
earliestBlockHeight = earliestBlockMeta.Header.Height
|
|
earliestAppHash = earliestBlockMeta.Header.AppHash
|
|
earliestBlockHash = earliestBlockMeta.BlockID.Hash
|
|
earliestBlockTimeNano = earliestBlockMeta.Header.Time.UnixNano()
|
|
}
|
|
|
|
var (
|
|
latestBlockHash tmbytes.HexBytes
|
|
latestAppHash tmbytes.HexBytes
|
|
latestBlockTimeNano int64
|
|
|
|
latestHeight = env.BlockStore.Height()
|
|
)
|
|
|
|
if latestHeight != 0 {
|
|
if latestBlockMeta := env.BlockStore.LoadBlockMeta(latestHeight); latestBlockMeta != nil {
|
|
latestBlockHash = latestBlockMeta.BlockID.Hash
|
|
latestAppHash = latestBlockMeta.Header.AppHash
|
|
latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano()
|
|
}
|
|
}
|
|
|
|
// Return the very last voting power, not the voting power of this validator
|
|
// during the last block.
|
|
var votingPower int64
|
|
if val := env.validatorAtHeight(env.latestUncommittedHeight()); val != nil {
|
|
votingPower = val.VotingPower
|
|
}
|
|
validatorInfo := coretypes.ValidatorInfo{}
|
|
if env.PubKey != nil {
|
|
validatorInfo = coretypes.ValidatorInfo{
|
|
Address: env.PubKey.Address(),
|
|
PubKey: env.PubKey,
|
|
VotingPower: votingPower,
|
|
}
|
|
}
|
|
result := &coretypes.ResultStatus{
|
|
NodeInfo: env.P2PTransport.NodeInfo(),
|
|
SyncInfo: coretypes.SyncInfo{
|
|
LatestBlockHash: latestBlockHash,
|
|
LatestAppHash: latestAppHash,
|
|
LatestBlockHeight: latestHeight,
|
|
LatestBlockTime: time.Unix(0, latestBlockTimeNano),
|
|
EarliestBlockHash: earliestBlockHash,
|
|
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(),
|
|
},
|
|
ValidatorInfo: validatorInfo,
|
|
}
|
|
|
|
if env.StateSyncMetricer != nil {
|
|
result.SyncInfo.TotalSnapshots = env.StateSyncMetricer.TotalSnapshots()
|
|
result.SyncInfo.ChunkProcessAvgTime = env.StateSyncMetricer.ChunkProcessAvgTime()
|
|
result.SyncInfo.SnapshotHeight = env.StateSyncMetricer.SnapshotHeight()
|
|
result.SyncInfo.SnapshotChunksCount = env.StateSyncMetricer.SnapshotChunksCount()
|
|
result.SyncInfo.SnapshotChunksTotal = env.StateSyncMetricer.SnapshotChunksTotal()
|
|
result.SyncInfo.BackFilledBlocks = env.StateSyncMetricer.BackFilledBlocks()
|
|
result.SyncInfo.BackFillBlocksTotal = env.StateSyncMetricer.BackFillBlocksTotal()
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func (env *Environment) validatorAtHeight(h int64) *types.Validator {
|
|
valsWithH, err := env.StateStore.LoadValidators(h)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
if env.PubKey == nil {
|
|
return nil
|
|
}
|
|
privValAddress := env.PubKey.Address()
|
|
|
|
// If we're still at height h, search in the current validator set.
|
|
lastBlockHeight, vals := env.ConsensusState.GetValidators()
|
|
if lastBlockHeight == h {
|
|
for _, val := range vals {
|
|
if bytes.Equal(val.Address, privValAddress) {
|
|
return val
|
|
}
|
|
}
|
|
}
|
|
|
|
_, val := valsWithH.GetByAddress(privValAddress)
|
|
return val
|
|
}
|