Skip to content

Commit

Permalink
Merge pull request #1 from proofcast/sentinel-generic-event-signing
Browse files Browse the repository at this point in the history
  • Loading branch information
ubordignon committed May 17, 2024
2 parents 84b2bc0 + e1d7b70 commit bbfec92
Show file tree
Hide file tree
Showing 40 changed files with 584 additions and 523 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ target/
*.gz
*.env
/server
sentinel-app
71 changes: 69 additions & 2 deletions 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 common/sentinel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ common_debug_signers = { workspace = true }

# NOTE: Rev is my PR to get a long commit hash. If merged we can update this import.
rbtag = { git = "https://github.com/LivingInSyn/rbtag.git", rev = "feee7c0" }
eth_trie = "0.4.0"

[dev-dependencies]
simple_logger = { workspace = true }
12 changes: 0 additions & 12 deletions common/sentinel/src/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use common_network_ids::NetworkId;
use derive_getters::Getters;
use ethereum_types::{Address as EthAddress, U256};
use jsonrpsee::ws_client::WsClient;
use serde_json::Value as Json;
use thiserror::Error;

use crate::{endpoints::Endpoints, Bpm, ProcessorOutput, SentinelConfig, SentinelError};
Expand Down Expand Up @@ -78,17 +77,6 @@ impl Batch {
self.block_num
}

pub fn update_bpm_from_json(&mut self, j: Json) {
let err_msg = format!("error converting json: '{j}' to processor output:");
match ProcessorOutput::try_from(j) {
Ok(ref o) => self.update_bpm(o),
Err(e) => {
warn!("{err_msg}: {e}");
warn!("not updating syncer bpm for network {}", self.bpm.network_id());
},
}
}

pub fn update_bpm(&mut self, o: &ProcessorOutput) {
self.bpm.push(o)
}
Expand Down
3 changes: 2 additions & 1 deletion common/sentinel/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ mod tests {
fn should_get_config() {
let path = "src/config/test_utils/sample-config";
let result = SentinelConfig::new(path);
assert!(result.is_ok());
result.unwrap();
//assert!(result.is_ok());
}
}
6 changes: 6 additions & 0 deletions common/sentinel/src/config/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use thiserror::Error;

