diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 882e761b0..2f39bf4cf 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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) diff --git a/internal/blockchain/v0/reactor.go b/internal/blockchain/v0/reactor.go index 17074e040..859b0fe97 100644 --- a/internal/blockchain/v0/reactor.go +++ b/internal/blockchain/v0/reactor.go @@ -589,3 +589,7 @@ FOR_LOOP: } } } + +func (r *Reactor) GetMaxPeerBlockHeight() int64 { + return r.pool.MaxPeerHeight() +} diff --git a/internal/blockchain/v2/reactor.go b/internal/blockchain/v2/reactor.go index 3773bc49a..861b3033d 100644 --- a/internal/blockchain/v2/reactor.go +++ b/internal/blockchain/v2/reactor.go @@ -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 +} diff --git a/internal/consensus/reactor.go b/internal/consensus/reactor.go index 6bac1a1d1..eb2868f7e 100644 --- a/internal/consensus/reactor.go +++ b/internal/consensus/reactor.go @@ -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 diff --git a/node/node.go b/node/node.go index 66255f069..2bd668a59 100644 --- a/node/node.go +++ b/node/node.go @@ -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...") diff --git a/rpc/client/mock/status_test.go b/rpc/client/mock/status_test.go index 4c2112b9c..2a7474aa6 100644 --- a/rpc/client/mock/status_test.go +++ b/rpc/client/mock/status_test.go @@ -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) } diff --git a/rpc/core/env.go b/rpc/core/env.go index 3152ee882..ff4ccbdc8 100644 --- a/rpc/core/env.go +++ b/rpc/core/env.go @@ -81,6 +81,7 @@ type Environment struct { ConsensusReactor *consensus.Reactor EventBus *types.EventBus // thread safe Mempool mempl.Mempool + FastSyncReactor consensus.FastSyncReactor Logger log.Logger diff --git a/rpc/core/status.go b/rpc/core/status.go index c6407b390..24424a5cf 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -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, diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index c69b520f0..8a2b1a899 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -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"` } diff --git a/rpc/openapi/openapi.yaml b/rpc/openapi/openapi.yaml index 32e516b22..9e1200bc6 100644 --- a/rpc/openapi/openapi.yaml +++ b/rpc/openapi/openapi.yaml @@ -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