hopr_protocol_hopr/
errors.rs

1use hopr_api::Address;
2use hopr_crypto_packet::errors::TicketValidationError;
3use hopr_crypto_types::{prelude::HalfKeyChallenge, types::OffchainPublicKey};
4use hopr_internal_types::prelude::ChannelId;
5use hopr_primitive_types::balance::HoprBalance;
6use thiserror::Error;
7
8/// Error that can occur when processing an incoming packet.
9#[derive(Debug, strum::EnumIs, strum::EnumTryAs, Error)]
10pub enum IncomingPacketError<E: std::error::Error> {
11    /// Packet is not decodable.
12    ///
13    /// Such errors are fatal and therefore the packet cannot be acknowledged.
14    #[error("packet is not decodable: {0}")]
15    Undecodable(E),
16    /// Packet is decodable but cannot be processed due to other reasons.
17    ///
18    /// Such errors are protocol-related and packets must be acknowledged.
19    #[error("packet from {0} decodable, but cannot be processed: {1}")]
20    ProcessingError(OffchainPublicKey, E),
21    /// Packet is decodable, but the ticket is invalid.
22    #[error("packet from {0} is decodable, but the ticket is invalid: {1}")]
23    InvalidTicket(OffchainPublicKey, TicketValidationError),
24}
25
26/// Error that can occur when creating a ticket.
27#[derive(Debug, strum::EnumIs, strum::EnumTryAs, Error)]
28pub enum TicketCreationError<E: std::error::Error> {
29    #[error("channel {0} does not have at least {1} to create a ticket")]
30    OutOfFunds(ChannelId, HoprBalance),
31    #[error("could not create ticket: {0}")]
32    Other(E),
33}
34
35#[derive(Error, Debug)]
36pub enum HoprProtocolError {
37    #[error("packet is in invalid state: {0}")]
38    InvalidState(&'static str),
39
40    #[error("cannot decode the sender address of the packet")]
41    InvalidSender,
42
43    #[error("failed to resolve chain key or packet key")]
44    KeyNotFound,
45
46    #[error("channel {0} does not have at least {1} to create a ticket")]
47    OutOfFunds(ChannelId, HoprBalance),
48
49    #[error("packet replay detected")]
50    Replay,
51
52    #[error("failed to find channel {0} -> {1}")]
53    ChannelNotFound(Address, Address),
54
55    #[error("could not find unacknowledged ticket for challenge {0}")]
56    UnacknowledgedTicketNotFound(HalfKeyChallenge),
57
58    #[error("chain resolver error: {0}")]
59    ResolverError(anyhow::Error),
60
61    #[error("ticket tracker error: {0}")]
62    TicketTrackerError(anyhow::Error),
63
64    #[error(transparent)]
65    TicketValidationError(#[from] TicketValidationError),
66
67    #[error(transparent)]
68    CoreTypesError(#[from] hopr_internal_types::errors::CoreTypesError),
69
70    #[error(transparent)]
71    PacketError(#[from] hopr_crypto_packet::errors::PacketError),
72
73    #[error(transparent)]
74    GeneralError(#[from] hopr_primitive_types::errors::GeneralError),
75}