mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/light: shift sync committees over correctly
This commit is contained in:
parent
2d2b7f4bec
commit
c63e8c58bc
2 changed files with 8 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue