From c63e8c58bc710b46749bb360ab5ac45af2a328ba Mon Sep 17 00:00:00 2001 From: lightclient Date: Fri, 5 Jan 2024 19:43:46 -0700 Subject: [PATCH] beacon/light: shift sync committees over correctly --- beacon/light/chain.go | 9 +++++++-- beacon/light/store.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/beacon/light/chain.go b/beacon/light/chain.go index 247687fdf7..0ff3859402 100644 --- a/beacon/light/chain.go +++ b/beacon/light/chain.go @@ -54,6 +54,9 @@ func Bootstrap(server string, headers []string, root common.Hash) (*LightClient, if err != nil { return nil, fmt.Errorf("failed to get bootstrap data: %w", err) } + if bs.Header.Hash() != root { + return nil, fmt.Errorf("bootstrap root did not match requested: want %s, got %s", root, bs.Header.Hash()) + } if err := bs.Valid(); err != nil { return nil, fmt.Errorf("failed to validate bootstrap data: %w", err) } @@ -95,20 +98,22 @@ func (c *LightClient) Finalized() *types.Header { func (c *LightClient) Start() error { var ( ticker = time.NewTicker(params.SlotLength * time.Second) - lastFinality = time.Now() + lastFinality = time.Time{} ) for { select { case <-c.quitCh: return nil case <-ticker.C: + log.Trace("Blsync status", "period", c.store.finalizedPeriod(), "active", c.store.currActive, "prevActive", c.store.prevActive, "currCommittee", c.store.current != nil, "nextCommittee", c.store.next != nil) if c.store.next == nil { - log.Debug("Fetching committee update", "period", c.store.finalizedPeriod()) + log.Debug("Fetching committee update", "period", c.store.finalizedPeriod()+1) updates, err := c.beacon.GetRangeUpdate(c.store.finalizedPeriod(), 1) if err != nil { log.Error("Failed to fetch next committee", "err", err) } else { for _, update := range updates { + log.Trace("New beacon range update", "slot", update.AttestedHeader.Slot, "root", update.AttestedHeader.Hash(), "sigslot", update.SignatureSlot, "period", update.AttestedHeader.SyncPeriod()) if err := c.store.Insert(update); err != nil { log.Error("Failed to insert committee update", "err", err) break diff --git a/beacon/light/store.go b/beacon/light/store.go index 93d3aac442..6fc1432f52 100644 --- a/beacon/light/store.go +++ b/beacon/light/store.go @@ -166,7 +166,6 @@ func (s *store) Insert(update *types.LightClientUpdate) error { // Process finalized header update. if update.FinalizedHeader != nil { if update.FinalizedHeader.Header.Slot > s.finalized.Slot { - s.finalized = &update.FinalizedHeader.Header var ( storedPeriod = types.SyncPeriod(s.finalized.Slot) updatePeriod = types.SyncPeriod(update.FinalizedHeader.Slot) @@ -179,6 +178,7 @@ func (s *store) Insert(update *types.LightClientUpdate) error { s.prevActive = s.currActive s.currActive = 0 } + s.finalized = &update.FinalizedHeader.Header } }