Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #159 from binance-chain/develop
Browse files Browse the repository at this point in the history
[R4R] Prepare for release v0.32.3-binance.4
  • Loading branch information
unclezoro authored Jan 8, 2021
2 parents 40a8c51 + b528fd0 commit 298320b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## v0.32.3-binance.4
- [sync] [\#157](https://github.com/binance-chain/bnc-tendermint/pull/157) fix goroutine/memory leak under hotsync when receive consensus message
- [api] [\#148](https://github.com/binance-chain/bnc-tendermint/pull/148) fix `validators` api does now show correct height issue

## v0.32.3-binance.3
- [sync] [\#147](https://github.com/binance-chain/bnc-tendermint/pull/147) fix not panic when do not have block under state sync
Expand Down
2 changes: 1 addition & 1 deletion consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestByzantine(t *testing.T) {
blocksSubs[i], err = eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock)
require.NoError(t, err)

conR := NewConsensusReactor(css[i], true) // so we don't start the consensus states
conR := NewConsensusReactor(css[i], true, false) // so we don't start the consensus states
conR.SetLogger(logger.With("validator", i))
conR.SetEventBus(eventBus)

Expand Down
24 changes: 17 additions & 7 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ConsensusReactor struct {
conS *ConsensusState

mtx sync.RWMutex
hotSync bool
fastSync bool
eventBus *types.EventBus

Expand All @@ -51,10 +52,11 @@ type ReactorOption func(*ConsensusReactor)

// NewConsensusReactor returns a new ConsensusReactor with the given
// consensusState.
func NewConsensusReactor(consensusState *ConsensusState, fastSync bool, options ...ReactorOption) *ConsensusReactor {
func NewConsensusReactor(consensusState *ConsensusState, fastSync bool, hotSync bool, options ...ReactorOption) *ConsensusReactor {
conR := &ConsensusReactor{
conS: consensusState,
fastSync: fastSync,
hotSync: hotSync,
metrics: NopMetrics(),
}
conR.updateFastSyncingMetric()
Expand Down Expand Up @@ -115,6 +117,7 @@ func (conR *ConsensusReactor) SwitchToConsensus(state sm.State, blocksSynced int

conR.mtx.Lock()
conR.fastSync = false
conR.hotSync = false
conR.mtx.Unlock()
conR.metrics.FastSyncing.Set(0)

Expand Down Expand Up @@ -290,8 +293,8 @@ func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
}

case DataChannel:
if conR.FastSync() {
conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
if conR.FastSync() || conR.HotSync() {
conR.Logger.Info("Ignoring message received during fastSync/hotsync", "msg", msg)
return
}
switch msg := msg.(type) {
Expand All @@ -310,8 +313,8 @@ func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
}

case VoteChannel:
if conR.FastSync() {
conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
if conR.FastSync() || conR.HotSync() {
conR.Logger.Info("Ignoring message received during fastSync/hotSync", "msg", msg)
return
}
switch msg := msg.(type) {
Expand All @@ -332,8 +335,8 @@ func (conR *ConsensusReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
}

case VoteSetBitsChannel:
if conR.FastSync() {
conR.Logger.Info("Ignoring message received during fastSync", "msg", msg)
if conR.FastSync() || conR.HotSync() {
conR.Logger.Info("Ignoring message received during fastSync/hotSync", "msg", msg)
return
}
switch msg := msg.(type) {
Expand Down Expand Up @@ -380,6 +383,13 @@ func (conR *ConsensusReactor) FastSync() bool {
return conR.fastSync
}

// HotSync returns whether the consensus reactor is in hot-sync mode.
func (conR *ConsensusReactor) HotSync() bool {
conR.mtx.RLock()
defer conR.mtx.RUnlock()
return conR.hotSync
}

//--------------------------------------

// subscribeToBroadcastEvents subscribes for new round steps and votes
Expand Down
4 changes: 2 additions & 2 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/tendermint/tendermint/abci/example/kvstore"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
dbm "github.com/tendermint/tendermint/libs/db"
cstypes "github.com/tendermint/tendermint/consensus/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p"
Expand All @@ -44,7 +44,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, n int) (
for i := 0; i < n; i++ {
/*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info")
if err != nil { t.Fatal(err)}*/
reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states
reactors[i] = NewConsensusReactor(css[i], true, false) // so we dont start the consensus states
reactors[i].SetLogger(css[i].Logger)

// eventBus is already started with the cs
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func createConsensusReactor(config *cfg.Config,
if privValidator != nil {
consensusState.SetPrivValidator(privValidator)
}
consensusReactor := cs.NewConsensusReactor(consensusState, fastSync || (config.StateSyncHeight >= 0) || config.HotSync, cs.ReactorMetrics(csMetrics))
consensusReactor := cs.NewConsensusReactor(consensusState, fastSync || (config.StateSyncHeight >= 0) || config.HotSync, config.HotSync, cs.ReactorMetrics(csMetrics))
consensusReactor.SetLogger(consensusLogger)
// services which will be publishing and/or subscribing for messages (events)
// consensusReactor will set it on consensusState and blockExecutor
Expand Down
3 changes: 3 additions & 0 deletions rpc/core/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultValidato
// The latest validator that we know is the
// NextValidator of the last block.
height := consensusState.GetState().LastBlockHeight + 1
if hotSync {
height = blockStore.Height()
}
height, err := getHeight(height, heightPtr)
if err != nil {
return nil, err
Expand Down

0 comments on commit 298320b

Please sign in to comment.