Skip to main content

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 dropped due to local resource exhaustion (not sender's fault).
17    #[error("local overload: {0}")]
18    Overloaded(E),
19    /// Packet is decodable but cannot be processed due to other reasons.
20    ///
21    /// Such errors are protocol-related and packets must be acknowledged.
22    #[error("packet from {0} decodable, but cannot be processed: {1}")]
23    ProcessingError(OffchainPublicKey, E),
24    /// Packet is decodable, but the ticket is invalid.
25    #[error("packet from {0} is decodable, but the ticket is invalid: {1}")]
26    InvalidTicket(OffchainPublicKey, TicketValidationError),
27}
28
29/// Error that can occur when creating a ticket.
30#[derive(Debug, strum::EnumIs, strum::EnumTryAs, Error)]
31pub enum TicketCreationError<E: std::error::Error> {
32    #[error("channel {0} does not have at least {1} to create a ticket")]
33    OutOfFunds(ChannelId, HoprBalance),
34    #[error("could not create ticket: {0}")]
35    Other(E),
36}
37
38#[derive(Error, Debug)]
39pub enum HoprProtocolError {
40    #[error("packet is in invalid state: {0}")]
41    InvalidState(&'static str),
42
43    #[error("cannot decode the sender address of the packet")]
44    InvalidSender,
45
46    #[error("failed to resolve chain key or packet key")]
47    KeyNotFound,
48
49    #[error("channel {0} does not have at least {1} to create a ticket")]
50    OutOfFunds(ChannelId, HoprBalance),
51
52    #[error("packet replay detected")]
53    Replay,
54
55    #[error("failed to find channel {0} -> {1}")]
56    ChannelNotFound(Address, Address),
57
58    #[error("could not find unacknowledged ticket for challenge {0}")]
59    UnacknowledgedTicketNotFound(HalfKeyChallenge),
60
61    #[error("chain resolver error: {0}")]
62    ResolverError(#[source] anyhow::Error),
63
64    #[error("ticket tracker error: {0}")]
65    TicketTrackerError(#[source] anyhow::Error),
66
67    #[error(transparent)]
68    TicketValidationError(#[from] TicketValidationError),
69
70    #[error(transparent)]
71    CoreTypesError(#[from] hopr_internal_types::errors::CoreTypesError),
72
73    #[error(transparent)]
74    PacketError(#[from] hopr_crypto_packet::errors::PacketError),
75
76    #[error(transparent)]
77    GeneralError(#[from] hopr_primitive_types::errors::GeneralError),
78
79    #[error("rayon thread pool queue full: {0}")]
80    SpawnError(#[from] hopr_parallelize::cpu::SpawnError),
81}