cfxcore/pos/state_sync/
error.rs1use diem_types::transaction::Version;
9use futures::channel::{mpsc::SendError, oneshot::Canceled};
10use serde::{Deserialize, Serialize};
12use thiserror::Error;
13
14#[derive(Clone, Debug, Deserialize, Error, PartialEq, Serialize)]
15pub enum Error {
16 #[error("Failed to send callback: {0}")]
17 CallbackSendFailed(String),
18 #[error("Consensus is executing. There is no need for state sync to drive synchronization.")]
19 ConsensusIsExecuting,
20 #[error(
21 "A sync request was sent to a full node, but this isn't supported."
22 )]
23 FullNodeSyncRequest,
24 #[error("An integer overflow has occurred: {0}")]
25 IntegerOverflow(String),
26 #[error("Received an invalid chunk request: {0}")]
27 InvalidChunkRequest(String),
28 #[error(
29 "Unable to add peer as they are not a valid state sync peer: {0}. Connection origin: {1}"
30 )]
31 InvalidStateSyncPeer(String, String),
32 #[error("No peers are currently available: {0}")]
35 NoAvailablePeers(String),
36 #[error("No sync request was issued by consensus: {0}")]
37 NoSyncRequestFound(String),
38 #[error(
39 "No transactions were committed, but received a commit notification!"
40 )]
41 NoTransactionsCommitted,
42 #[error("Received an old sync request for version {0}, but our known version is: {1}")]
43 OldSyncRequestVersion(Version, Version),
44 #[error("Processed an invalid chunk! Failed to apply the chunk: {0}")]
45 ProcessInvalidChunk(String),
46 #[error(
47 "Received a chunk for an outdated request from peer {0}. Known version: {1}, received: {2}"
48 )]
49 ReceivedChunkForOutdatedRequest(String, String, String),
50 #[error("Received a chunk response from a downstream peer: {0}")]
51 ReceivedChunkFromDownstream(String),
52 #[error("Received an empty chunk response from a peer: {0}")]
53 ReceivedEmptyChunk(String),
54 #[error("Receivd a non-sequential chunk from {0}. Known version: {1}, received: {2}")]
55 ReceivedNonSequentialChunk(String, String, String),
56 #[error("Received an unexpected chunk type: {0}")]
57 ReceivedWrongChunkType(String),
58 #[error("Received a oneshot::canceled event as the sender of a channel was dropped: {0}")]
59 SenderDroppedError(String),
60 #[error("Synced beyond the target version. Synced version: {0}, target version: {1}")]
61 SyncedBeyondTarget(Version, Version),
62 #[error("State sync is uninitialized! Error: {0}")]
63 UninitializedError(String),
64 #[error("Unexpected error: {0}")]
65 UnexpectedError(String),
66}
67
68impl From<SendError> for Error {
76 fn from(error: SendError) -> Self {
77 Error::UnexpectedError(error.to_string())
78 }
79}
80
81impl From<Canceled> for Error {
82 fn from(canceled: Canceled) -> Self {
83 Error::SenderDroppedError(canceled.to_string())
84 }
85}