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

Historical evm events #173

Merged
merged 31 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
31caef4
Failing test for historical events
ryardley Nov 3, 2024
08b0b76
Tidy up use statements
ryardley Nov 3, 2024
2e346bd
EVM Contracts listen for both live and historical events
ryardley Nov 3, 2024
69c1fa1
Format
ryardley Nov 3, 2024
6b65f03
Format
ryardley Nov 3, 2024
37de0f8
Cache processed event_ids
ryardley Nov 4, 2024
f81b148
Formatting
ryardley Nov 4, 2024
a1cfdab
Formatting
ryardley Nov 4, 2024
5ce0a29
Store last_block
ryardley Nov 4, 2024
b9e8a07
Report last block to parent
ryardley Nov 4, 2024
f938e36
Hook up last_block to reader
ryardley Nov 4, 2024
d6df850
Tidy up test code
ryardley Nov 5, 2024
dc95319
Refactor to push persistence to EvmEventReader
ryardley Nov 5, 2024
59f0d54
Tidy up dead code
ryardley Nov 5, 2024
bf8bbe2
Resume after shutdown test
ryardley Nov 5, 2024
5afe50f
Formatting
ryardley Nov 5, 2024
7d35530
Neaten up test
ryardley Nov 5, 2024
f58a054
Formatting
ryardley Nov 5, 2024
3c1b436
Hook start_block up to config
ryardley Nov 5, 2024
20201e6
Formatting
ryardley Nov 5, 2024
b4475bb
Remove unnecessary Actor
ryardley Nov 5, 2024
b971db7
Fix not loading snapshot(must have been using deduplication)
ryardley Nov 5, 2024
91cd99d
Add passing test for config
ryardley Nov 5, 2024
fe8cbfa
Formatting
ryardley Nov 5, 2024
11ef5ca
Rename parent -> processor
ryardley Nov 6, 2024
4fcc027
Improve tracing transparency and fix config bug
ryardley Nov 10, 2024
93e6bfa
Centralize logging tag/id
ryardley Nov 10, 2024
f43e3f8
Tidy up instrument code and fix error
ryardley Nov 12, 2024
d55f793
Formatting
ryardley Nov 12, 2024
e2a8821
Update packages/ciphernode/core/src/tag.rs
ryardley Nov 12, 2024
113ddff
Formatting
ryardley Nov 12, 2024
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
4 changes: 4 additions & 0 deletions packages/ciphernode/Cargo.lock

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

4 changes: 2 additions & 2 deletions packages/ciphernode/aggregator/src/plaintext_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl FromSnapshotWithParams for PlaintextAggregator {
}

