Skip to content

Commit

Permalink
fix: double close (cosmos#13400)
Browse files Browse the repository at this point in the history
(cherry picked from commit dcb0c9c)
  • Loading branch information
mmsqe authored and mhofman committed Mar 8, 2023
1 parent 6954b1a commit 7edfcea
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
12 changes: 6 additions & 6 deletions baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions snapshots/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions snapshots/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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)},
Expand Down Expand Up @@ -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)},
Expand Down
4 changes: 0 additions & 4 deletions snapshots/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion snapshots/types/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion store/rootmulti/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestMultistoreSnapshot_Checksum(t *testing.T) {
"aa048b4ee0f484965d7b3b06822cf0772cdcaad02f3b1b9055e69f2cb365ef3c",
"7921eaa3ed4921341e504d9308a9877986a879fe216a099c86e8db66fcba4c63",
"a4a864e6c02c9fca5837ec80dc84f650b25276ed7e4820cf7516ced9f9901b86",
"ca2879ac6e7205d257440131ba7e72bef784cd61642e32b847729e543c1928b9",
"980925390cc50f14998ecb1e87de719ca9dd7e72f5fefbe445397bf670f36c31",
}},
}
for _, tc := range testcases {
Expand Down

0 comments on commit 7edfcea

Please sign in to comment.