Skip to content

Commit

Permalink
pacemaker revertTo also cleans up pendingList and reset p.lastVotingH…
Browse files Browse the repository at this point in the history
…eight to be consistent with leaf
  • Loading branch information
simonzg committed Apr 18, 2023
1 parent 3806020 commit 585583e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions consensus/pacemaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,11 @@ func (p *Pacemaker) revertTo(revertHeight uint32) {
p.QCHigh = pivotJustify
}
}

p.pendingList.CleanFrom(revertHeight)
if p.blockLeaf != nil {
p.lastVotingHeight = p.blockLeaf.Height
}
// First senario : pivot height < b-leaf height
// pivot b-leaf b-leaf
// v v v
Expand Down Expand Up @@ -1508,8 +1513,8 @@ func (p *Pacemaker) OnReceiveQueryProposal(mi *consensusMsgInfo) error {
result := p.proposalMap.Get(queryHeight)
if result == nil {
// Oooop!, I do not have it
p.logger.Error("I dont have the specific proposal", "height", queryHeight, "round", queryRound)
return fmt.Errorf("I dont have the specific proposal on height %v", queryHeight)
p.logger.Error("dont have the specific proposal", "height", queryHeight, "round", queryRound)
return fmt.Errorf("dont have the specific proposal on height %v", queryHeight)
}

if result.ProposalMessage == nil {
Expand Down
14 changes: 13 additions & 1 deletion consensus/pending_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ func (p *PendingList) CleanUpTo(height uint32) {
return
}

for key, _ := range p.messages {
for key := range p.messages {
if key <= height {
delete(p.messages, key)
}
}
p.lowest = height
}

func (p *PendingList) CleanFrom(height uint32) {
if height <= p.lowest {
p.CleanAll()
return
}
for key := range p.messages {
if key >= height {
delete(p.messages, key)
}
}
}

// clean all the pending messages
func (p *PendingList) CleanAll() {
for key := range p.messages {
Expand Down

0 comments on commit 585583e

Please sign in to comment.