@@ -92,39 +92,35 @@ impl SnapshotDownloadCommand {
92
92
. await ?
93
93
. with_context ( || format ! ( "Can not get the snapshot for digest: '{}'" , self . digest) ) ?;
94
94
95
- SnapshotDownloadCommand :: check_local_disk_info (
96
- 1 ,
97
- & progress_printer,
98
- & db_dir,
99
- & snapshot_message,
100
- ) ?;
95
+ Self :: check_local_disk_info ( 1 , & progress_printer, & db_dir, & snapshot_message) ?;
101
96
102
- let certificate = SnapshotDownloadCommand :: fetching_certificate_and_verifying_chain (
97
+ let certificate = Self :: fetch_certificate_and_verifying_chain (
103
98
2 ,
104
99
& progress_printer,
105
100
& client,
106
- & snapshot_message,
101
+ & snapshot_message. certificate_hash ,
107
102
)
108
103
. await ?;
109
104
110
- SnapshotDownloadCommand :: downloading_and_unpacking_snapshot (
105
+ Self :: download_and_unpack_snapshot (
111
106
3 ,
112
107
& progress_printer,
113
108
& client,
114
109
& snapshot_message,
115
110
& db_dir,
116
111
)
117
- . await ?;
112
+ . await
113
+ . with_context ( || {
114
+ format ! (
115
+ "Can not get download and unpack snapshot for digest: '{}'" ,
116
+ self . digest
117
+ )
118
+ } ) ?;
118
119
119
- let message = SnapshotDownloadCommand :: computing_snapshot_digest (
120
- 4 ,
121
- & progress_printer,
122
- & certificate,
123
- & db_dir,
124
- )
125
- . await ?;
120
+ let message =
121
+ Self :: compute_snapshot_message ( 4 , & progress_printer, & certificate, & db_dir) . await ?;
126
122
127
- SnapshotDownloadCommand :: verifying_snapshot_signature (
123
+ Self :: verify_snapshot_signature (
128
124
5 ,
129
125
& progress_printer,
130
126
& certificate,
@@ -133,7 +129,7 @@ impl SnapshotDownloadCommand {
133
129
)
134
130
. await ?;
135
131
136
- SnapshotDownloadCommand :: log_download_information ( & db_dir, & snapshot_message, self . json ) ?;
132
+ Self :: log_download_information ( & db_dir, & snapshot_message, self . json ) ?;
137
133
138
134
Ok ( ( ) )
139
135
}
@@ -142,13 +138,13 @@ impl SnapshotDownloadCommand {
142
138
step_number : u16 ,
143
139
progress_printer : & ProgressPrinter ,
144
140
db_dir : & PathBuf ,
145
- snapshot_message : & Snapshot ,
141
+ snapshot : & Snapshot ,
146
142
) -> StdResult < ( ) > {
147
143
progress_printer. report_step ( step_number, "Checking local disk info…" ) ?;
148
144
if let Err ( e) = SnapshotUnpacker :: check_prerequisites (
149
145
db_dir,
150
- snapshot_message . size ,
151
- snapshot_message . compression_algorithm . unwrap_or_default ( ) ,
146
+ snapshot . size ,
147
+ snapshot . compression_algorithm . unwrap_or_default ( ) ,
152
148
) {
153
149
progress_printer
154
150
. report_step ( step_number, & SnapshotUtils :: check_disk_space_error ( e) ?) ?;
@@ -164,52 +160,43 @@ impl SnapshotDownloadCommand {
164
160
Ok ( ( ) )
165
161
}
166
162
167
- async fn fetching_certificate_and_verifying_chain (
163
+ async fn fetch_certificate_and_verifying_chain (
168
164
step_number : u16 ,
169
165
progress_printer : & ProgressPrinter ,
170
166
client : & Client ,
171
- snapshot_message : & Snapshot ,
167
+ certificate_hash : & str ,
172
168
) -> StdResult < MithrilCertificate > {
173
169
progress_printer. report_step (
174
170
step_number,
175
171
"Fetching the certificate and verifying the certificate chain…" ,
176
172
) ?;
177
173
let certificate = client
178
174
. certificate ( )
179
- . verify_chain ( & snapshot_message . certificate_hash )
175
+ . verify_chain ( certificate_hash)
180
176
. await
181
177
. with_context ( || {
182
178
format ! (
183
179
"Can not verify the certificate chain from certificate_hash: '{}'" ,
184
- snapshot_message . certificate_hash
180
+ certificate_hash
185
181
)
186
182
} ) ?;
187
183
188
184
Ok ( certificate)
189
185
}
190
186
191
- async fn downloading_and_unpacking_snapshot (
187
+ async fn download_and_unpack_snapshot (
192
188
step_number : u16 ,
193
189
progress_printer : & ProgressPrinter ,
194
190
client : & Client ,
195
- snapshot_message : & Snapshot ,
191
+ snapshot : & Snapshot ,
196
192
db_dir : & Path ,
197
193
) -> StdResult < ( ) > {
198
194
progress_printer. report_step ( step_number, "Downloading and unpacking the snapshot…" ) ?;
199
- client
200
- . snapshot ( )
201
- . download_unpack ( snapshot_message, db_dir)
202
- . await
203
- . with_context ( || {
204
- format ! (
205
- "Snapshot Service can not download and verify the snapshot for digest: '{}'" ,
206
- snapshot_message. digest
207
- )
208
- } ) ?;
195
+ client. snapshot ( ) . download_unpack ( snapshot, db_dir) . await ?;
209
196
210
197
// The snapshot download does not fail if the statistic call fails.
211
198
// It would be nice to implement tests to verify the behavior of `add_statistics`
212
- if let Err ( e) = client. snapshot ( ) . add_statistics ( snapshot_message ) . await {
199
+ if let Err ( e) = client. snapshot ( ) . add_statistics ( snapshot ) . await {
213
200
warn ! ( "Could not increment snapshot download statistics: {e:?}" ) ;
214
201
}
215
202
@@ -224,13 +211,13 @@ impl SnapshotDownloadCommand {
224
211
Ok ( ( ) )
225
212
}
226
213
227
- async fn computing_snapshot_digest (
214
+ async fn compute_snapshot_message (
228
215
step_number : u16 ,
229
216
progress_printer : & ProgressPrinter ,
230
217
certificate : & MithrilCertificate ,
231
218
db_dir : & Path ,
232
219
) -> StdResult < ProtocolMessage > {
233
- progress_printer. report_step ( step_number, "Computing the snapshot digest… " ) ?;
220
+ progress_printer. report_step ( step_number, "Computing the snapshot message " ) ?;
234
221
let message = SnapshotUtils :: wait_spinner (
235
222
progress_printer,
236
223
MessageBuilder :: new ( ) . compute_snapshot_message ( certificate, db_dir) ,
@@ -246,20 +233,20 @@ impl SnapshotDownloadCommand {
246
233
Ok ( message)
247
234
}
248
235
249
- async fn verifying_snapshot_signature (
236
+ async fn verify_snapshot_signature (
250
237
step_number : u16 ,
251
238
progress_printer : & ProgressPrinter ,
252
239
certificate : & MithrilCertificate ,
253
240
message : & ProtocolMessage ,
254
- snapshot_message : & Snapshot ,
241
+ snapshot : & Snapshot ,
255
242
) -> StdResult < ( ) > {
256
243
progress_printer. report_step ( step_number, "Verifying the snapshot signature…" ) ?;
257
244
if !certificate. match_message ( message) {
258
245
debug ! ( "Digest verification failed, removing unpacked files & directory." ) ;
259
246
260
247
return Err ( anyhow ! (
261
248
"Certificate verification failed (snapshot digest = '{}')." ,
262
- snapshot_message . digest. clone( )
249
+ snapshot . digest. clone( )
263
250
) ) ;
264
251
}
265
252
@@ -268,7 +255,7 @@ impl SnapshotDownloadCommand {
268
255
269
256
fn log_download_information (
270
257
db_dir : & Path ,
271
- snapshot_message : & Snapshot ,
258
+ snapshot : & Snapshot ,
272
259
json_output : bool ,
273
260
) -> StdResult < ( ) > {
274
261
let canonicalized_filepath = & db_dir. canonicalize ( ) . with_context ( || {
@@ -285,24 +272,26 @@ impl SnapshotDownloadCommand {
285
272
canonicalized_filepath. display( )
286
273
) ;
287
274
} else {
275
+ let cardano_node_version = snapshot
276
+ . cardano_node_version
277
+ . clone ( )
278
+ . unwrap_or ( "latest" . to_string ( ) ) ;
288
279
println ! (
289
280
r###"Snapshot '{}' has been unpacked and successfully checked against Mithril multi-signature contained in the certificate.
290
281
291
282
Files in the directory '{}' can be used to run a Cardano node with version >= {}.
292
283
293
284
If you are using Cardano Docker image, you can restore a Cardano Node with:
294
285
295
- docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source="{}",target=/data/db/ -e NETWORK={} inputoutput/cardano-node:8.1.2
286
+ docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source="{}",target=/data/db/ -e NETWORK={} inputoutput/cardano-node:{}
296
287
297
288
"### ,
298
- snapshot_message . digest,
289
+ snapshot . digest,
299
290
db_dir. display( ) ,
300
- snapshot_message
301
- . cardano_node_version
302
- . clone( )
303
- . unwrap_or( "latest" . to_string( ) ) ,
291
+ cardano_node_version,
304
292
canonicalized_filepath. display( ) ,
305
- snapshot_message. beacon. network,
293
+ snapshot. beacon. network,
294
+ cardano_node_version
306
295
) ;
307
296
}
308
297
0 commit comments