#[derive(Error, Debug)]
pub enum SentinelConfigError {
#[error("need an array of address and topic arguments in events in config")]
NotEnoughEventArgs,

#[error("common error: {0}")]
Common(#[from] common::CommonError),

#[error("sentinel config network id error {0}")]
NetworkId(#[from] common_network_ids::NetworkIdError),

Expand Down
2 changes: 1 addition & 1 deletion common/sentinel/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub use self::{
governance::GovernanceConfig,
ipfs::IpfsConfig,
log::LogConfig,
network::NetworkConfig,
network::{ConfiguredEvent, ConfiguredEvents, NetworkConfig},
};
use self::{governance::GovernanceToml, log::LogToml, network::NetworkToml};
43 changes: 41 additions & 2 deletions common/sentinel/src/config/network.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
use common_eth::convert_hex_to_eth_address;
use common_eth::{convert_hex_to_eth_address, convert_hex_to_h256};
use common_network_ids::NetworkId;
use derive_getters::Getters;
use ethereum_types::Address as EthAddress;
use derive_more::{Constructor, Deref};
use ethereum_types::{Address as EthAddress, H256 as EthHash};
use serde::{Deserialize, Serialize};

use super::SentinelConfigError;
use crate::{Endpoints, SentinelError};

#[derive(Debug, Clone, Default, Getters, Eq, PartialEq, Serialize, Deserialize, Constructor)]
pub struct ConfiguredEvent {
pub address: EthAddress,
pub topic: EthHash,
}

#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Constructor, Deref)]
pub struct ConfiguredEvents(Vec<ConfiguredEvent>);

impl TryFrom<&Vec<Vec<String>>> for ConfiguredEvents {
type Error = SentinelConfigError;

fn try_from(e: &Vec<Vec<String>>) -> Result<Self, Self::Error> {
let events = e
.iter()
.map(|v| {
if v.len() < 2 {
Err(Self::Error::NotEnoughEventArgs)
} else {
Ok(ConfiguredEvent::new(
convert_hex_to_eth_address(&v[0])?,
convert_hex_to_h256(&v[1])?,
))
}
})
.collect::<Result<Vec<_>, Self::Error>>()?;

Ok(Self::new(events))
}
}

#[derive(Debug, Clone, Deserialize)]
pub struct NetworkToml {
validate: bool,
Expand All @@ -17,6 +49,7 @@ pub struct NetworkToml {
pnetwork_hub: String,
endpoints: Vec<String>,
gas_price: Option<u64>,
events: Vec<Vec<String>>,
pre_filter_receipts: bool,
}

Expand All @@ -31,10 +64,15 @@ pub struct NetworkConfig {
endpoints: Endpoints,
gas_price: Option<u64>,
pnetwork_hub: EthAddress,
events: ConfiguredEvents,
pre_filter_receipts: bool,
}

impl NetworkConfig {
pub fn network_id(&self) -> NetworkId {
*self.endpoints.network_id()
}

pub fn from_toml(network_id: NetworkId, toml: &NetworkToml) -> Result<Self, SentinelError> {
let sleep_duration = toml.sleep_duration;
let endpoints = Endpoints::new(sleep_duration, network_id, toml.endpoints.clone());
Expand All @@ -44,6 +82,7 @@ impl NetworkConfig {
validate: toml.validate,
gas_price: toml.gas_price,
gas_limit: toml.gas_limit,
events: ConfiguredEvents::try_from(&toml.events)?,
pre_filter_receipts: toml.pre_filter_receipts,
batch_size: Self::sanity_check_batch_size(toml.batch_size)?,
pnetwork_hub: convert_hex_to_eth_address(&toml.pnetwork_hub)?,
Expand Down
7 changes: 7 additions & 0 deletions common/sentinel/src/config/test_utils/sample-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ batch_size = 500 # Max number of blocks to batch together before submitting to c
batch_duration = 60 # Max amount of time (in seconds) between batch submissions
pre_filter_receipts = true # Pre filter receipts in app before submitting to the core
base_challenge_period_duration = 600 # Smart-contract enforced minimum time before a queued operation becomes executable
events = [
["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
]

[networks.polygon]
pnetwork_hub = "0x578E916A4064c32F2eF44614Ff9B04B6D2546A13"
Expand All @@ -43,3 +46,7 @@ pre_filter_receipts = true # Pre filter receipts in app before submitting to the
batch_size = 500 # Max number of host blocks to batch together before submission
batch_duration = 60 # Max amount of time between batch submission in seconds
base_challenge_period_duration = 600 # Smart-contract enforced minimum time before a queued operation becomes executable
events = [
["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
]
3 changes: 3 additions & 0 deletions common/sentinel/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ impl From<SentinelError> for CommonError {

#[derive(Error, Debug)]
pub enum SentinelError {
#[error("signed event error: {0}")]
SignedEvent(#[from] crate::SignedEventError),

#[error("file logger error: {0}")]
FileLogger(#[from] common_file_logger::LoggerError),

Expand Down
15 changes: 14 additions & 1 deletion common/sentinel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ mod flatten_join_handle;
mod ipfs;
mod latest_block_info;
mod logging;
mod merkle;
mod messages;
mod processor;
mod registration;
mod sanity_check_frequency;
mod signed_events;
mod status;
mod sync_state;
mod test_utils;
Expand All @@ -43,7 +45,16 @@ pub use self::{
ChallengesError,
ChallengesList,
},
config::{IpfsConfig, LogConfig, NetworkConfig, SentinelConfig, SentinelConfigError, SentinelCoreConfig},
config::{
ConfiguredEvent,
ConfiguredEvents,
IpfsConfig,
LogConfig,
NetworkConfig,
SentinelConfig,
SentinelConfigError,
SentinelCoreConfig,
},
constants::{
DEFAULT_SLEEP_TIME,
HOST_PROTOCOL_ID,
Expand Down Expand Up @@ -76,6 +87,7 @@ pub use self::{
ipfs::{check_ipfs_daemon_is_running, publish_status, IpfsError},
latest_block_info::{LatestBlockInfo, LatestBlockInfos},
logging::{init_logger, LogLevel},
merkle::{MerkleError, MerkleProof, MerkleTree},
messages::{
BroadcastChannelMessages,
ChallengeResponderBroadcastChannelMessages,
Expand All @@ -101,6 +113,7 @@ pub use self::{
processor::{process_batch, ProcessorOutput},
registration::{get_registration_extension_tx, get_registration_signature},
sanity_check_frequency::sanity_check_frequency,
signed_events::{SignedEvent, SignedEventError, SignedEvents},
status::{SentinelStatus, SentinelStatusError},
sync_state::SyncState,
user_ops::{
Expand Down
13 changes: 13 additions & 0 deletions common/sentinel/src/merkle/merkle_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum MerkleError {
#[error("cannot make proof, target key is not in trie")]
NoKeyToProve,

#[error("trie error: {0}")]
Trie(#[from] eth_trie::TrieError),

#[error("common error: {0}")]
Common(#[from] common::CommonError),
}
Loading

0 comments on commit bbfec92

Please sign in to comment.