mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
Fix initialization race (#12374)
* block all the sync startup code on init signal * don't need chainStarted if everything blocks * set empty clock by default to work around panics * remove unused clock, zero-value for init-sync --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
parent
98f8ca4e34
commit
7d9f36985e
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/db"
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/db"
|
||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p"
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p"
|
||||||
p2pTypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types"
|
p2pTypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/types"
|
||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/startup"
|
|
||||||
prysmsync "github.com/prysmaticlabs/prysm/v4/beacon-chain/sync"
|
prysmsync "github.com/prysmaticlabs/prysm/v4/beacon-chain/sync"
|
||||||
"github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags"
|
"github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags"
|
||||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||||
@ -87,7 +86,6 @@ type blocksFetcher struct {
|
|||||||
capacityWeight float64 // how remaining capacity affects peer selection
|
capacityWeight float64 // how remaining capacity affects peer selection
|
||||||
mode syncMode // allows to use fetcher in different sync scenarios
|
mode syncMode // allows to use fetcher in different sync scenarios
|
||||||
quit chan struct{} // termination notifier
|
quit chan struct{} // termination notifier
|
||||||
clock *startup.Clock
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// peerLock restricts fetcher actions on per peer basis. Currently, used for rate limiting.
|
// peerLock restricts fetcher actions on per peer basis. Currently, used for rate limiting.
|
||||||
|
@ -552,7 +552,6 @@ func TestBlocksFetcher_RequestBlocksRateLimitingLocks(t *testing.T) {
|
|||||||
gt := time.Now()
|
gt := time.Now()
|
||||||
vr := [32]byte{}
|
vr := [32]byte{}
|
||||||
fetcher.chain = &mock.ChainService{Genesis: gt, ValidatorsRoot: vr}
|
fetcher.chain = &mock.ChainService{Genesis: gt, ValidatorsRoot: vr}
|
||||||
fetcher.clock = startup.NewClock(gt, vr)
|
|
||||||
hook := logTest.NewGlobal()
|
hook := logTest.NewGlobal()
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@ -621,7 +620,6 @@ func TestBlocksFetcher_WaitForBandwidth(t *testing.T) {
|
|||||||
gt := time.Now()
|
gt := time.Now()
|
||||||
vr := [32]byte{}
|
vr := [32]byte{}
|
||||||
fetcher.chain = &mock.ChainService{Genesis: gt, ValidatorsRoot: vr}
|
fetcher.chain = &mock.ChainService{Genesis: gt, ValidatorsRoot: vr}
|
||||||
fetcher.clock = startup.NewClock(gt, vr)
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
assert.NoError(t, fetcher.waitForBandwidth(p2.PeerID(), 10))
|
assert.NoError(t, fetcher.waitForBandwidth(p2.PeerID(), 10))
|
||||||
dur := time.Since(start)
|
dur := time.Since(start)
|
||||||
|
@ -67,6 +67,7 @@ func NewService(ctx context.Context, cfg *Config) *Service {
|
|||||||
chainStarted: abool.New(),
|
chainStarted: abool.New(),
|
||||||
counter: ratecounter.NewRateCounter(counterSeconds * time.Second),
|
counter: ratecounter.NewRateCounter(counterSeconds * time.Second),
|
||||||
genesisChan: make(chan time.Time),
|
genesisChan: make(chan time.Time),
|
||||||
|
clock: startup.NewClock(time.Unix(0, 0), [32]byte{}), // default clock to prevent panic
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
@ -150,7 +150,7 @@ func NewService(ctx context.Context, opts ...Option) *Service {
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
chainStarted: abool.New(),
|
chainStarted: abool.New(),
|
||||||
cfg: &config{},
|
cfg: &config{clock: startup.NewClock(time.Unix(0, 0), [32]byte{})},
|
||||||
slotToPendingBlocks: c,
|
slotToPendingBlocks: c,
|
||||||
seenPendingBlocks: make(map[[32]byte]bool),
|
seenPendingBlocks: make(map[[32]byte]bool),
|
||||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||||
|
Loading…
Reference in New Issue
Block a user