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

refactor: modify eth rpc trait for other chains #550

Merged
merged 1 commit into from
Oct 22, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sync_test.sh

openapi-generator-cli.jar
.env
ceramic_cicddb.sqlite*
ceramic_cicddb.sqlite*
event-svc/model_error_counts.csv
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion event-svc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ itertools.workspace = true
multihash-codetable.workspace = true
multihash-derive.workspace = true
multihash.workspace = true
once_cell.workspace = true
prometheus-client.workspace = true
recon.workspace = true
serde.workspace = true
Expand Down
35 changes: 24 additions & 11 deletions event-svc/src/event/validator/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use ceramic_core::{Cid, EventId, NodeId};
use ceramic_event::unvalidated;
use ceramic_validation::eth_rpc;
use ipld_core::ipld::Ipld;
use recon::ReconItem;
use tokio::try_join;
Expand All @@ -14,7 +15,7 @@ use crate::{
validator::{
grouped::{GroupedEvents, SignedValidationBatch, TimeValidationBatch},
signed::SignedEventValidator,
time::{ChainInclusionError, TimeEventValidator},
time::TimeEventValidator,
},
},
store::EventInsertable,
Expand Down Expand Up @@ -226,37 +227,49 @@ impl EventValidator {
}

/// Transforms the [`ChainInclusionError`] into a [`ValidationError`] with an appropriate message
fn convert_inclusion_error(err: ChainInclusionError, order_key: &EventId) -> ValidationError {
fn convert_inclusion_error(err: eth_rpc::Error, order_key: &EventId) -> ValidationError {
match err {
ChainInclusionError::TxNotFound { chain_id, tx_hash } => {
eth_rpc::Error::TxNotFound { chain_id, tx_hash } => {
// we have an RPC provider so the transaction missing means it's invalid/unproveable
ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!(
"Transaction on chain '{chain_id}' with hash '{tx_hash}' not found."
),
}
}
ChainInclusionError::TxNotMined { chain_id, tx_hash } => {
},
eth_rpc::Error::TxNotMined { chain_id, tx_hash } => {
ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!("Transaction on chain '{chain_id}' with hash '{tx_hash}' has not been mined in a block yet."),
}
}
ChainInclusionError::InvalidProof(reason) => ValidationError::InvalidTimeProof {
},
eth_rpc::Error::InvalidProof(reason) => ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason,
},
ChainInclusionError::NoChainProvider(chain_id) => {
eth_rpc::Error::NoChainProvider(chain_id) => {
ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!("No RPC provider for chain '{chain_id}'. Transaction for event cannot be verified."),
}
}
ChainInclusionError::Error(error) => ValidationError::InvalidTimeProof {
},
eth_rpc::Error::InvalidArgument(e) => ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: error.to_string(),
reason: format!("Invalid argument: {}", e),
},
eth_rpc::Error::BlockNotFound { chain_id, block_hash } => ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!("Block not found on chain {} with hash: {}", chain_id, block_hash)
},
eth_rpc::Error::Transient(error) => ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!("transient error encountered talking to eth rpc: {error}")
},
eth_rpc::Error::Application(error) => ValidationError::InvalidTimeProof {
key: order_key.to_owned(),
reason: format!("application error encountered: {error}")
}
}
}
}
Expand Down
Loading
Loading