Skip to content

Commit

Permalink
feat: split BaseApp.Commit
Browse files Browse the repository at this point in the history
Allow manual snapshot making
  • Loading branch information
mhofman committed Mar 23, 2023
1 parent 17f1103 commit aea978e
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv
// against that height and gracefully halt if it matches the latest committed
// height.
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
res, snapshotHeight := app.CommitWithoutSnapshot()

if snapshotHeight > 0 {
go app.Snapshot(snapshotHeight)
}

return res
}

// CommitWithoutSnapshot is like Commit but returns the snapshot information instead
// of starting the snapshot goroutine
// It can be used by apps to synchronize snapshots according to their requirements.
func (app *BaseApp) CommitWithoutSnapshot() (res abci.ResponseCommit, snapshotHeight int64) {
defer telemetry.MeasureSince(time.Now(), "abci", "commit")

header := app.deliverState.ctx.BlockHeader()
Expand Down Expand Up @@ -348,13 +361,15 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
}

if app.snapshotInterval > 0 && uint64(header.Height)%app.snapshotInterval == 0 {
go app.snapshot(header.Height)
snapshotHeight = header.Height
}

return abci.ResponseCommit{
res = abci.ResponseCommit{
Data: commitID.Hash,
RetainHeight: retainHeight,
}

return res, snapshotHeight
}

// halt attempts to gracefully shutdown the node via SIGINT and SIGTERM falling
Expand All @@ -379,8 +394,9 @@ func (app *BaseApp) halt() {
os.Exit(0)
}

// snapshot takes a snapshot of the current state and prunes any old snapshottypes.
func (app *BaseApp) snapshot(height int64) {
// Snapshot takes a snapshot of the current state and prunes any old snapshottypes.
// It should be started as a goroutine
func (app *BaseApp) Snapshot(height int64) {
if app.snapshotManager == nil {
app.logger.Info("snapshot manager not configured")
return
Expand Down

0 comments on commit aea978e

Please sign in to comment.