1use ant_protocol::PrettyPrintRecordKey;
10use libp2p::PeerId;
11use thiserror::Error;
12
13pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
14
15const SCRATCHPAD_MAX_SIZE: usize = ant_protocol::storage::Scratchpad::MAX_SIZE;
16
17#[derive(Debug, Error)]
19#[allow(missing_docs)]
20pub enum PutValidationError {
21 #[error("Error while requesting data from the local swarm")]
22 LocalSwarmError,
23
24 #[error("The record header cannot be deserialized")]
25 InvalidRecordHeader,
26
27 #[error("The record cannot be deserialized to the expected type")]
28 InvalidRecord(PrettyPrintRecordKey<'static>),
29
30 #[error("The Record::key does not match with the key derived from Record::value")]
31 RecordKeyMismatch,
32
33 #[error("Failed to serialize the record")]
34 RecordSerializationFailed(PrettyPrintRecordKey<'static>),
35
36 #[error("The record did not contain any payments: {0:?}")]
38 NoPayment(PrettyPrintRecordKey<'static>),
39
40 #[error("Record should not be a `WithPayment` type: {0:?}")]
42 UnexpectedRecordWithPayment(PrettyPrintRecordKey<'static>),
43
44 #[error("Our node did not receive any payment for record: {0:?}")]
45 PaymentNotMadeToOurNode(PrettyPrintRecordKey<'static>),
46
47 #[error("The payment was made to an incorrect data type: {0:?}")]
48 PaymentMadeToIncorrectDataType(PrettyPrintRecordKey<'static>),
49
50 #[error(
51 "The payment quote has out of range payees for record: {record_key:?}. Payees: {payees:?}"
52 )]
53 PaymentQuoteOutOfRange {
54 record_key: PrettyPrintRecordKey<'static>,
55 payees: Vec<PeerId>,
56 },
57
58 #[error("Failed to verify payment with EVM network for record: {record_key:?}. Error: {error}")]
59 PaymentVerificationFailed {
60 record_key: PrettyPrintRecordKey<'static>,
61 error: ant_evm::payment_vault::error::Error,
62 },
63
64 #[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
66 OversizedChunk(usize, usize),
67
68 #[error("Rejected outdated record: with counter {counter}, expected any above {expected}")]
70 OutdatedRecordCounter { counter: u64, expected: u64 },
71
72 #[error("Scratchpad signature is invalid")]
73 InvalidScratchpadSignature,
74
75 #[error("Scratchpad too big: {0}, max size is {SCRATCHPAD_MAX_SIZE}")]
76 ScratchpadTooBig(usize),
77
78 #[error("There are no GraphEntries in the record: {0:?}")]
80 EmptyGraphEntry(PrettyPrintRecordKey<'static>),
81
82 #[error("Pointer signature is invalid")]
84 InvalidPointerSignature,
85}
86
87#[derive(Debug, Error)]
89#[allow(missing_docs)]
90pub enum Error {
91 #[error("Network error {0}")]
92 Network(#[from] crate::networking::NetworkError),
93
94 #[error("Failed to parse NodeEvent")]
95 NodeEventParsingFailed,
96
97 #[error("Failed to obtain node's current port")]
98 FailedToGetNodePort,
99
100 #[error("The content of the payment quote is invalid")]
102 InvalidQuoteContent,
103
104 #[error("The payment quote's signature is invalid")]
105 InvalidQuoteSignature,
106}