use derive_more::From;
use std::collections::BTreeMap;
use serde::Serialize;
use thiserror::Error;
use casper_execution_engine::engine_state::Error as EngineStateError;
use casper_storage::{
data_access_layer::{
forced_undelegate::ForcedUndelegateError, BlockRewardsError, FeeError, StepError,
},
global_state::error::Error as GlobalStateError,
tracking_copy::TrackingCopyError,
};
use casper_types::{bytesrepr, CLValueError, Digest, EraId, PublicKey, U512};
use crate::{
components::contract_runtime::ExecutionPreState,
types::{ChunkingError, ExecutableBlock, InternalEraReport},
};
#[derive(Debug, Error)]
pub(crate) enum StateResultError {
#[error("invalid state root hash")]
RootNotFound,
#[error("{0}")]
ValueNotFound(String),
#[error("{0}")]
Failure(TrackingCopyError),
}
#[derive(Debug, Error)]
pub(crate) enum ConfigError {
#[error("failed to initialize LMDB environment for contract runtime: {0}")]
GlobalState(#[from] GlobalStateError),
#[error("failed to initialize metrics for contract runtime: {0}")]
Prometheus(#[from] prometheus::Error),
}
#[derive(Debug, Error, From)]
pub(crate) enum ContractRuntimeError {
#[error("error deserializing id: {0}")]
InvalidSerializedId(#[source] bincode::Error),
#[error("error retrieving trie by id: {0}")]
FailedToRetrieveTrieById(#[source] GlobalStateError),
#[error("failed to chunk the data {0}")]
ChunkingError(#[source] ChunkingError),
}
#[derive(Debug, Error, Serialize)]
pub enum BlockExecutionError {
#[error("more than one execution result")]
MoreThanOneExecutionResult,
#[error(
"block's height does not agree with execution pre-state. \
block: {executable_block:?}, \
execution pre-state: {execution_pre_state:?}"
)]
WrongBlockHeight {
executable_block: Box<ExecutableBlock>,
execution_pre_state: Box<ExecutionPreState>,
},
#[error(transparent)]
EngineState(
#[from]
#[serde(skip_serializing)]
EngineStateError,
),
#[error(transparent)]
Step(
#[from]
#[serde(skip_serializing)]
StepError,
),
#[error(transparent)]
DistributeFees(
#[from]
#[serde(skip_serializing)]
FeeError,
),
#[error(transparent)]
DistributeBlockRewards(
#[from]
#[serde(skip_serializing)]
BlockRewardsError,
),
#[error(transparent)]
ForcedUndelegate(
#[from]
#[serde(skip_serializing)]
ForcedUndelegateError,
),
#[error("failed to compute approvals checksum: {0}")]
FailedToComputeApprovalsChecksum(bytesrepr::Error),
#[error("failed to compute execution results checksum: {0}")]
FailedToComputeExecutionResultsChecksum(bytesrepr::Error),
#[error("failed to convert the checksum registry to a clvalue: {0}")]
ChecksumRegistryToCLValue(CLValueError),
#[error(
"cannot create era end unless we have both an era report and next era validators. \
era report: {maybe_era_report:?}, \
next era validator weights: {maybe_next_era_validator_weights:?}"
)]
FailedToCreateEraEnd {
maybe_era_report: Option<InternalEraReport>,
maybe_next_era_validator_weights: Option<(BTreeMap<PublicKey, U512>, u8)>,
},
#[error(transparent)]
Lmdb(
#[from]
#[serde(skip_serializing)]
GlobalStateError,
),
#[error(transparent)]
GetEraValidators(
#[from]
#[serde(skip_serializing)]
TrackingCopyError,
),
#[error("Root state hash not found in global state.")]
RootNotFound(Digest),
#[error("Missing checksum registry")]
MissingChecksumRegistry,
#[error("Failed to get new era gas price when executing switch block")]
FailedToGetNewEraGasPrice { era_id: EraId },
#[error("Error while trying to set up payment for transaction: {0}")]
PaymentError(String),
#[error("Error while attempting to store block global data: {0}")]
BlockGlobal(String),
#[error("No switch block header available for era: {0}")]
NoSwitchBlockHash(u64),
#[error("Unsupported execution kind: {0}")]
UnsupportedTransactionKind(u8),
#[error("Error while converting transaction to internal representation: {0}")]
TransactionConversion(String),
#[error("Invalid gas limit amount: {0}")]
InvalidGasLimit(U512),
#[error("Invalid transaction variant")]
InvalidTransactionVariant,
#[error("Invalid transaction arguments")]
InvalidTransactionArgs,
#[error("Data Access Layer conflicts with chainspec setting: {0}")]
InvalidAESetting(bool),
}