Fixed memory leak and deadcode. (#4539)

pull/4544/head
Konstantin 1 year ago committed by GitHub
parent 163365625c
commit da863bf04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      consensus/consensus.go
  2. 8
      consensus/consensus_service.go
  3. 8
      consensus/consensus_v2.go
  4. 31
      consensus/downloader.go

@ -296,7 +296,7 @@ func New(
// viewID has to be initialized as the height of // viewID has to be initialized as the height of
// the blockchain during initialization as it was // the blockchain during initialization as it was
// displayed on explorer as Height right now // displayed on explorer as Height right now
consensus.SetCurBlockViewID(0) consensus.setCurBlockViewID(0)
consensus.SlashChan = make(chan slash.Record) consensus.SlashChan = make(chan slash.Record)
consensus.readySignal = make(chan ProposalType) consensus.readySignal = make(chan ProposalType)
consensus.commitSigChannel = make(chan []byte) consensus.commitSigChannel = make(chan []byte)

@ -514,12 +514,14 @@ func (consensus *Consensus) setViewIDs(height uint64) {
// SetCurBlockViewID set the current view ID // SetCurBlockViewID set the current view ID
func (consensus *Consensus) SetCurBlockViewID(viewID uint64) uint64 { func (consensus *Consensus) SetCurBlockViewID(viewID uint64) uint64 {
return consensus.current.SetCurBlockViewID(viewID) consensus.mutex.Lock()
defer consensus.mutex.Unlock()
return consensus.setCurBlockViewID(viewID)
} }
// SetCurBlockViewID set the current view ID // SetCurBlockViewID set the current view ID
func (consensus *Consensus) setCurBlockViewID(viewID uint64) { func (consensus *Consensus) setCurBlockViewID(viewID uint64) uint64 {
consensus.current.SetCurBlockViewID(viewID) return consensus.current.SetCurBlockViewID(viewID)
} }
// SetViewChangingID set the current view change ID // SetViewChangingID set the current view change ID

@ -323,9 +323,7 @@ func (consensus *Consensus) Start(
consensus.mutex.Unlock() consensus.mutex.Unlock()
}() }()
if consensus.dHelper != nil { consensus.dHelper.start()
consensus.dHelper.start()
}
} }
func (consensus *Consensus) StartChannel() { func (consensus *Consensus) StartChannel() {
@ -448,10 +446,6 @@ func (consensus *Consensus) BlockChannel(newBlock *types.Block) {
Msg("[ConsensusMainLoop] STARTING CONSENSUS") Msg("[ConsensusMainLoop] STARTING CONSENSUS")
consensus.announce(newBlock) consensus.announce(newBlock)
}) })
if consensus.dHelper != nil {
consensus.dHelper.start()
}
} }
// LastMileBlockIter is the iterator to iterate over the last mile blocks in consensus cache. // LastMileBlockIter is the iterator to iterate over the last mile blocks in consensus cache.

@ -39,7 +39,7 @@ func newDownloadHelper(c *Consensus, d downloader) *downloadHelper {
finishedCh := make(chan struct{}, 1) finishedCh := make(chan struct{}, 1)
finishedSub := d.SubscribeDownloadFinished(finishedCh) finishedSub := d.SubscribeDownloadFinished(finishedCh)
return &downloadHelper{ out := &downloadHelper{
c: c, c: c,
d: d, d: d,
startedCh: startedCh, startedCh: startedCh,
@ -47,16 +47,12 @@ func newDownloadHelper(c *Consensus, d downloader) *downloadHelper {
startedSub: startedSub, startedSub: startedSub,
finishedSub: finishedSub, finishedSub: finishedSub,
} }
go out.downloadStartedLoop()
go out.downloadFinishedLoop()
return out
} }
func (dh *downloadHelper) start() { func (dh *downloadHelper) start() {
go dh.downloadStartedLoop()
go dh.downloadFinishedLoop()
}
func (dh *downloadHelper) close() {
dh.startedSub.Unsubscribe()
dh.finishedSub.Unsubscribe()
} }
func (dh *downloadHelper) downloadStartedLoop() { func (dh *downloadHelper) downloadStartedLoop() {
@ -107,21 +103,10 @@ func (consensus *Consensus) AddConsensusLastMile() error {
} }
func (consensus *Consensus) spinUpStateSync() { func (consensus *Consensus) spinUpStateSync() {
if consensus.dHelper != nil { consensus.dHelper.d.DownloadAsync()
consensus.dHelper.d.DownloadAsync() consensus.current.SetMode(Syncing)
consensus.current.SetMode(Syncing) for _, v := range consensus.consensusTimeout {
for _, v := range consensus.consensusTimeout { v.Stop()
v.Stop()
}
} else {
select {
case consensus.BlockNumLowChan <- struct{}{}:
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
default:
}
} }
} }

Loading…
Cancel
Save