From 128f015a8d57392a7f4af5e1ffc1bd29f9392d70 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Tue, 28 May 2024 12:25:09 +0200 Subject: [PATCH] add lock to purgeMilestoneIDsList (#10524) Cherry pick PR #10493 into the release branch Co-authored-by: Mark Holt <135143369+mh0lt@users.noreply.github.com> --- polygon/bor/finality/whitelist/milestone.go | 7 +++++++ polygon/bor/finality/whitelist/service_test.go | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/polygon/bor/finality/whitelist/milestone.go b/polygon/bor/finality/whitelist/milestone.go index b4777c13cae..a79c712358e 100644 --- a/polygon/bor/finality/whitelist/milestone.go +++ b/polygon/bor/finality/whitelist/milestone.go @@ -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) @@ -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{}) } diff --git a/polygon/bor/finality/whitelist/service_test.go b/polygon/bor/finality/whitelist/service_test.go index 62fe3651dea..4e0de45b663 100644 --- a/polygon/bor/finality/whitelist/service_test.go +++ b/polygon/bor/finality/whitelist/service_test.go @@ -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 (