snarkvm_ledger_block/header/metadata/
verify.rs1#![allow(clippy::too_many_arguments)]
17
18use super::*;
19
20impl<N: Network> Metadata<N> {
21 pub fn verify(
23 &self,
24 expected_round: u64,
25 expected_height: u32,
26 expected_cumulative_weight: u128,
27 expected_cumulative_proof_target: u128,
28 expected_coinbase_target: u64,
29 expected_proof_target: u64,
30 expected_last_coinbase_target: u64,
31 expected_last_coinbase_timestamp: i64,
32 expected_timestamp: i64,
33 current_timestamp: i64,
34 ) -> Result<()> {
35 ensure!(self.is_valid(), "Metadata is malformed in block {expected_height}");
37 ensure!(
39 self.round == expected_round,
40 "Round is incorrect in block {expected_height} (found '{}', expected '{}')",
41 self.round,
42 expected_round
43 );
44 ensure!(
46 self.height == expected_height,
47 "Height is incorrect in block {expected_height} (found '{}', expected '{}')",
48 self.height,
49 expected_height
50 );
51 ensure!(
53 self.cumulative_weight == expected_cumulative_weight,
54 "Cumulative weight is incorrect in block {expected_height} (found '{}', expected '{}')",
55 self.cumulative_weight,
56 expected_cumulative_weight
57 );
58 ensure!(
60 self.cumulative_proof_target == expected_cumulative_proof_target,
61 "Cumulative proof target is incorrect in block {expected_height} (found '{}', expected '{}')",
62 self.cumulative_proof_target,
63 expected_cumulative_proof_target
64 );
65 ensure!(
67 self.coinbase_target == expected_coinbase_target,
68 "Coinbase target is incorrect in block {expected_height} (found '{}', expected '{}')",
69 self.coinbase_target,
70 expected_coinbase_target
71 );
72 ensure!(
74 self.proof_target == expected_proof_target,
75 "Proof target is incorrect in block {expected_height} (found '{}', expected '{}')",
76 self.proof_target,
77 expected_proof_target
78 );
79 ensure!(
81 self.last_coinbase_target == expected_last_coinbase_target,
82 "Last coinbase target is incorrect in block {expected_height} (found '{}', expected '{}')",
83 self.last_coinbase_target,
84 expected_last_coinbase_target
85 );
86 ensure!(
88 self.last_coinbase_timestamp == expected_last_coinbase_timestamp,
89 "Last coinbase timestamp is incorrect in block {expected_height} (found '{}', expected '{}')",
90 self.last_coinbase_timestamp,
91 expected_last_coinbase_timestamp
92 );
93 ensure!(
95 self.timestamp == expected_timestamp,
96 "Timestamp is incorrect in block {expected_height} (found '{}', expected '{}')",
97 self.timestamp,
98 expected_timestamp
99 );
100 ensure!(
102 self.timestamp <= current_timestamp,
103 "Timestamp is in the future in block {expected_height} (found '{}', expected before '{}')",
104 self.timestamp,
105 current_timestamp
106 );
107 Ok(())
109 }
110}