From d96d79b8fbbf8af7c1343700767fe9840edaba58 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Tue, 3 Nov 2020 16:02:27 -0600 Subject: [PATCH] fix: allow app.SetSnapshotStore(nil) (#7507) * fix: allow app.SetSnapshotStore(nil) * fix: downgrade Error to Info in BaseApp.snapshot --- baseapp/abci.go | 14 ++++++++++++++ baseapp/options.go | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/baseapp/abci.go b/baseapp/abci.go index a8f442b8d3b3..ada95acf1f67 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -354,6 +354,10 @@ func (app *BaseApp) halt() { // snapshot takes a snapshot of the current state and prunes any old snapshottypes. func (app *BaseApp) snapshot(height int64) { + if app.snapshotManager == nil { + app.logger.Info("snapshot manager not configured") + return + } app.logger.Info("Creating state snapshot", "height", height) snapshot, err := app.snapshotManager.Create(uint64(height)) if err != nil { @@ -447,6 +451,11 @@ func (app *BaseApp) LoadSnapshotChunk(req abci.RequestLoadSnapshotChunk) abci.Re // OfferSnapshot implements the ABCI interface. It delegates to app.snapshotManager if set. func (app *BaseApp) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferSnapshot { + if app.snapshotManager == nil { + app.logger.Error("snapshot manager not configured") + return abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ABORT} + } + if req.Snapshot == nil { app.logger.Error("Received nil snapshot") return abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_REJECT} @@ -481,6 +490,11 @@ func (app *BaseApp) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOf // ApplySnapshotChunk implements the ABCI interface. It delegates to app.snapshotManager if set. func (app *BaseApp) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) abci.ResponseApplySnapshotChunk { + if app.snapshotManager == nil { + app.logger.Error("snapshot manager not configured") + return abci.ResponseApplySnapshotChunk{Result: abci.ResponseApplySnapshotChunk_ABORT} + } + _, err := app.snapshotManager.RestoreChunk(req.Chunk) switch { case err == nil: diff --git a/baseapp/options.go b/baseapp/options.go index 008af9a18535..33de1a3aa6e8 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -204,6 +204,10 @@ func (app *BaseApp) SetSnapshotStore(snapshotStore *snapshots.Store) { if app.sealed { panic("SetSnapshotStore() on sealed BaseApp") } + if snapshotStore == nil { + app.snapshotManager = nil + return + } app.snapshotManager = snapshots.NewManager(snapshotStore, app.cms) }