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 29 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
10 changes: 8 additions & 2 deletions packages/ciphernode/Cargo.lock

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

1 change: 1 addition & 0 deletions packages/ciphernode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fhe-util = { git = "https://github.com/gnosisguild/fhe.rs", version = "0.1.0-bet
futures = "0.3.30"
futures-util = "0.3"
hex = "0.4.3"
lazy_static = "1.5.0"
num = "0.4.3"
rand_chacha = "0.3.1"
rand = "0.8.5"
Expand Down
33 changes: 33 additions & 0 deletions packages/ciphernode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,36 @@ sequenceDiagram
PTA--)PTA: Stop
KS--)-KS: Stop
```

# Debugging

You can debug using the `RUST_LOG` environment var to alter what output is produced by the node


```
RUST_LOG=info enclave start
```

if you supply a tag as an argument you can filter for that tag

```
RUST_LOG="[sortition{id=cn1}]" enclave start --tag cn1
```

This helps filter noise during tests where you might have multiple instances running and you need to see the output of a specific one.

In order to add tracing to a method or function it is recommended to use the `instrument` macro.

```rust
impl Sorition {
// ...
#[instrument(name="sortition", skip_all, fields(id = get_tag()))]
pub async fn attach(
bus: &Addr<EventBus>,
store: Repository<SortitionModule>,
) -> Result<Addr<Sortition>> {
// ...
}
}
```

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
1 change: 1 addition & 0 deletions packages/ciphernode/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ alloy = { workspace = true }
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
anyhow = { workspace = true }
lazy_static = { workspace = true }
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: 2 additions & 0 deletions packages/ciphernode/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
mod eventbus;
mod events;
mod ordered_set;
mod tag;

pub use eventbus::*;
pub use events::*;
pub use ordered_set::*;
pub use tag::*;
12 changes: 12 additions & 0 deletions packages/ciphernode/core/src/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::sync::OnceLock;

static TAG: OnceLock<String> = OnceLock::new();
ryardley marked this conversation as resolved.
Show resolved Hide resolved

pub fn get_tag() -> String {
TAG.get().cloned().unwrap_or_else(|| String::from("_"))
}

pub fn set_tag(new_tag: impl Into<String>) -> Result<(), &'static str> {
TAG.set(new_tag.into())
.map_err(|_| "Tag has already been initialized")
}
ryardley marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/ciphernode/data/src/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Get {
}

/// Generate proxy for the DB
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct DataStore {
scope: Vec<u8>,
get: Recipient<Get>,
Expand Down
1 change: 1 addition & 0 deletions packages/ciphernode/data/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::Result;

use crate::DataStore;

#[derive(Debug)]
pub struct Repository<S> {
store: DataStore,
_p: PhantomData<S>,
Expand Down
Loading
Loading