mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/light: reset invalid chain
This commit is contained in:
parent
46bdc031af
commit
b039c2c1c0
1 changed files with 34 additions and 19 deletions
|
|
@ -135,25 +135,9 @@ func NewCommitteeChain(db ethdb.KeyValueStore, config *types.ChainConfig, signer
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// check validity constraints
|
if !s.checkConstraints() {
|
||||||
if !s.updates.periods.IsEmpty() {
|
log.Info("Resetting invalid committee chain")
|
||||||
if s.fixedRoots.periods.IsEmpty() || s.updates.periods.First < s.fixedRoots.periods.First ||
|
s.Reset()
|
||||||
s.updates.periods.First >= s.fixedRoots.periods.AfterLast {
|
|
||||||
log.Error("First update is not in the fixed roots range")
|
|
||||||
}
|
|
||||||
if s.committees.periods.First > s.updates.periods.First || s.committees.periods.AfterLast <= s.updates.periods.AfterLast {
|
|
||||||
log.Error("Missing committees in update range")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !s.committees.periods.IsEmpty() {
|
|
||||||
if s.fixedRoots.periods.IsEmpty() || s.committees.periods.First < s.fixedRoots.periods.First ||
|
|
||||||
s.committees.periods.First >= s.fixedRoots.periods.AfterLast {
|
|
||||||
log.Error("First committee is not in the fixed roots range")
|
|
||||||
}
|
|
||||||
if s.committees.periods.AfterLast > s.fixedRoots.periods.AfterLast && s.committees.periods.AfterLast > s.updates.periods.AfterLast+1 {
|
|
||||||
log.Error("Last committee is neither in the fixed roots range nor proven by updates")
|
|
||||||
}
|
|
||||||
log.Trace("Sync committee chain loaded", "first period", s.committees.periods.First, "last period", s.committees.periods.AfterLast-1)
|
|
||||||
}
|
}
|
||||||
// roll back invalid updates (might be necessary if forks have been changed since last time)
|
// roll back invalid updates (might be necessary if forks have been changed since last time)
|
||||||
batch := s.db.NewBatch()
|
batch := s.db.NewBatch()
|
||||||
|
|
@ -169,9 +153,40 @@ func NewCommitteeChain(db ethdb.KeyValueStore, config *types.ChainConfig, signer
|
||||||
if err := batch.Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
log.Error("Error writing batch into chain database", "error", err)
|
log.Error("Error writing batch into chain database", "error", err)
|
||||||
}
|
}
|
||||||
|
if !s.committees.periods.IsEmpty() {
|
||||||
|
log.Trace("Sync committee chain loaded", "first period", s.committees.periods.First, "last period", s.committees.periods.AfterLast-1)
|
||||||
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkConstraints checks committee chain validity constraints
|
||||||
|
func (s *CommitteeChain) checkConstraints() bool {
|
||||||
|
valid := true
|
||||||
|
if !s.updates.periods.IsEmpty() {
|
||||||
|
if s.fixedRoots.periods.IsEmpty() || s.updates.periods.First < s.fixedRoots.periods.First ||
|
||||||
|
s.updates.periods.First >= s.fixedRoots.periods.AfterLast {
|
||||||
|
log.Error("First update is not in the fixed roots range")
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if s.committees.periods.First > s.updates.periods.First || s.committees.periods.AfterLast <= s.updates.periods.AfterLast {
|
||||||
|
log.Error("Missing committees in update range")
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !s.committees.periods.IsEmpty() {
|
||||||
|
if s.fixedRoots.periods.IsEmpty() || s.committees.periods.First < s.fixedRoots.periods.First ||
|
||||||
|
s.committees.periods.First >= s.fixedRoots.periods.AfterLast {
|
||||||
|
log.Error("First committee is not in the fixed roots range")
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if s.committees.periods.AfterLast > s.fixedRoots.periods.AfterLast && s.committees.periods.AfterLast > s.updates.periods.AfterLast+1 {
|
||||||
|
log.Error("Last committee is neither in the fixed roots range nor proven by updates")
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
// Reset resets the committee chain.
|
// Reset resets the committee chain.
|
||||||
func (s *CommitteeChain) Reset() {
|
func (s *CommitteeChain) Reset() {
|
||||||
s.chainmu.Lock()
|
s.chainmu.Lock()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue