From 0ec22a86f319c88ac2ddc2520bcee7b7ac38c60a Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 15 Jul 2024 15:25:22 +0700 Subject: [PATCH] bor: finality race - step 2 (#11151) ``` ================== WARNING: DATA RACE Write at 0x00c015bf2208 by goroutine 110: github.com/ledgerwatch/erigon/polygon/bor/finality/whitelist.(*milestone).RemoveMilestoneID() /home/ubuntu/erigon/polygon/bor/finality/whitelist/milestone.go:190 +0x164 github.com/ledgerwatch/erigon/polygon/bor/finality.handleNoAckMilestone() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:237 +0x12c github.com/ledgerwatch/erigon/polygon/bor/finality.retryHeimdallHandler() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:159 +0x5c4 github.com/ledgerwatch/erigon/polygon/bor/finality.RetryHeimdallHandler() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:117 +0x57 github.com/ledgerwatch/erigon/polygon/bor/finality.startNoAckMilestoneService() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:102 +0x2a github.com/ledgerwatch/erigon/polygon/bor/finality.Whitelist.gowrap3() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:65 +0x17 Previous read at 0x00c015bf2208 by goroutine 109: github.com/ledgerwatch/erigon/polygon/bor/finality/whitelist.(*milestone).ProcessFutureMilestone() /home/ubuntu/erigon/polygon/bor/finality/whitelist/milestone.go:277 +0x166 github.com/ledgerwatch/erigon/polygon/bor/finality.handleMilestone() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:208 +0x1e5 github.com/ledgerwatch/erigon/polygon/bor/finality.retryHeimdallHandler() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:159 +0x5c4 github.com/ledgerwatch/erigon/polygon/bor/finality.RetryHeimdallHandler() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:117 +0x5c github.com/ledgerwatch/erigon/polygon/bor/finality.startMilestoneWhitelistService() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:93 +0x2a github.com/ledgerwatch/erigon/polygon/bor/finality.Whitelist.gowrap2() /home/ubuntu/erigon/polygon/bor/finality/whitelist.go:64 +0x17 ``` --- polygon/bor/finality/whitelist/milestone.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/polygon/bor/finality/whitelist/milestone.go b/polygon/bor/finality/whitelist/milestone.go index 05f135ee63c..c42242e0510 100644 --- a/polygon/bor/finality/whitelist/milestone.go +++ b/polygon/bor/finality/whitelist/milestone.go @@ -168,6 +168,10 @@ func (m *milestone) UnlockSprint(endBlockNum uint64) { return } + if m.finality.TryLock() { + defer m.finality.Unlock() + } + m.Locked = false m.purgeMilestoneIDsList() @@ -263,6 +267,9 @@ func (m *milestone) IsFutureMilestoneCompatible(chain []*types.Header) bool { } func (m *milestone) ProcessFutureMilestone(num uint64, hash common.Hash) { + m.finality.Lock() + defer m.finality.Unlock() + if len(m.FutureMilestoneOrder) < m.MaxCapacity { m.enqueueFutureMilestone(num, hash) }