Source Code Survey
This page provides a very high level, sometimes "pseudocode", view of error types and related messages as implemented by the NEAR platform.
Errors raised by the NEAR platform are implemented in the following locations in nearcore
:
RuntimeError and subtypes
RuntimeError
Definition
/// Error returned from `Runtime::apply`
pub enum RuntimeError {
/// An unexpected integer overflow occurred. The likely issue is an invalid state or the transition.
UnexpectedIntegerOverflow,
/// An error happened during TX verification and account charging. It's likely the chunk is invalid.
/// and should be challenged.
InvalidTxError(InvalidTxError),
/// Unexpected error which is typically related to the node storage corruption.account
/// That it's possible the input state is invalid or malicious.
StorageError(StorageError),
/// An error happens if `check_balance` fails, which is likely an indication of an invalid state.
BalanceMismatchError(BalanceMismatchError),
}
Error Messages
- see below:
InvalidTxError
,StorageError
andBalanceMismatchError
InvalidTxError
Definition
/// An error happened during TX execution
pub enum InvalidTxError {
/// Happens if a wrong AccessKey used or AccessKey has not enough permissions
InvalidAccessKeyError(InvalidAccessKeyError),
/// TX signer_id is not in a valid format or not satisfy requirements see `near_core::primitives::utils::is_valid_account_id`
InvalidSignerId { signer_id: AccountId },
/// TX signer_id is not found in a storage
SignerDoesNotExist { signer_id: AccountId },
/// Transaction nonce must be account[access_key].nonce + 1
InvalidNonce { tx_nonce: Nonce, ak_nonce: Nonce },
/// TX receiver_id is not in a valid format or not satisfy requirements see `near_core::primitives::utils::is_valid_account_id`
InvalidReceiverId { receiver_id: AccountId },
/// TX signature is not valid
InvalidSignature,
/// Account does not have enough balance to cover TX cost
NotEnoughBalance {
signer_id: AccountId,
balance: Balance,
cost: Balance,
},
/// Signer account rent is unpaid
RentUnpaid {
/// An account which is required to pay the rent
signer_id: AccountId,
/// Required balance to cover the state rent
amount: Balance,
},
/// An integer overflow occurred during transaction cost estimation.
CostOverflow,
/// Transaction parent block hash doesn't belong to the current chain
InvalidChain,
/// Transaction has expired
Expired,
/// An error occurred while validating actions of a Transaction.
ActionsValidation(ActionsValidationError),
}
Error Messages
InvalidTxError::InvalidSignerId { signer_id }
"Invalid signer account ID {:?} according to requirements"
InvalidTxError::SignerDoesNotExist { signer_id }
"Signer {:?} does not exist"
InvalidTxError::InvalidAccessKeyError(access_key_error)
InvalidTxError::InvalidNonce { tx_nonce, ak_nonce }
"Transaction nonce {} must be larger than nonce of the used access key {}"
InvalidTxError::InvalidReceiverId { receiver_id }
"Invalid receiver account ID {:?} according to requirements"
InvalidTxError::InvalidSignature
"Transaction is not signed with the given public key"
InvalidTxError::NotEnoughBalance { signer_id, balance, cost }
"Sender {:?} does not have enough balance {} for operation costing {}"
InvalidTxError::RentUnpaid { signer_id, amount }
"Failed to execute, because the account {:?} wouldn't have enough to pay required rent {}"
InvalidTxError::CostOverflow
"Transaction gas or balance cost is too high"
InvalidTxError::InvalidChain
"Transaction parent block hash doesn't belong to the current chain"
InvalidTxError::Expired
"Transaction has expired"
InvalidTxError::ActionsValidation(error)
"Transaction actions validation error: {}"
StorageError
Definition
pub enum StorageError {
/// Key-value db internal failure
StorageInternalError,
/// Storage is PartialStorage and requested a missing trie node
TrieNodeMissing,
/// Either invalid state or key-value db is corrupted.
/// For PartialStorage it cannot be corrupted.
/// Error message is unreliable and for debugging purposes only. It's also probably ok to
/// panic in every place that produces this error.
/// We can check if db is corrupted by verifying everything in the state trie.
StorageInconsistentState(String),
}
BalanceMismatchError
Definition
/// Happens when the input balance doesn't match the output balance in Runtime apply.
pub struct BalanceMismatchError {
// Input balances
pub incoming_validator_rewards: Balance,
pub initial_accounts_balance: Balance,
pub incoming_receipts_balance: Balance,
pub processed_delayed_receipts_balance: Balance,
pub initial_postponed_receipts_balance: Balance,
// Output balances
pub final_accounts_balance: Balance,
pub outgoing_receipts_balance: Balance,
pub new_delayed_receipts_balance: Balance,
pub final_postponed_receipts_balance: Balance,
pub total_rent_paid: Balance,
pub total_validator_reward: Balance,
pub total_balance_burnt: Balance,
pub total_balance_slashed: Balance,
}
Error Messages
"Balance Mismatch Error. The input balance {} doesn't match output balance {}\n\
Inputs:\n\
\tIncoming validator rewards sum: {}\n\
\tInitial accounts balance sum: {}\n\
\tIncoming receipts balance sum: {}\n\
\tProcessed delayed receipts balance sum: {}\n\
\tInitial postponed receipts balance sum: {}\n\
Outputs:\n\
\tFinal accounts balance sum: {}\n\
\tOutgoing receipts balance sum: {}\n\
\tNew delayed receipts balance sum: {}\n\
\tFinal postponed receipts balance sum: {}\n\
\tTotal rent paid: {}\n\
\tTotal validators reward: {}\n\
\tTotal balance burnt: {}\n\
\tTotal balance slashed: {}",