Skip to content

Commit

Permalink
Rust agent config parsing (#2687)
Browse files Browse the repository at this point in the history
### Description

This does two things:
1) It parses the agent-specific configs for the relayer, validator, and
scraper.
2) It removes the rigid structures that had been in place for parsing
that were called out earlier and instead parses the serde json values
directly.

This PR does not cut over to the new versions just yet. That can happen
once we start integrating it into the testing and deployment pipelines.

### Drive-by changes

- Derive more was added and used where it made sense
- The old config macro was removed

### Related issues

- Progress on #2215 

### Backward compatibility

Yes

### Testing

None
  • Loading branch information
mattiekat authored Aug 29, 2023
1 parent 9612623 commit 17a6e79
Show file tree
Hide file tree
Showing 26 changed files with 1,690 additions and 1,074 deletions.
2 changes: 2 additions & 0 deletions rust/Cargo.lock

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

8 changes: 4 additions & 4 deletions rust/agents/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ version.workspace = true
async-trait.workspace = true
config.workspace = true
derive-new.workspace = true
derive_more.workspace = true
enum_dispatch.workspace = true
ethers-contract.workspace = true
ethers.workspace = true
eyre.workspace = true
futures-util.workspace = true
itertools.workspace = true
num-derive.workspace = true
num-traits.workspace = true
prometheus.workspace = true
regex.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde.workspace = true
serde_json.workspace = true
Expand All @@ -28,14 +32,10 @@ thiserror.workspace = true
tokio = { workspace = true, features = ["rt", "macros", "parking_lot"] }
tracing-futures.workspace = true
tracing.workspace = true
regex.workspace = true

hyperlane-core = { path = "../../hyperlane-core", features = ["agent"] }
hyperlane-base = { path = "../../hyperlane-base" }
hyperlane-ethereum = { path = "../../chains/hyperlane-ethereum" }
num-derive.workspace = true
num-traits.workspace = true
derive_more.workspace = true

[dev-dependencies]
tokio-test.workspace = true
Expand Down
24 changes: 7 additions & 17 deletions rust/agents/relayer/src/msg/metadata/ccip_read.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
use async_trait::async_trait;
use derive_more::Deref;
use derive_new::new;
use ethers::{abi::AbiDecode, core::utils::hex::decode as hex_decode};
use eyre::Context;
use hyperlane_core::{HyperlaneMessage, RawHyperlaneMessage, H256};
use hyperlane_ethereum::OffchainLookup;
use regex::Regex;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::ops::Deref;

use derive_new::new;
use eyre::Context;
use tracing::{info, instrument};

use super::{BaseMetadataBuilder, MetadataBuilder};
use ethers::abi::AbiDecode;
use ethers::core::utils::hex::decode as hex_decode;
use hyperlane_core::{HyperlaneMessage, RawHyperlaneMessage, H256};
use regex::Regex;

#[derive(Serialize, Deserialize)]
struct OffchainResponse {
data: String,
}

#[derive(Clone, Debug, new)]
#[derive(Clone, Debug, new, Deref)]
pub struct CcipReadIsmMetadataBuilder {
base: BaseMetadataBuilder,
}

impl Deref for CcipReadIsmMetadataBuilder {
type Target = BaseMetadataBuilder;

fn deref(&self) -> &Self::Target {
&self.base
}
}

