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 26 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
}
}
50 changes: 44 additions & 6 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 Expand Up @@ -297,7 +325,9 @@ chains:
rpc_url: "ws://localhost:8545"
contracts:
enclave: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
ciphernode_registry: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
ciphernode_registry:
address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
deploy_block: 1764352873645
filter_registry: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
"#,
)?;
Expand All @@ -308,10 +338,18 @@ chains:
assert_eq!(chain.name, "hardhat");
assert_eq!(chain.rpc_url, "ws://localhost:8545");
assert_eq!(
chain.contracts.enclave,
chain.contracts.enclave.address(),
"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
);

assert_eq!(
chain.contracts.ciphernode_registry.address(),
"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
);
assert_eq!(chain.contracts.enclave.deploy_block(), None);
assert_eq!(
chain.contracts.ciphernode_registry.deploy_block(),
Some(1764352873645)
);
Ok(())
});
}
Expand Down
29 changes: 15 additions & 14 deletions packages/ciphernode/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TryFrom<E3id> for U256 {
pub struct EventId(pub [u8; 32]);

impl EventId {
fn from<T: Hash>(value: T) -> Self {
pub fn hash<T: Hash>(value: T) -> Self {
let mut hasher = Sha256::new();
let mut std_hasher = DefaultHasher::new();
value.hash(&mut std_hasher);
Expand Down Expand Up @@ -224,7 +224,7 @@ pub trait FromError {
impl From<KeyshareCreated> for EnclaveEvent {
fn from(data: KeyshareCreated) -> Self {
EnclaveEvent::KeyshareCreated {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -233,7 +233,7 @@ impl From<KeyshareCreated> for EnclaveEvent {
impl From<E3Requested> for EnclaveEvent {
fn from(data: E3Requested) -> Self {
EnclaveEvent::E3Requested {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -242,7 +242,7 @@ impl From<E3Requested> for EnclaveEvent {
impl From<PublicKeyAggregated> for EnclaveEvent {
fn from(data: PublicKeyAggregated) -> Self {
EnclaveEvent::PublicKeyAggregated {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -251,7 +251,7 @@ impl From<PublicKeyAggregated> for EnclaveEvent {
impl From<CiphertextOutputPublished> for EnclaveEvent {
fn from(data: CiphertextOutputPublished) -> Self {
EnclaveEvent::CiphertextOutputPublished {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -260,7 +260,7 @@ impl From<CiphertextOutputPublished> for EnclaveEvent {
impl From<DecryptionshareCreated> for EnclaveEvent {
fn from(data: DecryptionshareCreated) -> Self {
EnclaveEvent::DecryptionshareCreated {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -269,7 +269,7 @@ impl From<DecryptionshareCreated> for EnclaveEvent {
impl From<PlaintextAggregated> for EnclaveEvent {
fn from(data: PlaintextAggregated) -> Self {
EnclaveEvent::PlaintextAggregated {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -278,7 +278,7 @@ impl From<PlaintextAggregated> for EnclaveEvent {
impl From<E3RequestComplete> for EnclaveEvent {
fn from(data: E3RequestComplete) -> Self {
EnclaveEvent::E3RequestComplete {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -287,7 +287,7 @@ impl From<E3RequestComplete> for EnclaveEvent {
impl From<CiphernodeSelected> for EnclaveEvent {
fn from(data: CiphernodeSelected) -> Self {
EnclaveEvent::CiphernodeSelected {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -296,7 +296,7 @@ impl From<CiphernodeSelected> for EnclaveEvent {
impl From<CiphernodeAdded> for EnclaveEvent {
fn from(data: CiphernodeAdded) -> Self {
EnclaveEvent::CiphernodeAdded {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -305,7 +305,7 @@ impl From<CiphernodeAdded> for EnclaveEvent {
impl From<CiphernodeRemoved> for EnclaveEvent {
fn from(data: CiphernodeRemoved) -> Self {
EnclaveEvent::CiphernodeRemoved {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -314,7 +314,7 @@ impl From<CiphernodeRemoved> for EnclaveEvent {
impl From<EnclaveError> for EnclaveEvent {
fn from(data: EnclaveError) -> Self {
EnclaveEvent::EnclaveError {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -323,7 +323,7 @@ impl From<EnclaveError> for EnclaveEvent {
impl From<Shutdown> for EnclaveEvent {
fn from(data: Shutdown) -> Self {
EnclaveEvent::Shutdown {
id: EventId::from(data.clone()),
id: EventId::hash(data.clone()),
data: data.clone(),
}
}
Expand All @@ -332,7 +332,7 @@ impl From<Shutdown> for EnclaveEvent {
impl From<TestEvent> for EnclaveEvent {
fn from(value: TestEvent) -> Self {
EnclaveEvent::TestEvent {
id: EventId::from(value.clone()),
id: EventId::hash(value.clone()),
data: value.clone(),
}
}
Expand Down 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
5 changes: 3 additions & 2 deletions packages/ciphernode/enclave/src/commands/aggregator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::*;
use clap::Subcommand;
use config::AppConfig;

#[derive(Subcommand)]
#[derive(Subcommand, Debug)]
pub enum AggregatorCommands {
/// Start the application as an aggregator
Start {
Expand All @@ -17,7 +17,7 @@ pub enum AggregatorCommands {
},
}

pub async fn execute(command: AggregatorCommands, config: AppConfig) -> Result<()> {
pub async fn execute(command: AggregatorCommands, config: AppConfig, id: &str) -> Result<()> {
match command {
AggregatorCommands::Start {
pubkey_write_path,
Expand All @@ -27,6 +27,7 @@ pub async fn execute(command: AggregatorCommands, config: AppConfig) -> Result<(
config,
pubkey_write_path.as_deref(),
plaintext_write_path.as_deref(),
id
)
.await?
}
Expand Down
7 changes: 4 additions & 3 deletions packages/ciphernode/enclave/src/commands/aggregator/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ pub async fn execute(
config: AppConfig,
pubkey_write_path: Option<&str>,
plaintext_write_path: Option<&str>,
id: &str
) -> Result<()> {
owo();

info!("LAUNCHING AGGREGATOR");

let (bus, handle) = setup_aggregator(config, pubkey_write_path, plaintext_write_path).await?;
let (bus, handle, peer_id) =
setup_aggregator(config, pubkey_write_path, plaintext_write_path, id).await?;

info!("LAUNCHING AGGREGATOR {}", peer_id);
tokio::spawn(listen_for_shutdown(bus.into(), handle));

std::future::pending::<()>().await;
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/enclave/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aggregator::AggregatorCommands;
use clap::Subcommand;
use wallet::WalletCommands;

#[derive(Subcommand)]
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Start the application
Start,
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave/src/commands/password/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::*;
use clap::Subcommand;
use config::AppConfig;

#[derive(Subcommand)]
#[derive(Subcommand, Debug)]
pub enum PasswordCommands {
/// Create a new password
Create {
Expand All @@ -25,7 +25,7 @@ pub enum PasswordCommands {
},
}

pub async fn execute(command: PasswordCommands, config: AppConfig) -> Result<()> {
pub async fn execute(command: PasswordCommands, config: AppConfig, id: &str) -> Result<()> {
match command {
PasswordCommands::Create { password } => create::execute(&config, password).await?,
PasswordCommands::Delete => delete::execute(&config).await?,
Expand Down
7 changes: 3 additions & 4 deletions packages/ciphernode/enclave/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ use tracing::info;

use crate::owo;

pub async fn execute(config: AppConfig) -> Result<()> {
pub async fn execute(config: AppConfig, id: &str) -> Result<()> {
owo();

// let address = Address::parse_checksummed(&config.address(), None).context("Invalid address")?;
let Some(address) = config.address() else {
return Err(anyhow!("You must provide an address"));
};

info!("LAUNCHING CIPHERNODE: ({})", address);

let (bus, handle) = setup_ciphernode(config, address).await?;
let (bus, handle, peer_id) = setup_ciphernode(config, address, id).await?;
info!("LAUNCHING CIPHERNODE: ({}/{})", address, peer_id);

tokio::spawn(listen_for_shutdown(bus.into(), handle));

Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave/src/commands/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::*;
use clap::Subcommand;
use config::AppConfig;

#[derive(Subcommand)]
#[derive(Subcommand, Debug)]
pub enum WalletCommands {
/// Set a new Wallet Private Key
Set {
Expand All @@ -22,7 +22,7 @@ fn ensure_hex(s: &str) -> Result<String> {
Ok(s.to_string())
}

pub async fn execute(command: WalletCommands, config: AppConfig) -> Result<()> {
pub async fn execute(command: WalletCommands, config: AppConfig, id: &str) -> Result<()> {
match command {
WalletCommands::Set { private_key } => set::execute(&config, private_key).await?,
};
Expand Down
Loading
Loading