Skip to content

Commit

Permalink
refactor: modify ethereum rpc trait for hoku support
Browse files Browse the repository at this point in the history
modified EthRpc to be ChainInclusion and only return timestamp and root cid from chain. this required moving a decent amount of logic around parsing chain info/validation from service to validation crate.
  • Loading branch information
dav1do authored and stbrody committed Oct 21, 2024
1 parent f704ef4 commit b5c388b
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 291 deletions.
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

0 comments on commit b5c388b

Please sign in to comment.