mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Added more checks on state reconstruction + made history reconstruction resumable. (#9211)
Co-authored-by: Bayram Guvanjov <bayramguwanjow@gmail.com>
This commit is contained in:
parent
c1e3ec59af
commit
8315033a92
@ -360,9 +360,11 @@ func (s *Antiquary) IncrementBeaconState(ctx context.Context, to uint64) error {
|
||||
defer progressTimer.Stop()
|
||||
prevSlot := slot
|
||||
first := false
|
||||
blocksBeforeCommit := 100_000
|
||||
blocksProcessed := 0
|
||||
// This tells us that transition and operations do not happen concurrently and access is safe, so we can optimize for GC.
|
||||
// there is optimized custom cache to recycle big GC overhead.
|
||||
for ; slot < to; slot++ {
|
||||
for ; slot < to && blocksProcessed < blocksBeforeCommit; slot++ {
|
||||
slashingOccured = false // Set this to false at the beginning of each slot.
|
||||
key := base_encoding.Encode64ToBytes4(slot)
|
||||
|
||||
@ -418,12 +420,13 @@ func (s *Antiquary) IncrementBeaconState(ctx context.Context, to uint64) error {
|
||||
prevValSet = prevValSet[:0]
|
||||
prevValSet = append(prevValSet, s.currentState.RawValidatorSet()...)
|
||||
|
||||
fullValidation := slot%100_000 == 0 || first
|
||||
fullValidation := slot%1000 == 0 || first
|
||||
blockRewardsCollector := ð2.BlockRewardsCollector{}
|
||||
// We sanity check the state every 100k slots or when we start.
|
||||
// We sanity check the state every 1k slots or when we start.
|
||||
if err := transition.TransitionState(s.currentState, block, blockRewardsCollector, fullValidation); err != nil {
|
||||
return err
|
||||
}
|
||||
blocksProcessed++
|
||||
|
||||
first = false
|
||||
|
||||
|
@ -166,7 +166,7 @@ func (c *checkpointState) isValidIndexedAttestation(att *cltypes.IndexedAttestat
|
||||
|
||||
pks := [][]byte{}
|
||||
inds.Range(func(_ int, v uint64, _ int) bool {
|
||||
if v < uint64(len(c.anchorPublicKeys)) {
|
||||
if v < uint64(len(c.anchorPublicKeys))/length.Bytes48 {
|
||||
pks = append(pks, c.anchorPublicKeys[v*length.Bytes48:(v+1)*length.Bytes48])
|
||||
} else {
|
||||
offset := uint64(len(c.anchorPublicKeys) / length.Bytes48)
|
||||
|
@ -114,7 +114,7 @@ func (I *impl) ProcessAttesterSlashing(s abstract.BeaconState, attSlashing *clty
|
||||
if validator.IsSlashable(currentEpoch) {
|
||||
pr, err := s.SlashValidator(ind, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to slash validator: %d", ind)
|
||||
return fmt.Errorf("unable to slash validator: %d: %s", ind, err)
|
||||
}
|
||||
if I.BlockRewardsCollector != nil {
|
||||
I.BlockRewardsCollector.AttesterSlashings += pr
|
||||
@ -755,28 +755,26 @@ func batchVerifyAttestations(s abstract.BeaconState, indexedAttestations []*clty
|
||||
}
|
||||
|
||||
func (I *impl) ProcessBlockHeader(s abstract.BeaconState, block *cltypes.BeaconBlock) error {
|
||||
if I.FullValidation {
|
||||
if block.Slot != s.Slot() {
|
||||
return fmt.Errorf("state slot: %d, not equal to block slot: %d", s.Slot(), block.Slot)
|
||||
}
|
||||
if block.Slot <= s.LatestBlockHeader().Slot {
|
||||
return fmt.Errorf("slock slot: %d, not greater than latest block slot: %d", block.Slot, s.LatestBlockHeader().Slot)
|
||||
}
|
||||
propInd, err := s.GetBeaconProposerIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in GetBeaconProposerIndex: %v", err)
|
||||
}
|
||||
if block.ProposerIndex != propInd {
|
||||
return fmt.Errorf("block proposer index: %d, does not match beacon proposer index: %d", block.ProposerIndex, propInd)
|
||||
}
|
||||
blockHeader := s.LatestBlockHeader()
|
||||
latestRoot, err := (&blockHeader).HashSSZ()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to hash tree root of latest block header: %v", err)
|
||||
}
|
||||
if block.ParentRoot != latestRoot {
|
||||
return fmt.Errorf("block parent root: %x, does not match latest block root: %x", block.ParentRoot, latestRoot)
|
||||
}
|
||||
if block.Slot != s.Slot() {
|
||||
return fmt.Errorf("state slot: %d, not equal to block slot: %d", s.Slot(), block.Slot)
|
||||
}
|
||||
if block.Slot <= s.LatestBlockHeader().Slot {
|
||||
return fmt.Errorf("slock slot: %d, not greater than latest block slot: %d", block.Slot, s.LatestBlockHeader().Slot)
|
||||
}
|
||||
propInd, err := s.GetBeaconProposerIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in GetBeaconProposerIndex: %v", err)
|
||||
}
|
||||
if block.ProposerIndex != propInd {
|
||||
return fmt.Errorf("block proposer index: %d, does not match beacon proposer index: %d", block.ProposerIndex, propInd)
|
||||
}
|
||||
blockHeader := s.LatestBlockHeader()
|
||||
latestRoot, err := (&blockHeader).HashSSZ()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to hash tree root of latest block header: %v", err)
|
||||
}
|
||||
if block.ParentRoot != latestRoot {
|
||||
return fmt.Errorf("block parent root: %x, does not match latest block root: %x", block.ParentRoot, latestRoot)
|
||||
}
|
||||
|
||||
bodyRoot, err := block.Body.HashSSZ()
|
||||
|
Loading…
Reference in New Issue
Block a user