mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
Fix NPE, ensure the listener is available (#11946)
* Fix NPE, ensure the listener is available * Added test --------- Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
parent
9ccfe17227
commit
094ff877f6
@ -22,9 +22,11 @@ func (s *Service) forkWatcher() {
|
||||
// the updated fork digest. These repeatedly does
|
||||
// this over the epoch, which might be slightly wasteful
|
||||
// but is fine nonetheless.
|
||||
_, err := addForkEntry(s.dv5Listener.LocalNode(), s.genesisTime, s.genesisValidatorsRoot)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not add fork entry")
|
||||
if s.dv5Listener != nil { // make sure it's not a local network
|
||||
_, err := addForkEntry(s.dv5Listener.LocalNode(), s.genesisTime, s.genesisValidatorsRoot)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not add fork entry")
|
||||
}
|
||||
}
|
||||
|
||||
// from Bellatrix Epoch, the MaxGossipSize and the MaxChunkSize is changed to 10Mb.
|
||||
|
@ -152,6 +152,51 @@ func TestService_Status_NoGenesisTimeSet(t *testing.T) {
|
||||
assert.NoError(t, s.Status(), "Status returned error")
|
||||
}
|
||||
|
||||
func TestService_Start_NoDiscoverFlag(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
|
||||
cfg := &Config{
|
||||
TCPPort: 2000,
|
||||
UDPPort: 2000,
|
||||
StateNotifier: &mock.MockStateNotifier{},
|
||||
NoDiscovery: true, // <-- no s.dv5Listener is created
|
||||
}
|
||||
s, err := NewService(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
s.stateNotifier = &mock.MockStateNotifier{}
|
||||
|
||||
// required params to addForkEntry in s.forkWatcher
|
||||
s.genesisTime = time.Now()
|
||||
beaconCfg := params.BeaconConfig().Copy()
|
||||
beaconCfg.AltairForkEpoch = 0
|
||||
beaconCfg.BellatrixForkEpoch = 0
|
||||
beaconCfg.CapellaForkEpoch = 0
|
||||
beaconCfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(beaconCfg)
|
||||
|
||||
exitRoutine := make(chan bool)
|
||||
go func() {
|
||||
s.Start()
|
||||
<-exitRoutine
|
||||
}()
|
||||
|
||||
// Send in a loop to ensure it is delivered (busy wait for the service to subscribe to the state feed).
|
||||
for sent := 0; sent == 0; {
|
||||
sent = s.stateNotifier.StateFeed().Send(&feed.Event{
|
||||
Type: statefeed.Initialized,
|
||||
Data: &statefeed.InitializedData{
|
||||
StartTime: time.Now(),
|
||||
GenesisValidatorsRoot: make([]byte, 32),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
exitRoutine <- true
|
||||
}
|
||||
|
||||
func TestListenForNewNodes(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
// Setup bootnode.
|
||||
|
Loading…
Reference in New Issue
Block a user