Skip to content

Commit

Permalink
add lock to purgeMilestoneIDsList (#10524)
Browse files Browse the repository at this point in the history
Cherry pick PR #10493 into the release branch

Co-authored-by: Mark Holt <[email protected]>
  • Loading branch information
yperbasis and mh0lt authored May 28, 2024
1 parent 9501f93 commit 128f015
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 7 additions & 0 deletions polygon/bor/finality/whitelist/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (m *milestone) UnlockSprint(endBlockNum uint64) {
}

m.Locked = false

m.purgeMilestoneIDsList()

err := rawdb.WriteLockField(m.db, m.Locked, m.LockedMilestoneNumber, m.LockedMilestoneHash, m.LockedMilestoneIDs)
Expand Down Expand Up @@ -213,6 +214,12 @@ func (m *milestone) GetMilestoneIDsList() []string {

// This is remove the milestoneIDs stored in the list.
func (m *milestone) purgeMilestoneIDsList() {
// try is used here as the finality lock is preserved over calls - so the lock state
// is not clearly defined in the local code - this likely needs to be revised
if m.finality.TryLock() {
defer m.finality.Unlock()
}

m.LockedMilestoneIDs = make(map[string]struct{})
}

Expand Down
6 changes: 1 addition & 5 deletions polygon/bor/finality/whitelist/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,7 @@ func TestPropertyBasedTestingMilestone(t *testing.T) {
}

fitlerFn := func(i uint64) bool {
if i <= uint64(1000) {
return true
}

return false
return i <= uint64(1000)
}

var (
Expand Down

0 comments on commit 128f015

Please sign in to comment.