1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Protocol-specific error types
//!
//! This module defines error types for the protocol layer that wrap consensus errors
//! and add protocol-specific error context.
use crate::ProtocolVersion;
use std::borrow::Cow;
use thiserror::Error;
/// Protocol-specific error types
///
/// This enum wraps consensus errors and adds protocol-specific error types
/// for better error context through the protocol layer.
#[derive(Debug, Error, Clone, PartialEq)]
pub enum ProtocolError {
/// Consensus validation error (wrapped from consensus layer)
#[error("Consensus error: {0}")]
Consensus(#[from] blvm_consensus::error::ConsensusError),
/// Protocol validation failed (size limits, feature flags, etc.)
#[error("Protocol validation failed: {0}")]
Validation(Cow<'static, str>),
/// Feature not supported by this protocol version
#[error("Feature not supported: {0}")]
UnsupportedFeature(String),
/// Protocol version mismatch
#[error("Protocol version mismatch: expected {expected:?}, got {actual:?}")]
VersionMismatch {
expected: ProtocolVersion,
actual: ProtocolVersion,
},
/// Network parameter error
#[error("Network parameter error: {0}")]
NetworkParameter(Cow<'static, str>),
/// Configuration error
#[error("Configuration error: {0}")]
Configuration(Cow<'static, str>),
/// Message size exceeds protocol limits
#[error("Message size exceeds protocol limit: {size} bytes (max {max} bytes)")]
MessageTooLarge { size: usize, max: usize },
/// Invalid protocol message
#[error("Invalid protocol message: {0}")]
InvalidMessage(Cow<'static, str>),
/// Service flag error
#[error("Service flag error: {0}")]
ServiceFlag(Cow<'static, str>),
/// Serialization error
#[error("Serialization error: {0}")]
Serialization(String),
}
/// Protocol-specific Result type
pub type Result<T> = std::result::Result<T, ProtocolError>;