Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove bytearray conversion #6777

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions base_layer/core/src/chain_storage/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ pub enum ChainStorageError {
InvalidChainMetaData(#[from] ChainMetaDataError),
#[error("Block header error: `{0}`")]
MrHashError(#[from] MrHashError),
#[error("Invalid Transaction: {0}")]
ByteArrayError(#[from] ByteArrayError),
#[error("Invalid Serialized Public key: {0}")]
InvalidSerializedPublicKey(String),
}

impl ChainStorageError {
Expand All @@ -167,7 +167,7 @@ impl ChainStorageError {
err @ ChainStorageError::MismatchedMmrRoot(_) |
err @ ChainStorageError::TransactionError(_) |
err @ ChainStorageError::SMTError(_) |
err @ ChainStorageError::ByteArrayError(_) => Some(BanReason {
err @ ChainStorageError::InvalidSerializedPublicKey(_) => Some(BanReason {
reason: err.to_string(),
ban_duration: BanPeriod::Long,
}),
Expand Down Expand Up @@ -206,6 +206,12 @@ impl ChainStorageError {
}
}

impl From<ByteArrayError> for ChainStorageError {
fn from(err: ByteArrayError) -> Self {
Self::InvalidSerializedPublicKey(err.to_string())
}
}

impl From<task::JoinError> for ChainStorageError {
fn from(err: task::JoinError) -> Self {
Self::BlockingTaskSpawnError(err.to_string())
Expand Down
12 changes: 9 additions & 3 deletions base_layer/core/src/validation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub enum ValidationError {
DifficultyError(#[from] DifficultyError),
#[error("Covenant too large. Max size: {max_size}, Actual size: {actual_size}")]
CovenantTooLarge { max_size: usize, actual_size: usize },
#[error("Invalid Transaction: {0}")]
ByteArrayError(#[from] ByteArrayError),
#[error("Invalid Serialized Public key: {0}")]
InvalidSerializedPublicKey(String),
}

// ChainStorageError has a ValidationError variant, so to prevent a cyclic dependency we use a string representation in
Expand All @@ -147,6 +147,12 @@ impl From<ChainStorageError> for ValidationError {
}
}

impl From<ByteArrayError> for ValidationError {
fn from(err: ByteArrayError) -> Self {
Self::InvalidSerializedPublicKey(err.to_string())
}
}

impl ValidationError {
pub fn get_ban_reason(&self) -> Option<BanReason> {
match self {
Expand Down Expand Up @@ -188,7 +194,7 @@ impl ValidationError {
err @ ValidationError::DifficultyError(_) |
err @ ValidationError::CoinbaseExceedsMaxLimit |
err @ ValidationError::CovenantTooLarge { .. } |
err @ ValidationError::ByteArrayError(_) => Some(BanReason {
err @ ValidationError::InvalidSerializedPublicKey(_) => Some(BanReason {
reason: err.to_string(),
ban_duration: BanPeriod::Long,
}),
Expand Down
Loading