impl Checkpoint for PlaintextAggregator {
fn repository(&self) -> Repository<PlaintextAggregatorState> {
self.store.clone()
fn repository(&self) -> &Repository<PlaintextAggregatorState> {
&self.store
}
}
4 changes: 2 additions & 2 deletions packages/ciphernode/aggregator/src/publickey_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl FromSnapshotWithParams for PublicKeyAggregator {
}

impl Checkpoint for PublicKeyAggregator {
fn repository(&self) -> Repository<PublicKeyAggregatorState> {
self.store.clone()
fn repository(&self) -> &Repository<PublicKeyAggregatorState> {
&self.store
}
}
34 changes: 31 additions & 3 deletions packages/ciphernode/config/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,39 @@ use std::{
path::{Path, PathBuf},
};

#[derive(Debug, Deserialize, Serialize, PartialEq)]
#[serde(untagged)]
pub enum Contract {
Full {
address: String,
deploy_block: Option<u64>,
},
AddressOnly(String),
}
ryardley marked this conversation as resolved.
Show resolved Hide resolved

impl Contract {
pub fn address(&self) -> &String {
use Contract::*;
match self {
Full { address, .. } => address,
AddressOnly(v) => v,
}
}

pub fn deploy_block(&self) -> Option<u64> {
use Contract::*;
match self {
Full { deploy_block, .. } => deploy_block.clone(),
AddressOnly(_) => None,
}
}
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ContractAddresses {
pub enclave: String,
pub ciphernode_registry: String,
pub filter_registry: String,
pub enclave: Contract,
pub ciphernode_registry: Contract,
pub filter_registry: Contract,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
1 change: 1 addition & 0 deletions packages/ciphernode/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ impl Display for Shutdown {
#[rtype(result = "()")]
pub struct TestEvent {
pub msg: String,
pub entropy: u64,
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/data/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where
/// This trait enables the self type to checkpoint its state
pub trait Checkpoint: Snapshot {
/// Declare the DataStore instance available on the object
fn repository(&self) -> Repository<Self::Snapshot>;
fn repository(&self) -> &Repository<Self::Snapshot>;

/// Write the current snapshot to the `Repository` provided by `repository()`
fn checkpoint(&self) {
Expand Down
17 changes: 13 additions & 4 deletions packages/ciphernode/enclave_node/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,25 @@ pub async fn setup_aggregator(
let read_provider = create_readonly_provider(&ensure_ws_rpc(rpc_url)).await?;
let write_provider =
create_provider_with_signer(&ensure_http_rpc(rpc_url), &signer).await?;

EnclaveSol::attach(
&bus,
&read_provider,
&write_provider,
&chain.contracts.enclave,
&chain.contracts.enclave.address(),
&repositories.enclave_sol_reader(read_provider.get_chain_id()),
chain.contracts.enclave.deploy_block(),
)
.await?;
RegistryFilterSol::attach(&bus, &write_provider, &chain.contracts.filter_registry.address()).await?;
ryardley marked this conversation as resolved.
Show resolved Hide resolved
CiphernodeRegistrySol::attach(
&bus,
&read_provider,
&chain.contracts.ciphernode_registry.address(),
&repositories.ciphernode_registry_reader(read_provider.get_chain_id()),
chain.contracts.ciphernode_registry.deploy_block(),
)
.await?;
RegistryFilterSol::attach(&bus, &write_provider, &chain.contracts.filter_registry).await?;
CiphernodeRegistrySol::attach(&bus, &read_provider, &chain.contracts.ciphernode_registry)
.await?;
}

E3RequestRouter::builder(&bus, store)
Expand Down
20 changes: 16 additions & 4 deletions packages/ciphernode/enclave_node/src/ciphernode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use alloy::primitives::Address;
use anyhow::Result;
use cipher::Cipher;
use config::AppConfig;
use data::{DataStore, InMemStore, SledStore};
use enclave_core::EventBus;
use evm::{
helpers::{create_readonly_provider, ensure_ws_rpc},
Expand Down Expand Up @@ -46,9 +45,22 @@ pub async fn setup_ciphernode(
let rpc_url = &chain.rpc_url;

let read_provider = create_readonly_provider(&ensure_ws_rpc(rpc_url)).await?;
EnclaveSolReader::attach(&bus, &read_provider, &chain.contracts.enclave).await?;
CiphernodeRegistrySol::attach(&bus, &read_provider, &chain.contracts.ciphernode_registry)
.await?;
EnclaveSolReader::attach(
&bus,
&read_provider,
&chain.contracts.enclave.address(),
&repositories.enclave_sol_reader(read_provider.get_chain_id()),
chain.contracts.enclave.deploy_block(),
)
.await?;
CiphernodeRegistrySol::attach(
&bus,
&read_provider,
&chain.contracts.ciphernode_registry.address(),
&repositories.ciphernode_registry_reader(read_provider.get_chain_id()),
chain.contracts.ciphernode_registry.deploy_block()
)
.await?;
}

E3RequestRouter::builder(&bus, store.clone())
Expand Down
14 changes: 12 additions & 2 deletions packages/ciphernode/enclave_node/src/datastore.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
use std::path::PathBuf;

use actix::{Actor, Addr};
use anyhow::Result;
use config::AppConfig;
use data::{DataStore, InMemStore, SledStore};
use enclave_core::EventBus;
use router::{Repositories, RepositoriesFactory};

pub fn get_sled_store(bus: &Addr<EventBus>, db_file: &PathBuf) -> Result<DataStore> {
Ok((&SledStore::new(bus, db_file)?.start()).into())
}

pub fn get_in_mem_store() -> DataStore {
(&InMemStore::new(true).start()).into()
}
ryardley marked this conversation as resolved.
Show resolved Hide resolved

pub fn setup_datastore(config: &AppConfig, bus: &Addr<EventBus>) -> Result<DataStore> {
let store: DataStore = if !config.use_in_mem_store() {
(&SledStore::new(&bus, &config.db_file())?.start()).into()
get_sled_store(&bus, &config.db_file())?
} else {
(&InMemStore::new(true).start()).into()
get_in_mem_store()
};
Ok(store)
}
Expand Down
6 changes: 6 additions & 0 deletions packages/ciphernode/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ actix = { workspace = true }
alloy = { workspace = true }
alloy-primitives = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
enclave-core = { path = "../core" }
data = { path = "../data" }
futures-util = { workspace = true }
sortition = { path = "../sortition" }
cipher = { path = "../cipher" }
tokio = { workspace = true }
tracing = { workspace = true }
serde = { workspace = true }
zeroize = { workspace = true }

[dev-dependencies]
enclave_node = { path = "../enclave_node" }

31 changes: 27 additions & 4 deletions packages/ciphernode/evm/src/ciphernode_registry_sol.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use crate::{
event_reader::EvmEventReaderState,
helpers::{ReadonlyProvider, WithChainId},
EvmEventReader,
};
use actix::Addr;
use actix::{Actor, Addr};
use alloy::{
primitives::{LogData, B256},
sol,
sol_types::SolEvent,
};
use anyhow::Result;
use data::Repository;
use enclave_core::{EnclaveEvent, EventBus};
use tracing::{error, trace};
use tracing::{error, info, trace};

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -102,20 +104,41 @@ impl CiphernodeRegistrySolReader {
bus: &Addr<EventBus>,
provider: &WithChainId<ReadonlyProvider>,
contract_address: &str,
repository: &Repository<EvmEventReaderState>,
start_block: Option<u64>
) -> Result<Addr<EvmEventReader<ReadonlyProvider>>> {
let addr = EvmEventReader::attach(bus, provider, extractor, contract_address).await?;
let addr = EvmEventReader::attach(
provider,
extractor,
contract_address,
start_block,
&bus.clone().into(),
repository,
)
.await?;

info!(address=%contract_address, "EnclaveSolReader is listening to address");

Ok(addr)
}
}

impl Actor for CiphernodeRegistrySolReader {
type Context = actix::Context<Self>;
}

/// Eventual wrapper for both a reader and a writer
pub struct CiphernodeRegistrySol;
impl CiphernodeRegistrySol {
pub async fn attach(
bus: &Addr<EventBus>,
provider: &WithChainId<ReadonlyProvider>,
contract_address: &str,
repository: &Repository<EvmEventReaderState>,
start_block: Option<u64>
) -> Result<()> {
CiphernodeRegistrySolReader::attach(bus, provider, contract_address).await?;
CiphernodeRegistrySolReader::attach(bus, provider, contract_address, repository, start_block).await?;
// TODO: Writer if needed
Ok(())
}
}
6 changes: 5 additions & 1 deletion packages/ciphernode/evm/src/enclave_sol.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::{
enclave_sol_reader::EnclaveSolReader,
enclave_sol_writer::EnclaveSolWriter,
event_reader::EvmEventReaderState,
helpers::{ReadonlyProvider, SignerProvider, WithChainId},
};
use actix::Addr;
use anyhow::Result;
use data::Repository;
use enclave_core::EventBus;

pub struct EnclaveSol;
Expand All @@ -14,8 +16,10 @@ impl EnclaveSol {
read_provider: &WithChainId<ReadonlyProvider>,
write_provider: &WithChainId<SignerProvider>,
contract_address: &str,
repository: &Repository<EvmEventReaderState>,
start_block: Option<u64>
) -> Result<()> {
EnclaveSolReader::attach(bus, read_provider, contract_address).await?;
EnclaveSolReader::attach(bus, read_provider, contract_address, repository, start_block).await?;
EnclaveSolWriter::attach(bus, write_provider, contract_address).await?;
Ok(())
}
Expand Down
19 changes: 17 additions & 2 deletions packages/ciphernode/evm/src/enclave_sol_reader.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::event_reader::EvmEventReaderState;
use crate::helpers::{ReadonlyProvider, WithChainId};
use crate::EvmEventReader;
use actix::Addr;
use alloy::primitives::{LogData, B256};
use alloy::transports::BoxTransport;
use alloy::{sol, sol_types::SolEvent};
use anyhow::Result;
use data::Repository;
use enclave_core::{EnclaveEvent, EventBus};
use tracing::{error, trace};
use tracing::{error, info, trace};

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -86,8 +88,21 @@ impl EnclaveSolReader {
bus: &Addr<EventBus>,
provider: &WithChainId<ReadonlyProvider, BoxTransport>,
contract_address: &str,
repository: &Repository<EvmEventReaderState>,
start_block: Option<u64>
) -> Result<Addr<EvmEventReader<ReadonlyProvider>>> {
let addr = EvmEventReader::attach(bus, provider, extractor, contract_address).await?;
let addr = EvmEventReader::attach(
provider,
extractor,
contract_address,
start_block,
&bus.clone(),
repository,
)
.await?;
ryardley marked this conversation as resolved.
Show resolved Hide resolved

info!(address=%contract_address, "EnclaveSolReader is listening to address");

Ok(addr)
}
}
Loading
Loading