mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Fix wait for activation (#1913)
* fix but no test * ensure a canonical state is sent
This commit is contained in:
parent
869f08ad26
commit
34f0241f32
@ -105,10 +105,12 @@ func (c *ChainService) Start() {
|
||||
DepositRootHash32: depositRoot[:],
|
||||
BlockHash32: latestBlockHash[:],
|
||||
}
|
||||
if err := c.initializeBeaconChain(genesisTime, initialDeposits, eth1Data); err != nil {
|
||||
beaconState, err := c.initializeBeaconChain(genesisTime, initialDeposits, eth1Data)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not initialize beacon chain: %v", err)
|
||||
}
|
||||
c.stateInitializedFeed.Send(genesisTime)
|
||||
c.canonicalStateFeed.Send(beaconState)
|
||||
go c.blockProcessing()
|
||||
subChainStart.Unsubscribe()
|
||||
}()
|
||||
@ -119,29 +121,29 @@ func (c *ChainService) Start() {
|
||||
// based on a genesis timestamp value obtained from the ChainStart event emitted
|
||||
// by the ETH1.0 Deposit Contract and the POWChain service of the node.
|
||||
func (c *ChainService) initializeBeaconChain(genesisTime time.Time, deposits []*pb.Deposit,
|
||||
eth1data *pb.Eth1Data) error {
|
||||
eth1data *pb.Eth1Data) (*pb.BeaconState, error) {
|
||||
log.Info("ChainStart time reached, starting the beacon chain!")
|
||||
c.genesisTime = genesisTime
|
||||
unixTime := uint64(genesisTime.Unix())
|
||||
if err := c.beaconDB.InitializeState(unixTime, deposits, eth1data); err != nil {
|
||||
return fmt.Errorf("could not initialize beacon state to disk: %v", err)
|
||||
return nil, fmt.Errorf("could not initialize beacon state to disk: %v", err)
|
||||
}
|
||||
beaconState, err := c.beaconDB.State(c.ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not attempt fetch beacon state: %v", err)
|
||||
return nil, fmt.Errorf("could not attempt fetch beacon state: %v", err)
|
||||
}
|
||||
stateRoot, err := hashutil.HashProto(beaconState)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not hash beacon state: %v", err)
|
||||
return nil, fmt.Errorf("could not hash beacon state: %v", err)
|
||||
}
|
||||
genBlock := b.NewGenesisBlock(stateRoot[:])
|
||||
if err := c.beaconDB.SaveBlock(genBlock); err != nil {
|
||||
return fmt.Errorf("could not save genesis block to disk: %v", err)
|
||||
return nil, fmt.Errorf("could not save genesis block to disk: %v", err)
|
||||
}
|
||||
if err := c.beaconDB.UpdateChainHead(genBlock, beaconState); err != nil {
|
||||
return fmt.Errorf("could not set chain head, %v", err)
|
||||
return nil, fmt.Errorf("could not set chain head, %v", err)
|
||||
}
|
||||
return nil
|
||||
return beaconState, nil
|
||||
}
|
||||
|
||||
// Stop the blockchain service's main event loop and associated goroutines.
|
||||
|
@ -257,8 +257,11 @@ func TestChainStartStop_Uninitialized(t *testing.T) {
|
||||
|
||||
// Test the start function.
|
||||
genesisChan := make(chan time.Time, 0)
|
||||
stateChan := make(chan *pb.BeaconState, 0)
|
||||
sub := chainService.stateInitializedFeed.Subscribe(genesisChan)
|
||||
defer sub.Unsubscribe()
|
||||
sub2 := chainService.canonicalStateFeed.Subscribe(stateChan)
|
||||
defer sub2.Unsubscribe()
|
||||
chainService.Start()
|
||||
chainService.chainStartChan <- time.Unix(0, 0)
|
||||
genesisTime := <-genesisChan
|
||||
@ -270,6 +273,12 @@ func TestChainStartStop_Uninitialized(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
beaconState := <-stateChan
|
||||
|
||||
if beaconState == nil || beaconState.Slot != params.BeaconConfig().GenesisSlot {
|
||||
t.Error("Expected canonical state feed to send a state with genesis block")
|
||||
}
|
||||
|
||||
if err := chainService.Stop(); err != nil {
|
||||
t.Fatalf("Unable to stop chain service: %v", err)
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ func NewValidatorService(ctx context.Context, cfg *Config) (*ValidatorService, e
|
||||
// Start the validator service. Launches the main go routine for the validator
|
||||
// client.
|
||||
func (v *ValidatorService) Start() {
|
||||
log.WithField("publicKey", fmt.Sprintf("%#x", v.key.PublicKey.Marshal())).Info("Initializing new validator service")
|
||||
|
||||
var dialOpt grpc.DialOption
|
||||
if v.withCert != "" {
|
||||
creds, err := credentials.NewClientTLSFromFile(v.withCert, "")
|
||||
|
Loading…
Reference in New Issue
Block a user