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

feat(sentinel-lib): Add support to generic event signing #1

Merged
merged 26 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6bde57b
fix(sentinel-app): <- rm user op cancellor loop
gskapka May 1, 2024
62fa5b6
feat(sentinel-lib): <- adds events list to config
gskapka May 8, 2024
9284dd5
feat(sentinel-lib): <- adds barebones `SignedEvent` struct
gskapka May 8, 2024
8b4d4f5
feat(sentinel-lib): <- adds required fields to signed event struct
gskapka May 8, 2024
38fe038
feat(sentinel-lib): <- flesh out signed event parser more
gskapka May 8, 2024
ef6108c
feat(sentinel-lib): <- adds method to network id from network config
gskapka May 9, 2024
2ab62c2
feat(sentinel-lib): <- adds `empty` method to `SignedEvents`
gskapka May 9, 2024
1934d77
feat(sentinel-lib): <- update processor to return `SignedEvents` inst…
gskapka May 9, 2024
56ff894
fix(sentinel-lib): <- rm unused batching fxn
gskapka May 9, 2024
3e3ff5e
feat(sentinel-app): <- add `todo!` to that where `ProcessorOutput` sh…
gskapka May 9, 2024
25a5629
feat(sentinel-lib): <- adds eth receipt merkle proving fxn to that
gskapka May 9, 2024
5f6d9c1
feat(sentinel-lib): <- `wire up process_single` in processor
gskapka May 9, 2024
34a5e24
feat(sentinel-lib): <- adds in method to create `SignedEvent`
gskapka May 9, 2024
416e1e2
feat(sentinel-lib): <- make fields public in `ConfiguredEvent`
gskapka May 9, 2024
df537f5
feat(sentinel-lib): <- move merkle stuff to merkle mod
gskapka May 10, 2024
444ed4f
feat(sentinel-lib): <- use full submat in processor instead of just r…
gskapka May 10, 2024
365dcd3
chore(sentinel-lib): <- fix clippy lints
gskapka May 10, 2024
ee4fe4c
feat(sentinel-lib): <- adds `SignedEvents` parsing logic from submat
gskapka May 10, 2024
19d2edd
feat(sentinel-lib): implement encode for SignedEvent
ubordignon May 14, 2024
018de8c
feat(sentinel-lib): test signed events TryFrom implementation
ubordignon May 14, 2024
5b25d61
feat(sentinel-lib): add merkle root calculation test
ubordignon May 17, 2024
005a66d
fix(sentinel-lib): use transaction index to generate merkle proof
ubordignon May 17, 2024
53207e1
feat(sentinel-lib): add merkle proof test
ubordignon May 17, 2024
2363502
fix: pass through `NetworkConfig` instead of `NetworkId` as expected …
gitmp01 May 14, 2024
0278319
fix(android): initialize keystore upon startup
gitmp01 May 15, 2024
e1d7b70
ref(sentinel-lib): comply with signed event spec
ubordignon May 17, 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
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