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 #140 from binance-chain/hotstatus
Browse files Browse the repository at this point in the history
[R4R]fix hot sync not a catched up status
  • Loading branch information
unclezoro authored Jul 13, 2020
2 parents 5613ebd + 6bbcfbb commit 3951961
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type consensusReactor interface {
// for when we switch from blockchain reactor and fast sync to
// the consensus machine
SwitchToConsensus(sm.State, int)
SwitchToCatchUp()
}

type hotsyncReactor interface {
Expand Down Expand Up @@ -303,6 +304,10 @@ FOR_LOOP:
hotR, ok := bcR.Switch.Reactor("HOT").(hotsyncReactor)
if ok {
hotR.SwitchToHotSync(state, int32(blocksSynced))
conR, ok := bcR.Switch.Reactor("CONSENSUS").(consensusReactor)
if ok {
conR.SwitchToCatchUp()
}
} else {
// should only happen during testing
}
Expand Down
5 changes: 5 additions & 0 deletions blockchain/v1/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type consensusReactor interface {
// for when we switch from blockchain reactor and fast sync to
// the consensus machine
SwitchToConsensus(sm.State, int)
SwitchToCatchUp()
}

// BlockchainReactor handles long-term catchup syncing.
Expand Down Expand Up @@ -496,6 +497,10 @@ func (bcR *BlockchainReactor) switchToConsensusOrHotSync() {
hotR, ok := bcR.Switch.Reactor("HOT").(hotsyncReactor)
if ok {
hotR.SwitchToHotSync(bcR.state, int32(bcR.blocksSynced))
conR, ok := bcR.Switch.Reactor("CONSENSUS").(consensusReactor)
if ok {
conR.SwitchToCatchUp()
}
} else {
// should only happen during testing
}
Expand Down
7 changes: 7 additions & 0 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (conR *ConsensusReactor) OnStop() {
}
}

func (conR *ConsensusReactor) SwitchToCatchUp() {
conR.mtx.Lock()
conR.fastSync = false
conR.mtx.Unlock()
conR.metrics.FastSyncing.Set(0)
}

// SwitchToConsensus switches from fast_sync mode to consensus mode.
// It resets the state, turns off fast_sync, and starts the consensus state-machine
func (conR *ConsensusReactor) SwitchToConsensus(state sm.State, blocksSynced int) {
Expand Down

0 comments on commit 3951961

Please sign in to comment.