Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed memory leak and deadcode. #4539

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func New(
// viewID has to be initialized as the height of
// the blockchain during initialization as it was
// displayed on explorer as Height right now
consensus.SetCurBlockViewID(0)
consensus.setCurBlockViewID(0)
consensus.SlashChan = make(chan slash.Record)
consensus.readySignal = make(chan ProposalType)
consensus.commitSigChannel = make(chan []byte)
Expand Down
8 changes: 5 additions & 3 deletions consensus/consensus_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,14 @@ func (consensus *Consensus) setViewIDs(height uint64) {

// SetCurBlockViewID set the current view ID
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
func (consensus *Consensus) setCurBlockViewID(viewID uint64) {
consensus.current.SetCurBlockViewID(viewID)
func (consensus *Consensus) setCurBlockViewID(viewID uint64) uint64 {
return consensus.current.SetCurBlockViewID(viewID)
}

// SetViewChangingID set the current view change ID
Expand Down
8 changes: 1 addition & 7 deletions consensus/consensus_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ func (consensus *Consensus) Start(
consensus.mutex.Unlock()
}()

if consensus.dHelper != nil {
consensus.dHelper.start()
}
consensus.dHelper.start()
}

func (consensus *Consensus) StartChannel() {
Expand Down Expand Up @@ -448,10 +446,6 @@ func (consensus *Consensus) BlockChannel(newBlock *types.Block) {
Msg("[ConsensusMainLoop] STARTING CONSENSUS")
consensus.announce(newBlock)
})

if consensus.dHelper != nil {
consensus.dHelper.start()
}
}

// LastMileBlockIter is the iterator to iterate over the last mile blocks in consensus cache.
Expand Down
31 changes: 8 additions & 23 deletions consensus/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,20 @@ func newDownloadHelper(c *Consensus, d downloader) *downloadHelper {
finishedCh := make(chan struct{}, 1)
finishedSub := d.SubscribeDownloadFinished(finishedCh)

return &downloadHelper{
out := &downloadHelper{
c: c,
d: d,
startedCh: startedCh,
finishedCh: finishedCh,
startedSub: startedSub,
finishedSub: finishedSub,
}
go out.downloadStartedLoop()
go out.downloadFinishedLoop()
return out
}

func (dh *downloadHelper) start() {
go dh.downloadStartedLoop()
go dh.downloadFinishedLoop()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function start initiates an internal loop and awaits the occurrence of close, which never happens.

}

func (dh *downloadHelper) close() {
dh.startedSub.Unsubscribe()
dh.finishedSub.Unsubscribe()
}

func (dh *downloadHelper) downloadStartedLoop() {
Expand Down Expand Up @@ -107,21 +103,10 @@ func (consensus *Consensus) AddConsensusLastMile() error {
}

func (consensus *Consensus) spinUpStateSync() {
if consensus.dHelper != nil {
consensus.dHelper.d.DownloadAsync()
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
} else {
select {
case consensus.BlockNumLowChan <- struct{}{}:
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
default:
}
consensus.dHelper.d.DownloadAsync()
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
}

Expand Down