Skip to content

Commit

Permalink
abci: Create snapshots if snapshots are enabled and none exists
Browse files Browse the repository at this point in the history
A node should create a snapshot if:

- none exists
- it is height 1 (genesis+1)
- it is not doing blocksync to some much larger height
- height is a multiple of snapshot duration
  • Loading branch information
charithabandi authored Sep 3, 2024
1 parent 662628d commit b4da094
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,17 @@ func (a *AbciApp) Commit(ctx context.Context, _ *abciTypes.RequestCommit) (*abci

a.txApp.Commit(ctx)

if a.snapshotter != nil && a.replayingBlocks != nil &&
a.snapshotter.IsSnapshotDue(uint64(a.height)) && !a.replayingBlocks() {
// Snapshots are to be taken if:
// - the block height is a multiple of the snapshot interval
// - there are no snapshots in the store (This is to support the new nodes joining the network using
// statesync. As the snapshot intervals are pretty large, the new nodes will not have any
// snapshots to start with for a long time, during which the new nodes just hangs in the snapshot
// discovery phase, which can be mitigated if we can produce a snapshot at the start of the network
// or when the node joins network at any height)
snapshotsDue := a.snapshotter != nil &&
(a.snapshotter.IsSnapshotDue(uint64(a.height)) || len(a.snapshotter.ListSnapshots()) == 0)

if a.replayingBlocks != nil && snapshotsDue && !a.replayingBlocks() {
// we make a snapshot tx but don't directly use it. This is because under the hood,
// we are using the pg_dump executable to create the snapshot, and we are simply
// giving pg_dump the snapshot ID to guarantee it has an isolated view of the database.
Expand Down

0 comments on commit b4da094

Please # to comment.