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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
crate::ix!();
#[derive(Default)]
pub struct BlockValidationState {
base: ValidationState<BlockValidationResult>,
}
impl BlockValidationState {
delegate! {
to self.base {
pub fn invalid(&mut self,
result: BlockValidationResult,
reject_reason: Option<&str>,
debug_message: Option<&str>) -> bool;
pub fn error(&mut self, reject_reason: &String) -> bool;
pub fn is_valid(&self) -> bool;
pub fn is_invalid(&self) -> bool;
pub fn is_error(&self) -> bool;
pub fn get_result(&self) -> BlockValidationResult;
pub fn get_reject_reason(&self) -> String;
pub fn get_debug_message(&self) -> String;
pub fn to_string(&self) -> String;
}
}
}
impl Default for BlockValidationResult {
fn default() -> Self {
BlockValidationResult::BLOCK_RESULT_UNSET
}
}
/**
| A "reason" why a block was invalid, suitable
| for determining whether the provider
| of the block should be banned/ignored/disconnected/etc.
|
| These are much more granular than the
| rejection codes, which may be more useful
| for some other use-cases.
|
*/
#[derive(PartialEq,Eq,Clone,Debug)]
pub enum BlockValidationResult {
/**
| initial value. Block has not yet been
| rejected
|
*/
BLOCK_RESULT_UNSET = 0,
/**
| invalid by consensus rules (excluding
| any below reasons)
|
*/
BLOCK_CONSENSUS,
/**
| Invalid by a change to consensus rules
| more recent than SegWit.
|
| Currently unused as there are no such
| consensus rule changes, and any download
| sources realistically need to support
| SegWit in order to provide useful data,
| so differentiating between always-invalid
| and invalid-by-pre-SegWit-soft-fork
| is uninteresting.
|
*/
BLOCK_RECENT_CONSENSUS_CHANGE,
/**
| this block was cached as being invalid
| and we didn't store the reason why
|
*/
BLOCK_CACHED_INVALID,
/**
| invalid proof of work or time too old
|
*/
BLOCK_INVALID_HEADER,
/**
| the block's data didn't match the data
| committed to by the PoW
|
*/
BLOCK_MUTATED,
/**
| We don't have the previous block the
| checked one is built on
|
*/
BLOCK_MISSING_PREV,
/**
| A block this one builds on is invalid
|
*/
BLOCK_INVALID_PREV,
/**
| block timestamp was > 2 hours in the future
| (or our clock is bad)
|
*/
BLOCK_TIME_FUTURE,
/**
| the block failed to meet one of our checkpoints
|
*/
BLOCK_CHECKPOINT,
}