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 #[error("Failed to verify Merkle payment for record: {record_key:?}. Error: {error}")]
88 MerklePaymentVerificationFailed {
89 record_key: PrettyPrintRecordKey<'static>,
90 error: String,
91 },
92
93 #[error(
94 "Topology verification failed: only {valid_count}/{total_paid} paid nodes in closest {closest_count}"
95 )]
96 TopologyVerificationFailed {
97 target_address: ant_protocol::NetworkAddress,
99 valid_count: usize,
101 total_paid: usize,
103 closest_count: usize,
105 node_peers: Vec<PeerId>,
107 paid_peers: Vec<PeerId>,
109 },
110}
111
112#[derive(Debug, Error)]
114#[allow(missing_docs)]
115pub enum Error {
116 #[error("Network error {0}")]
117 Network(#[from] crate::networking::NetworkError),
118
119 #[error("Failed to parse NodeEvent")]
120 NodeEventParsingFailed,
121
122 #[error("Failed to obtain node's current port")]
123 FailedToGetNodePort,
124
125 #[error("The content of the payment quote is invalid")]
127 InvalidQuoteContent,
128
129 #[error("The payment quote's signature is invalid")]
130 InvalidQuoteSignature,
131}