@@ -27,7 +27,6 @@ const (
27
27
28
28
type SnapshotVersion byte
29
29
30
- const SnapshotVersionV1 = SnapshotVersion (1 )
31
30
const SnapshotVersionV2 = SnapshotVersion (2 )
32
31
33
32
var (
@@ -95,19 +94,10 @@ func (m *SnapshotManager) createShapshotForVersion(height uint64, version Snapsh
95
94
return nil , common.Hash {}, ""
96
95
}
97
96
98
- switch version {
99
- case SnapshotVersionV1 :
100
- if root , err = m .state .WriteSnapshot (height , file ); err != nil {
101
- file .Close ()
102
- m .log .Error ("Cannot write snapshot to file" , "err" , err )
103
- return nil , common.Hash {}, ""
104
- }
105
- case SnapshotVersionV2 :
106
- if root , err = m .state .WriteSnapshot2 (height , file ); err != nil {
107
- file .Close ()
108
- m .log .Error ("Cannot write snapshot to file" , "err" , err )
109
- return nil , common.Hash {}, ""
110
- }
97
+ if root , err = m .state .WriteSnapshot2 (height , file ); err != nil {
98
+ file .Close ()
99
+ m .log .Error ("Cannot write snapshot to file" , "err" , err )
100
+ return nil , common.Hash {}, ""
111
101
}
112
102
113
103
file .Close ()
@@ -132,19 +122,16 @@ func (m *SnapshotManager) createShapshotForVersion(height uint64, version Snapsh
132
122
133
123
func (m * SnapshotManager ) createSnapshot (height uint64 ) (root common.Hash ) {
134
124
135
- cidV1 , root , filePath := m .createShapshotForVersion (height , SnapshotVersionV1 )
136
- cidV2 , _ , filePath2 := m .createShapshotForVersion (height , SnapshotVersionV2 )
137
-
138
- if cidV1 != nil && cidV2 != nil {
139
- m .clearFs ([]string {filePath , filePath2 })
140
- m .writeLastManifest (cidV1 , cidV2 , root , height , filePath , filePath2 )
125
+ cidV2 , _ , filePath := m .createShapshotForVersion (height , SnapshotVersionV2 )
126
+ if cidV2 != nil {
127
+ m .clearFs ([]string {filePath })
128
+ m .writeLastManifest (cidV2 , root , height , filePath )
141
129
}
142
130
return root
143
131
}
144
132
145
133
func (m * SnapshotManager ) clearFs (excludedFiles []string ) {
146
- if prevCid , prevCidV2 , _ , _ , _ := m .repo .LastSnapshotManifest (); prevCid != nil {
147
- m .ipfs .Unpin (prevCid )
134
+ if prevCidV2 , _ , _ , _ := m .repo .LastSnapshotManifest (); prevCidV2 != nil {
148
135
m .ipfs .Unpin (prevCidV2 )
149
136
}
150
137
m .clearSnapshotFolder (excludedFiles )
@@ -182,16 +169,12 @@ func (m *SnapshotManager) clearSnapshotFolder(excludedFiles []string) {
182
169
}
183
170
}
184
171
185
- func (m * SnapshotManager ) writeLastManifest (snapshotCid [] byte , snapshotCidV2 []byte , root common.Hash , height uint64 , file string , fileV2 string ) {
186
- m .repo .WriteLastSnapshotManifest (snapshotCid , snapshotCidV2 , root , height , file , fileV2 )
172
+ func (m * SnapshotManager ) writeLastManifest (snapshotCidV2 []byte , root common.Hash , height uint64 , fileV2 string ) {
173
+ m .repo .WriteLastSnapshotManifest (snapshotCidV2 , root , height , fileV2 )
187
174
}
188
175
189
176
func (m * SnapshotManager ) DownloadSnapshot (snapshot * snapshot.Manifest ) (filePath string , version SnapshotVersion , err error ) {
190
177
version = SnapshotVersionV2
191
- if len (snapshot .CidV2 ) == 0 {
192
- version = SnapshotVersionV1
193
- }
194
-
195
178
filePath , file , err := createSnapshotFile (m .cfg .DataDir , snapshot .Height , version )
196
179
if err != nil {
197
180
return "" , 0 , err
@@ -219,13 +202,7 @@ func (m *SnapshotManager) DownloadSnapshot(snapshot *snapshot.Manifest) (filePat
219
202
done := make (chan struct {})
220
203
221
204
go func () {
222
- switch version {
223
- case SnapshotVersionV1 :
224
- loadToErr = m .ipfs .LoadTo (snapshot .Cid , file , ctx , onLoading )
225
- case SnapshotVersionV2 :
226
- loadToErr = m .ipfs .LoadTo (snapshot .CidV2 , file , ctx , onLoading )
227
- }
228
-
205
+ loadToErr = m .ipfs .LoadTo (snapshot .CidV2 , file , ctx , onLoading )
229
206
wg .Done ()
230
207
close (done )
231
208
}()
@@ -252,14 +229,12 @@ func (m *SnapshotManager) DownloadSnapshot(snapshot *snapshot.Manifest) (filePat
252
229
253
230
if loadToErr == nil {
254
231
m .clearFs ([]string {filePath })
255
- var filePath1 , filePath2 string
256
- if version == SnapshotVersionV1 {
257
- filePath1 = filePath
258
- }
232
+ var filePath2 string
233
+
259
234
if version == SnapshotVersionV2 {
260
235
filePath2 = filePath
261
236
}
262
- m .writeLastManifest (snapshot .Cid , snapshot . CidV2 , snapshot .Root , snapshot .Height , filePath1 , filePath2 )
237
+ m .writeLastManifest (snapshot .CidV2 , snapshot .Root , snapshot .Height , filePath2 )
263
238
}
264
239
265
240
return filePath , version , loadToErr
0 commit comments