From 7edfcea0b1635186d733e2751eaf300f24ee50bb Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 28 Sep 2022 02:16:13 +0800 Subject: [PATCH] fix: double close (#13400) (cherry picked from commit dcb0c9c04c5d8406bede521cde94335015185b2b) --- CHANGELOG.md | 1 + baseapp/baseapp_test.go | 2 +- baseapp/deliver_tx_test.go | 12 ++++++------ snapshots/helpers_test.go | 5 ++--- snapshots/manager_test.go | 6 +++--- snapshots/stream.go | 4 ---- snapshots/types/format.go | 2 +- store/rootmulti/snapshot_test.go | 2 +- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe5b9ea1312..ae68bfc1653f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (deps) Bump Tendermint version to [v0.34.23](https://github.com/tendermint/tendermint/releases/tag/v0.34.23). * (deps) Bump IAVL version to [v0.19.4](https://github.com/cosmos/iavl/releases/tag/v0.19.4). +* (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. ### Bug Fixes diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index f9cdfcb71438..bf962439c096 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -167,7 +167,7 @@ func TestListSnapshots(t *testing.T) { app, _ := setupBaseAppWithSnapshots(t, 2, 5) expected := abci.ResponseListSnapshots{Snapshots: []*abci.Snapshot{ - {Height: 2, Format: 1, Chunks: 2}, + {Height: 2, Format: 2, Chunks: 2}, }} resp := app.ListSnapshots(abci.RequestListSnapshots{}) diff --git a/baseapp/deliver_tx_test.go b/baseapp/deliver_tx_test.go index c0126f9964f4..df2dea33a8a7 100644 --- a/baseapp/deliver_tx_test.go +++ b/baseapp/deliver_tx_test.go @@ -39,13 +39,13 @@ func TestLoadSnapshotChunk(t *testing.T) { chunk uint32 expectEmpty bool }{ - "Existing snapshot": {2, 1, 1, false}, - "Missing height": {100, 1, 1, true}, - "Missing format": {2, 2, 1, true}, - "Missing chunk": {2, 1, 9, true}, - "Zero height": {0, 1, 1, true}, + "Existing snapshot": {2, 2, 1, false}, + "Missing height": {100, 2, 1, true}, + "Missing format": {2, 3, 1, true}, + "Missing chunk": {2, 2, 9, true}, + "Zero height": {0, 2, 1, true}, "Zero format": {2, 0, 1, true}, - "Zero chunk": {2, 1, 0, false}, + "Zero chunk": {2, 2, 0, false}, } for name, tc := range testcases { tc := tc diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 7eb2aeae9a1c..d84ae45c7ee2 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -90,7 +90,6 @@ func snapshotItems(items [][]byte, ext snapshottypes.ExtensionSnapshotter) [][]b return snapshottypes.WriteExtensionPayload(protoWriter, payload) }) protoWriter.Close() - zWriter.Close() bufWriter.Flush() chunkWriter.Close() }() @@ -150,11 +149,11 @@ func (m *mockSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) er } func (m *mockSnapshotter) SnapshotFormat() uint32 { - return 1 + return 2 } func (m *mockSnapshotter) SupportedFormats() []uint32 { - return []uint32{1} + return []uint32{2} } // setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1. diff --git a/snapshots/manager_test.go b/snapshots/manager_test.go index e8d02ca28fd6..efd3a7f78dfd 100644 --- a/snapshots/manager_test.go +++ b/snapshots/manager_test.go @@ -83,7 +83,7 @@ func TestManager_Take(t *testing.T) { Height: 5, Format: snapshotter.SnapshotFormat(), Chunks: 1, - Hash: []uint8{0x89, 0xfa, 0x18, 0xbc, 0x5a, 0xe3, 0xdc, 0x36, 0xa6, 0x95, 0x5, 0x17, 0xf9, 0x2, 0x1a, 0x55, 0x36, 0x16, 0x5d, 0x4b, 0x8b, 0x2b, 0x3d, 0xfd, 0xe, 0x2f, 0xb6, 0x40, 0x6b, 0xc3, 0xbc, 0x23}, + Hash: []uint8{0xc5, 0xf7, 0xfe, 0xea, 0xd3, 0x4d, 0x3e, 0x87, 0xff, 0x41, 0xa2, 0x27, 0xfa, 0xcb, 0x38, 0x17, 0xa, 0x5, 0xeb, 0x27, 0x4e, 0x16, 0x5e, 0xf3, 0xb2, 0x8b, 0x47, 0xd1, 0xe6, 0x94, 0x7e, 0x8b}, Metadata: types.Metadata{ ChunkHashes: checksums(expectChunks), }, @@ -162,7 +162,7 @@ func TestManager_Restore(t *testing.T) { // Starting a restore works err = manager.Restore(types.Snapshot{ Height: 3, - Format: 1, + Format: 2, Hash: []byte{1, 2, 3}, Chunks: 1, Metadata: types.Metadata{ChunkHashes: checksums(chunks)}, @@ -211,7 +211,7 @@ func TestManager_Restore(t *testing.T) { target.items = nil err = manager.Restore(types.Snapshot{ Height: 3, - Format: 1, + Format: 2, Hash: []byte{1, 2, 3}, Chunks: 1, Metadata: types.Metadata{ChunkHashes: checksums(chunks)}, diff --git a/snapshots/stream.go b/snapshots/stream.go index 80cd5c3dfdcb..ba622ebfb5ae 100644 --- a/snapshots/stream.go +++ b/snapshots/stream.go @@ -57,10 +57,6 @@ func (sw *StreamWriter) Close() error { sw.chunkWriter.CloseWithError(err) return err } - if err := sw.zWriter.Close(); err != nil { - sw.chunkWriter.CloseWithError(err) - return err - } if err := sw.bufWriter.Flush(); err != nil { sw.chunkWriter.CloseWithError(err) return err diff --git a/snapshots/types/format.go b/snapshots/types/format.go index edfdb36d7bfc..d5e960660ac9 100644 --- a/snapshots/types/format.go +++ b/snapshots/types/format.go @@ -3,4 +3,4 @@ package types // CurrentFormat is the currently used format for snapshots. Snapshots using the same format // must be identical across all nodes for a given height, so this must be bumped when the binary // snapshot output changes. -const CurrentFormat uint32 = 1 +const CurrentFormat uint32 = 2 diff --git a/store/rootmulti/snapshot_test.go b/store/rootmulti/snapshot_test.go index 7a3071940e99..48cd4ff8f4f1 100644 --- a/store/rootmulti/snapshot_test.go +++ b/store/rootmulti/snapshot_test.go @@ -128,7 +128,7 @@ func TestMultistoreSnapshot_Checksum(t *testing.T) { "aa048b4ee0f484965d7b3b06822cf0772cdcaad02f3b1b9055e69f2cb365ef3c", "7921eaa3ed4921341e504d9308a9877986a879fe216a099c86e8db66fcba4c63", "a4a864e6c02c9fca5837ec80dc84f650b25276ed7e4820cf7516ced9f9901b86", - "ca2879ac6e7205d257440131ba7e72bef784cd61642e32b847729e543c1928b9", + "980925390cc50f14998ecb1e87de719ca9dd7e72f5fefbe445397bf670f36c31", }}, } for _, tc := range testcases {