fix: allow app.SetSnapshotStore(nil) (#7507)

* fix: allow app.SetSnapshotStore(nil)

* fix: downgrade Error to Info in BaseApp.snapshot
This commit is contained in:
Michael FIG 2020-11-03 16:02:27 -06:00 committed by GitHub
parent ec285f1798
commit d96d79b8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -354,6 +354,10 @@ func (app *BaseApp) halt() {
// snapshot takes a snapshot of the current state and prunes any old snapshottypes. // snapshot takes a snapshot of the current state and prunes any old snapshottypes.
func (app *BaseApp) snapshot(height int64) { 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) app.logger.Info("Creating state snapshot", "height", height)
snapshot, err := app.snapshotManager.Create(uint64(height)) snapshot, err := app.snapshotManager.Create(uint64(height))
if err != nil { 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. // OfferSnapshot implements the ABCI interface. It delegates to app.snapshotManager if set.
func (app *BaseApp) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferSnapshot { 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 { if req.Snapshot == nil {
app.logger.Error("Received nil snapshot") app.logger.Error("Received nil snapshot")
return abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_REJECT} 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. // ApplySnapshotChunk implements the ABCI interface. It delegates to app.snapshotManager if set.
func (app *BaseApp) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) abci.ResponseApplySnapshotChunk { 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) _, err := app.snapshotManager.RestoreChunk(req.Chunk)
switch { switch {
case err == nil: case err == nil:

View File

@ -204,6 +204,10 @@ func (app *BaseApp) SetSnapshotStore(snapshotStore *snapshots.Store) {
if app.sealed { if app.sealed {
panic("SetSnapshotStore() on sealed BaseApp") panic("SetSnapshotStore() on sealed BaseApp")
} }
if snapshotStore == nil {
app.snapshotManager = nil
return
}
app.snapshotManager = snapshots.NewManager(snapshotStore, app.cms) app.snapshotManager = snapshots.NewManager(snapshotStore, app.cms)
} }