#[async_trait]
impl MetadataBuilder for CcipReadIsmMetadataBuilder {
#[instrument(err, skip(self))]
Expand Down
16 changes: 3 additions & 13 deletions rust/agents/relayer/src/msg/metadata/routing.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
use async_trait::async_trait;
use std::ops::Deref;

use derive_more::Deref;
use derive_new::new;
use eyre::Context;
use tracing::instrument;

use hyperlane_core::{HyperlaneMessage, H256};
use tracing::instrument;

use super::{BaseMetadataBuilder, MetadataBuilder};

#[derive(Clone, Debug, new)]
#[derive(Clone, Debug, new, Deref)]
pub struct RoutingIsmMetadataBuilder {
base: BaseMetadataBuilder,
}

impl Deref for RoutingIsmMetadataBuilder {
type Target = BaseMetadataBuilder;

fn deref(&self) -> &Self::Target {
&self.base
}
}

#[async_trait]
impl MetadataBuilder for RoutingIsmMetadataBuilder {
#[instrument(err, skip(self))]
Expand Down
30 changes: 12 additions & 18 deletions rust/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
use std::fmt::{Debug, Formatter};
use std::{
collections::{HashMap, HashSet},
fmt::{Debug, Formatter},
sync::Arc,
};

use async_trait::async_trait;
use derive_more::AsRef;
use eyre::Result;
use hyperlane_base::{MessageContractSync, WatermarkContractSync};
use tokio::sync::mpsc::UnboundedSender;
use hyperlane_base::{
db::{HyperlaneRocksDB, DB},
run_all, BaseAgent, ContractSyncMetrics, CoreMetrics, HyperlaneAgentCore, MessageContractSync,
WatermarkContractSync,
};
use hyperlane_core::{HyperlaneDomain, InterchainGasPayment, U256};
use tokio::{
sync::{
mpsc::{self, UnboundedReceiver},
mpsc::{self, UnboundedReceiver, UnboundedSender},
RwLock,
},
task::JoinHandle,
};
use tracing::{info, info_span, instrument::Instrumented, Instrument};

use hyperlane_base::{
db::{HyperlaneRocksDB, DB},
run_all, BaseAgent, ContractSyncMetrics, CoreMetrics, HyperlaneAgentCore,
};
use hyperlane_core::{HyperlaneDomain, InterchainGasPayment, U256};

use crate::msg::pending_message::MessageSubmissionMetrics;
use crate::{
merkle_tree_builder::MerkleTreeBuilder,
msg::{
gas_payment::GasPaymentEnforcer,
metadata::BaseMetadataBuilder,
pending_message::MessageContext,
pending_message::{MessageContext, MessageSubmissionMetrics},
pending_operation::DynPendingOperation,
processor::{MessageProcessor, MessageProcessorMetrics},
serial_submitter::{SerialSubmitter, SerialSubmitterMetrics},
Expand All @@ -44,9 +42,11 @@ struct ContextKey {
}

/// A relayer agent
#[derive(AsRef)]
pub struct Relayer {
origin_chains: HashSet<HyperlaneDomain>,
destination_chains: HashSet<HyperlaneDomain>,
#[as_ref]
core: HyperlaneAgentCore,
message_syncs: HashMap<HyperlaneDomain, Arc<MessageContractSync>>,
interchain_gas_payment_syncs:
Expand Down Expand Up @@ -79,12 +79,6 @@ impl Debug for Relayer {
}
}

impl AsRef<HyperlaneAgentCore> for Relayer {
fn as_ref(&self) -> &HyperlaneAgentCore {
&self.core
}
}

#[async_trait]
#[allow(clippy::unit_arg)]
impl BaseAgent for Relayer {
Expand Down
27 changes: 16 additions & 11 deletions rust/agents/relayer/src/settings/matching_list.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;

use serde::de::{Error, SeqAccess, Visitor};
use serde::{Deserialize, Deserializer};

use hyperlane_core::config::StrOrInt;
use hyperlane_core::{HyperlaneMessage, H160, H256};
//! The correct settings shape is defined in the TypeScript SDK metadata. While the the exact shape
//! and validations it defines are not applied here, we should mirror them.
//! ANY CHANGES HERE NEED TO BE REFLECTED IN THE TYPESCRIPT SDK.

use std::{
fmt,
fmt::{Debug, Display, Formatter},
marker::PhantomData,
};

use hyperlane_core::{config::StrOrInt, HyperlaneMessage, H160, H256};
use serde::{
de::{Error, SeqAccess, Visitor},
Deserialize, Deserializer,
};

/// Defines a set of patterns for determining if a message should or should not
/// be relayed. This is useful for determine if a message matches a given set or
Expand Down Expand Up @@ -260,9 +266,8 @@ fn parse_addr<E: Error>(addr_str: &str) -> Result<H256, E> {
mod test {
use hyperlane_core::{H160, H256};

use crate::settings::matching_list::MatchInfo;

use super::{Filter::*, MatchingList};
use crate::settings::matching_list::MatchInfo;

#[test]
fn basic_config() {
Expand Down
Loading

0 comments on commit 17a6e79

Please sign in to comment.