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
use std::collections::BTreeMap;
use thiserror::Error;
use casper_hashing::Digest;
use casper_types::{bytesrepr, PublicKey, U512};
use crate::types::{block::EraReport, Block, BlockHash};
#[derive(Error, Debug)]
pub enum BlockCreationError {
#[error(
"Cannot create EraEnd unless we have both an EraReport and next era validators. \
Era report: {maybe_era_report:?}, \
Next era validator weights: {maybe_next_era_validator_weights:?}"
)]
CouldNotCreateEraEnd {
maybe_era_report: Option<EraReport>,
maybe_next_era_validator_weights: Option<BTreeMap<PublicKey, U512>>,
},
}
#[derive(Error, Debug)]
pub enum BlockValidationError {
#[error("{0}")]
BytesReprError(bytesrepr::Error),
#[error(
"Block header has incorrect body hash. \
Actual block body hash: {actual_block_body_hash:?}, \
Block: {block:?}"
)]
UnexpectedBodyHash {
block: Box<Block>,
actual_block_body_hash: Digest,
},
#[error(
"Block has incorrect block hash. \
Actual block body hash: {actual_block_header_hash:?}, \
Block: {block:?}"
)]
UnexpectedBlockHash {
block: Box<Block>,
actual_block_header_hash: BlockHash,
},
}
impl From<bytesrepr::Error> for BlockValidationError {
fn from(error: bytesrepr::Error) -> Self {
BlockValidationError::BytesReprError(error)
}
}