casper_node/components/storage/
error.rs1use std::{fmt::Debug, io, path::PathBuf};
2
3use casper_binary_port::RecordId;
4use thiserror::Error;
5use tracing::error;
6
7use casper_types::{
8 bytesrepr, crypto, BlockBody, BlockHash, BlockHeader, BlockValidationError, DeployHash, Digest,
9 EraId, FinalitySignature, FinalitySignatureId, TransactionHash,
10};
11
12use crate::types::VariantMismatch;
13use casper_storage::block_store::BlockStoreError;
14
15#[derive(Debug, Error)]
20pub enum FatalStorageError {
21 #[error("failed to create database directory `{}`: {}", .0.display(), .1)]
23 CreateDatabaseDirectory(PathBuf, io::Error),
24 #[error("duplicate entries for switch block at era id {era_id}: {first} / {second}")]
26 DuplicateEraIdIndex {
27 era_id: EraId,
29 first: BlockHash,
31 second: BlockHash,
33 },
34 #[error("failed overwriting block")]
36 FailedToOverwriteBlock,
37 #[error("unable to find db for record: {0}")]
39 DatabaseNotFound(RecordId),
40 #[error("unable to move file {source_path} to {dest_path}: {original_error}")]
42 UnableToMoveFile {
43 source_path: PathBuf,
45 dest_path: PathBuf,
47 original_error: io::Error,
49 },
50 #[error("expected files to exist: {missing_files:?}.")]
52 MissingStorageFiles {
53 missing_files: Vec<PathBuf>,
55 },
56 #[error(transparent)]
58 BlockValidation(#[from] BlockValidationError),
59 #[error(
61 "Block header not stored under its hash. \
62 Queried block hash bytes: {queried_block_hash_bytes:x?}, \
63 Found block header hash bytes: {found_block_header_hash:x?}, \
64 Block header: {block_header}"
65 )]
66 BlockHeaderNotStoredUnderItsHash {
67 queried_block_hash_bytes: Vec<u8>,
69 found_block_header_hash: BlockHash,
71 block_header: Box<BlockHeader>,
73 },
74 #[error(
76 "No block header corresponding to block body found in LMDB. \
77 Block body hash: {block_body_hash:?}, \
78 Block body: {block_body:?}"
79 )]
80 NoBlockHeaderForBlockBody {
81 block_body_hash: Digest,
83 block_body: Box<BlockBody>,
85 },
86 #[error("{0} in signature verification. Database is corrupted.")]
88 SignatureVerification(crypto::Error),
89 #[error(
91 "Block signatures not indexed by their block hash. \
92 Key bytes in LMDB: {raw_key:x?}, \
93 Block hash bytes in record: {block_hash_bytes:x?}"
94 )]
95 CorruptedBlockSignatureIndex {
96 raw_key: Vec<u8>,
98 block_hash_bytes: Vec<u8>,
100 },
101 #[error("switch block does not contain era end: {0:?}")]
103 InvalidSwitchBlock(Box<BlockHeader>),
104 #[error(
106 "Found an unexpected part of a block body in the database: \
107 {part_hash:?}"
108 )]
109 UnexpectedBlockBodyPart {
110 block_body_hash: Digest,
112 part_hash: Digest,
114 },
115 #[error("failed to serialized stored item")]
117 StoredItemSerializationFailure(#[source] bincode::Error),
118 #[error("Tried to store FinalizedApprovals for a nonexistent transaction {transaction_hash}")]
120 UnexpectedFinalizedApprovals {
121 transaction_hash: TransactionHash,
123 },
124 #[error("unexpected serialization failure: {0}")]
126 UnexpectedSerializationFailure(bytesrepr::Error),
127 #[error("unexpected deserialization failure: {0}")]
129 UnexpectedDeserializationFailure(bytesrepr::Error),
130 #[error(
132 "stored finalized approvals hashes count doesn't match number of deploys: \
133 block hash: {block_hash}, expected: {expected}, actual: {actual}"
134 )]
135 ApprovalsHashesLengthMismatch {
136 block_hash: BlockHash,
138 expected: usize,
140 actual: usize,
142 },
143 #[error(
145 "stored v1 execution results doesn't have exactly one entry: deploy: {deploy_hash}, number \
146 of entries: {results_length}"
147 )]
148 InvalidExecutionResultsV1Length {
149 deploy_hash: DeployHash,
151 results_length: usize,
153 },
154 #[error("failed to initialize metrics for storage: {0}")]
156 Prometheus(#[from] prometheus::Error),
157 #[error(transparent)]
159 VariantMismatch(#[from] VariantMismatch),
160 #[error(transparent)]
162 BlockStoreError(#[from] BlockStoreError),
163 #[error("unexpected record id {0}")]
165 UnexpectedRecordId(RecordId),
166}
167
168impl From<Box<BlockValidationError>> for FatalStorageError {
169 fn from(err: Box<BlockValidationError>) -> Self {
170 Self::BlockValidation(*err)
171 }
172}
173
174#[derive(Debug, Error)]
178pub(super) enum GetRequestError {
179 #[error(transparent)]
181 Fatal(#[from] FatalStorageError),
182 #[error("failed to deserialize incoming item id")]
184 MalformedIncomingItemId(#[source] bincode::Error),
185 #[error(
186 "id information not matching the finality signature: \
187 requested id: {requested_id},\
188 signature: {finality_signature}"
189 )]
190 FinalitySignatureIdMismatch {
191 requested_id: Box<FinalitySignatureId>,
193 finality_signature: Box<FinalitySignature>,
195 },
196}