Skip to content

Commit

Permalink
consensus/parlia: recover faster when snapshot of parlia is gone in disk
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Nov 28, 2023
1 parent c92b6ce commit a6f3393
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash
// If we're at the genesis, snapshot the initial state. Alternatively if we have
// piled up more headers than allowed to be reorged (chain reinit from a freezer),
// consider the checkpoint trusted and snapshot it.
if number == 0 || (number%p.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold)) {
if number == 0 || (number%p.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold/10)) {
checkpoint := chain.GetHeaderByNumber(number)
if checkpoint != nil {
// get checkpoint data
Expand All @@ -694,10 +694,12 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash

// new snapshot
snap = newSnapshot(p.config, p.signatures, number, hash, validators, voteAddrs, p.ethAPI)
if err := snap.store(p.db); err != nil {
return nil, err
if snap.Number%checkpointInterval == 0 { // snapshot will only be loaded when snap.Number%checkpointInterval == 0
if err := snap.store(p.db); err != nil {
return nil, err
}
log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash)
}
log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash)
break
}
}
Expand Down
3 changes: 3 additions & 0 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func (s *Snapshot) updateAttestation(header *types.Header, chainConfig *params.C
}

// Update attestation
// Two scenarios for s.Attestation being nil:
// 1) The first attestation is assembled.
// 2) The snapshot on disk is missing, prompting the creation of a new snapshot using `newSnapshot`.
if s.Attestation != nil && attestation.Data.SourceNumber+1 != attestation.Data.TargetNumber {
s.Attestation.TargetNumber = attestation.Data.TargetNumber
s.Attestation.TargetHash = attestation.Data.TargetHash
Expand Down

0 comments on commit a6f3393

Please sign in to comment.