mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add locks to forkchoice spec tests (#12165)
* Add locks to forkchoice spec testS * Fix * Rm forkchoice store getter * Rm useless lock
This commit is contained in:
@@ -484,8 +484,3 @@ func (s *Service) Ancestor(ctx context.Context, root []byte, slot primitives.Slo
|
||||
func (s *Service) SetGenesisTime(t time.Time) {
|
||||
s.genesisTime = t
|
||||
}
|
||||
|
||||
// ForkChoiceStore returns the fork choice store in the service.
|
||||
func (s *Service) ForkChoiceStore() forkchoice.ForkChoicer {
|
||||
return s.cfg.ForkChoiceStore
|
||||
}
|
||||
|
||||
@@ -71,12 +71,6 @@ func TestHeadRoot_Nil(t *testing.T) {
|
||||
assert.DeepEqual(t, params.BeaconConfig().ZeroHash[:], headRoot, "Incorrect pre chain start value")
|
||||
}
|
||||
|
||||
func TestService_ForkChoiceStore(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: doublylinkedtree.New()}}
|
||||
p := c.ForkChoiceStore()
|
||||
require.Equal(t, primitives.Epoch(0), p.FinalizedCheckpoint().Epoch)
|
||||
}
|
||||
|
||||
func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
@@ -559,7 +553,7 @@ func TestService_IsFinalized(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c := &Service{cfg: &config{BeaconDB: beaconDB, ForkChoiceStore: doublylinkedtree.New()}}
|
||||
r1 := [32]byte{'a'}
|
||||
require.NoError(t, c.ForkChoiceStore().UpdateFinalizedCheckpoint(&forkchoicetypes.Checkpoint{
|
||||
require.NoError(t, c.ForkChoicer().UpdateFinalizedCheckpoint(&forkchoicetypes.Checkpoint{
|
||||
Root: r1,
|
||||
}))
|
||||
b := util.NewBeaconBlock()
|
||||
|
||||
@@ -38,6 +38,9 @@ func NewBuilder(t testing.TB, initialState state.BeaconState, initialBlock inter
|
||||
|
||||
// Tick resets the genesis time to now()-tick and adjusts the slot to the appropriate value.
|
||||
func (bb *Builder) Tick(t testing.TB, tick int64) {
|
||||
bb.service.ForkChoicer().Lock()
|
||||
defer bb.service.ForkChoicer().Unlock()
|
||||
|
||||
bb.service.SetGenesisTime(time.Unix(time.Now().Unix()-tick, 0))
|
||||
lastSlot := uint64(bb.lastTick) / params.BeaconConfig().SecondsPerSlot
|
||||
currentSlot := uint64(tick) / params.BeaconConfig().SecondsPerSlot
|
||||
@@ -104,11 +107,17 @@ func (bb *Builder) PoWBlock(pb *ethpb.PowBlock) {
|
||||
|
||||
// Attestation receives the attestation and updates forkchoice.
|
||||
func (bb *Builder) Attestation(t testing.TB, a *ethpb.Attestation) {
|
||||
bb.service.ForkChoicer().Lock()
|
||||
defer bb.service.ForkChoicer().Unlock()
|
||||
|
||||
require.NoError(t, bb.service.OnAttestation(context.TODO(), a, params.BeaconNetworkConfig().MaximumGossipClockDisparity))
|
||||
}
|
||||
|
||||
// AttesterSlashing receives an attester slashing and feeds it to forkchoice.
|
||||
func (bb *Builder) AttesterSlashing(s *ethpb.AttesterSlashing) {
|
||||
bb.service.ForkChoicer().Lock()
|
||||
defer bb.service.ForkChoicer().Unlock()
|
||||
|
||||
slashings := []*ethpb.AttesterSlashing{s}
|
||||
bb.service.InsertSlashingsToForkChoiceStore(context.TODO(), slashings)
|
||||
}
|
||||
@@ -119,7 +128,9 @@ func (bb *Builder) Check(t testing.TB, c *Check) {
|
||||
return
|
||||
}
|
||||
ctx := context.TODO()
|
||||
bb.service.ForkChoicer().Lock()
|
||||
require.NoError(t, bb.service.UpdateAndSaveHeadWithBalances(ctx))
|
||||
bb.service.ForkChoicer().Unlock()
|
||||
if c.Head != nil {
|
||||
r, err := bb.service.HeadRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -144,9 +155,9 @@ func (bb *Builder) Check(t testing.TB, c *Check) {
|
||||
}
|
||||
if c.ProposerBoostRoot != nil {
|
||||
want := fmt.Sprintf("%#x", common.FromHex(*c.ProposerBoostRoot))
|
||||
bb.service.ForkChoiceStore().RLock()
|
||||
got := fmt.Sprintf("%#x", bb.service.ForkChoiceStore().ProposerBoost())
|
||||
bb.service.ForkChoiceStore().RUnlock()
|
||||
bb.service.ForkChoicer().RLock()
|
||||
got := fmt.Sprintf("%#x", bb.service.ForkChoicer().ProposerBoost())
|
||||
bb.service.ForkChoicer().RUnlock()
|
||||
require.DeepEqual(t, want, got)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user