1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::storage::FileHandle;
use anyhow::{ensure, Result};
use diem_types::transaction::Version;
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
pub struct TransactionChunk {
pub first_version: Version,
pub last_version: Version,
pub transactions: FileHandle,
pub proof: FileHandle,
}
#[derive(Deserialize, Serialize)]
pub struct TransactionBackup {
pub first_version: Version,
pub last_version: Version,
pub chunks: Vec<TransactionChunk>,
}
impl TransactionBackup {
pub fn verify(&self) -> Result<()> {
ensure!(
self.first_version <= self.last_version,
"Bad version range: [{}, {}]",
self.first_version,
self.last_version,
);
ensure!(!self.chunks.is_empty(), "No chunks.");
let mut next_version = self.first_version;
for chunk in &self.chunks {
ensure!(
chunk.first_version == next_version,
"Chunk ranges not continuous. Expected first version: {}, actual: {}.",
next_version,
chunk.first_version,
);
ensure!(
chunk.last_version >= chunk.first_version,
"Chunk range invalid. [{}, {}]",
chunk.first_version,
chunk.last_version,
);
next_version = chunk.last_version + 1;
}
ensure!(
next_version - 1 == self.last_version, "Last version in chunks: {}, in manifest: {}",
next_version - 1,
self.last_version,
);
Ok(())
}
}