beacon/light: fix lock after lock deadlock

This commit is contained in:
Weixie Cui 2026-04-23 12:55:20 +08:00
parent 8e2107dc39
commit 445867e23a

View file

@ -182,6 +182,12 @@ func (s *CommitteeChain) Reset() {
s.chainmu.Lock() s.chainmu.Lock()
defer s.chainmu.Unlock() defer s.chainmu.Unlock()
s.resetLocked()
}
// ResetLocked resets the committee chain without locking. The caller should hold
// the chainmu lock.
func (s *CommitteeChain) resetLocked() {
if err := s.rollback(0); err != nil { if err := s.rollback(0); err != nil {
log.Error("Error writing batch into chain database", "error", err) log.Error("Error writing batch into chain database", "error", err)
} }
@ -201,22 +207,22 @@ func (s *CommitteeChain) CheckpointInit(bootstrap types.BootstrapData) error {
} }
period := bootstrap.Header.SyncPeriod() period := bootstrap.Header.SyncPeriod()
if err := s.deleteFixedCommitteeRootsFrom(period + 2); err != nil { if err := s.deleteFixedCommitteeRootsFrom(period + 2); err != nil {
s.Reset() s.resetLocked()
return err return err
} }
if s.addFixedCommitteeRoot(period, bootstrap.CommitteeRoot) != nil { if s.addFixedCommitteeRoot(period, bootstrap.CommitteeRoot) != nil {
s.Reset() s.resetLocked()
if err := s.addFixedCommitteeRoot(period, bootstrap.CommitteeRoot); err != nil { if err := s.addFixedCommitteeRoot(period, bootstrap.CommitteeRoot); err != nil {
s.Reset() s.resetLocked()
return err return err
} }
} }
if err := s.addFixedCommitteeRoot(period+1, common.Hash(bootstrap.CommitteeBranch[0])); err != nil { if err := s.addFixedCommitteeRoot(period+1, common.Hash(bootstrap.CommitteeBranch[0])); err != nil {
s.Reset() s.resetLocked()
return err return err
} }
if err := s.addCommittee(period, bootstrap.Committee); err != nil { if err := s.addCommittee(period, bootstrap.Committee); err != nil {
s.Reset() s.resetLocked()
return err return err
} }
s.changeCounter++ s.changeCounter++