Browse Source

rpc: add max peer block height into /status rpc call (#6610)

use  `maxPeerBlockHeight` information to show the current network's best height.

Closes #3983
Relate to #3365

ref: the`highestBlock` in the response of `eth.isSyncing` call
https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html#issyncing
pull/6609/head
JayT106 3 years ago
committed by GitHub
parent
commit
2cc872543b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 14 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +4
    -0
      internal/blockchain/v0/reactor.go
  3. +6
    -0
      internal/blockchain/v2/reactor.go
  4. +8
    -0
      internal/consensus/reactor.go
  5. +4
    -9
      node/node.go
  6. +6
    -3
      rpc/client/mock/status_test.go
  7. +1
    -0
      rpc/core/env.go
  8. +2
    -1
      rpc/core/status.go
  9. +2
    -0
      rpc/core/types/responses.go
  10. +4
    -1
      rpc/openapi/openapi.yaml

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -19,6 +19,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [state/indexer] \#6382 reconstruct indexer, move txindex into the indexer package (@JayT106)
- [cli] \#6372 Introduce `BootstrapPeers` as part of the new p2p stack. Peers to be connected on startup (@cmwaters)
- [config] \#6462 Move `PrivValidator` configuration out of `BaseConfig` into its own section. (@tychoish)
- [rpc] \#6610 Add MaxPeerBlockHeight into /status rpc call (@JayT106)
- Apps
- [ABCI] \#6408 Change the `key` and `value` fields from `[]byte` to `string` in the `EventAttribute` type. (@alexanderbez)


+ 4
- 0
internal/blockchain/v0/reactor.go View File

@ -589,3 +589,7 @@ FOR_LOOP:
}
}
}
func (r *Reactor) GetMaxPeerBlockHeight() int64 {
return r.pool.MaxPeerHeight()
}

+ 6
- 0
internal/blockchain/v2/reactor.go View File

@ -590,3 +590,9 @@ func (r *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor {
},
}
}
func (r *BlockchainReactor) GetMaxPeerBlockHeight() int64 {
r.mtx.RLock()
defer r.mtx.RUnlock()
return r.maxPeerHeight
}

+ 8
- 0
internal/consensus/reactor.go View File

@ -98,6 +98,14 @@ const (
type ReactorOption func(*Reactor)
// Temporary interface for switching to fast sync, we should get rid of v0.
// See: https://github.com/tendermint/tendermint/issues/4595
type FastSyncReactor interface {
SwitchToFastSync(sm.State) error
GetMaxPeerBlockHeight() int64
}
// Reactor defines a reactor for the consensus service.
type Reactor struct {
service.BaseService


+ 4
- 9
node/node.go View File

@ -560,12 +560,6 @@ func makeSeedNode(config *cfg.Config,
return node, nil
}
// Temporary interface for switching to fast sync, we should get rid of v0.
// See: https://github.com/tendermint/tendermint/issues/4595
type fastSyncReactor interface {
SwitchToFastSync(sm.State) error
}
// OnStart starts the Node. It implements service.Service.
func (n *nodeImpl) OnStart() error {
now := tmtime.Now()
@ -658,7 +652,7 @@ func (n *nodeImpl) OnStart() error {
// Run state sync
if n.stateSync {
bcR, ok := n.bcReactor.(fastSyncReactor)
bcR, ok := n.bcReactor.(cs.FastSyncReactor)
if !ok {
return fmt.Errorf("this blockchain reactor does not support switching from state sync")
}
@ -787,7 +781,8 @@ func (n *nodeImpl) ConfigureRPC() (*rpccore.Environment, error) {
Logger: n.Logger.With("module", "rpc"),
Config: *n.config.RPC,
Config: *n.config.RPC,
FastSyncReactor: n.bcReactor.(cs.FastSyncReactor),
}
if n.config.Mode == cfg.ModeValidator {
pubKey, err := n.privValidator.GetPubKey(context.TODO())
@ -1032,7 +1027,7 @@ func (n *nodeImpl) NodeInfo() p2p.NodeInfo {
}
// startStateSync starts an asynchronous state sync process, then switches to fast sync mode.
func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor,
func startStateSync(ssR *statesync.Reactor, bcR cs.FastSyncReactor, conR *cs.Reactor,
stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool,
stateStore sm.Store, blockStore *store.BlockStore, state sm.State) error {
ssR.Logger.Info("starting state sync...")


+ 6
- 3
rpc/client/mock/status_test.go View File

@ -19,9 +19,10 @@ func TestStatus(t *testing.T) {
Call: mock.Call{
Response: &ctypes.ResultStatus{
SyncInfo: ctypes.SyncInfo{
LatestBlockHash: bytes.HexBytes("block"),
LatestAppHash: bytes.HexBytes("app"),
LatestBlockHeight: 10,
LatestBlockHash: bytes.HexBytes("block"),
LatestAppHash: bytes.HexBytes("app"),
LatestBlockHeight: 10,
MaxPeerBlockHeight: 20,
},
}},
}
@ -34,6 +35,7 @@ func TestStatus(t *testing.T) {
require.Nil(err, "%+v", err)
assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
assert.EqualValues(20, status.SyncInfo.MaxPeerBlockHeight)
// make sure recorder works properly
require.Equal(1, len(r.Calls))
@ -46,4 +48,5 @@ func TestStatus(t *testing.T) {
require.True(ok)
assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
assert.EqualValues(20, st.SyncInfo.MaxPeerBlockHeight)
}

+ 1
- 0
rpc/core/env.go View File

@ -81,6 +81,7 @@ type Environment struct {
ConsensusReactor *consensus.Reactor
EventBus *types.EventBus // thread safe
Mempool mempl.Mempool
FastSyncReactor consensus.FastSyncReactor
Logger log.Logger


+ 2
- 1
rpc/core/status.go View File

@ -11,7 +11,7 @@ import (
)
// Status returns Tendermint status including node info, pubkey, latest block
// hash, app hash, block height and time.
// 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) (*ctypes.ResultStatus, error) {
var (
@ -69,6 +69,7 @@ func (env *Environment) Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, err
EarliestAppHash: earliestAppHash,
EarliestBlockHeight: earliestBlockHeight,
EarliestBlockTime: time.Unix(0, earliestBlockTimeNano),
MaxPeerBlockHeight: env.FastSyncReactor.GetMaxPeerBlockHeight(),
CatchingUp: env.ConsensusReactor.WaitSync(),
},
ValidatorInfo: validatorInfo,


+ 2
- 0
rpc/core/types/responses.go View File

@ -94,6 +94,8 @@ type SyncInfo struct {
EarliestBlockHeight int64 `json:"earliest_block_height"`
EarliestBlockTime time.Time `json:"earliest_block_time"`
MaxPeerBlockHeight int64 `json:"max_peer_block_height"`
CatchingUp bool `json:"catching_up"`
}


+ 4
- 1
rpc/openapi/openapi.yaml View File

@ -484,7 +484,7 @@ paths:
tags:
- Info
description: |
Get Tendermint status including node info, pubkey, latest block hash, app hash, block height and time.
Get Tendermint status including node info, pubkey, latest block hash, app hash, block height, current max peer height, and time.
responses:
"200":
description: Status of the node
@ -1324,6 +1324,9 @@ components:
earliest_block_time:
type: string
example: "2019-08-01T11:52:22.818762194Z"
max_peer_block_height:
type: string
example: "1262196"
catching_up:
type: boolean
example: false


Loading…
Cancel
Save