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

Refactor: keyless eth rpc client #4256

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 1 addition & 10 deletions api/bin/chainflip-ingress-egress-tracker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chainflip_engine::settings::{HttpBasicAuthEndpoint, WsHttpEndpoints};
use futures::FutureExt;
use jsonrpsee::{core::Error, server::ServerBuilder, RpcModule};
use std::{env, io::Write, net::SocketAddr, path::PathBuf};
use std::{env, net::SocketAddr};
use tracing::log;
use utilities::task_scope;

Expand All @@ -11,7 +11,6 @@ mod witnessing;
pub struct DepositTrackerSettings {
eth_node: WsHttpEndpoints,
// The key shouldn't be necessary, but the current witnesser wants this
kylezs marked this conversation as resolved.
Show resolved Hide resolved
eth_key_path: PathBuf,
dot_node: WsHttpEndpoints,
state_chain_ws_endpoint: String,
btc: HttpBasicAuthEndpoint,
Expand Down Expand Up @@ -83,13 +82,6 @@ async fn start(

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Temporary hack: we don't actually use eth key, but the current witnesser is
// expecting a path with a valid key, so we create a temporary dummy key file here:
let mut eth_key_temp_file = tempfile::NamedTempFile::new()?;
eth_key_temp_file
.write_all(b"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
.unwrap();

let settings = DepositTrackerSettings {
eth_node: WsHttpEndpoints {
ws_endpoint: env::var("ETH_WS_ENDPOINT")
Expand All @@ -99,7 +91,6 @@ async fn main() -> anyhow::Result<()> {
.unwrap_or("http://localhost:8545".to_string())
.into(),
},
eth_key_path: eth_key_temp_file.path().into(),
dot_node: WsHttpEndpoints {
ws_endpoint: env::var("DOT_WS_ENDPOINT")
.unwrap_or("ws://localhost:9947".to_string())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cf_primitives::chains::assets::eth::Asset;
use utilities::task_scope;

use chainflip_engine::{
eth::{retry_rpc::EthersRetryRpcClient, rpc::EthRpcSigningClient},
eth::{retry_rpc::EthersRetryRpcClient, rpc::EthRpcClient},
settings::NodeContainer,
state_chain_observer::client::{StateChainClient, StateChainStreamApi},
witness::{
Expand Down Expand Up @@ -40,12 +40,7 @@ where
let eth_client = {
let nodes = NodeContainer { primary: settings.eth_node.clone(), backup: None };

EthersRetryRpcClient::<EthRpcSigningClient>::new(
scope,
settings.eth_key_path,
nodes,
env_params.eth_chain_id.into(),
)?
EthersRetryRpcClient::<EthRpcClient>::new(scope, nodes, env_params.eth_chain_id.into())?
};

let vaults = epoch_source.vaults().await;
Expand Down
6 changes: 4 additions & 2 deletions engine/src/eth/retry_rpc/address_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethers::prelude::*;

use crate::eth::rpc::{
address_checker::{AddressCheckerRpcApi, *},
EthRpcSigningClient,
EthRpcApi,
};

use super::EthersRetryRpcClient;
Expand All @@ -27,7 +27,9 @@ pub trait AddressCheckerRetryRpcApi {
}

#[async_trait::async_trait]
impl AddressCheckerRetryRpcApi for EthersRetryRpcClient<EthRpcSigningClient> {
impl<Rpc: EthRpcApi + AddressCheckerRpcApi> AddressCheckerRetryRpcApi
for EthersRetryRpcClient<Rpc>
{
async fn address_states(
&self,
block_hash: H256,
Expand Down
29 changes: 25 additions & 4 deletions engine/src/eth/rpc/address_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethers::prelude::*;

use anyhow::{Ok, Result};

use super::EthRpcSigningClient;
use super::{EthRpcClient, EthRpcSigningClient};

abigen!(AddressChecker, "$CF_ETH_CONTRACT_ABI_ROOT/$CF_ETH_CONTRACT_ABI_TAG/IAddressChecker.json");

Expand All @@ -24,14 +24,14 @@ pub trait AddressCheckerRpcApi {
}

#[async_trait::async_trait]
impl AddressCheckerRpcApi for EthRpcSigningClient {
impl AddressCheckerRpcApi for EthRpcClient {
async fn address_states(
&self,
block_hash: H256,
contract_address: H160,
addresses: Vec<H160>,
) -> Result<Vec<AddressState>> {
Ok(AddressChecker::new(contract_address, self.signer.inner().clone())
Ok(AddressChecker::new(contract_address, self.provider.clone())
.address_states(addresses)
.block(BlockId::Hash(block_hash))
.call()
Expand All @@ -44,10 +44,31 @@ impl AddressCheckerRpcApi for EthRpcSigningClient {
contract_address: H160,
addresses: Vec<H160>,
) -> Result<Vec<U256>> {
Ok(AddressChecker::new(contract_address, self.signer.inner().clone())
Ok(AddressChecker::new(contract_address, self.provider.clone())
.native_balances(addresses)
.block(BlockId::Hash(block_hash))
.call()
.await?)
}
}

#[async_trait::async_trait]
impl AddressCheckerRpcApi for EthRpcSigningClient {
async fn address_states(
&self,
block_hash: H256,
contract_address: H160,
addresses: Vec<H160>,
) -> Result<Vec<AddressState>> {
self.rpc_client.address_states(block_hash, contract_address, addresses).await
}

async fn balances(
&self,
block_hash: H256,
contract_address: H160,
addresses: Vec<H160>,
) -> Result<Vec<U256>> {
self.rpc_client.balances(block_hash, contract_address, addresses).await
}
}
7 changes: 3 additions & 4 deletions engine/src/witness/eth/ethereum_deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
use crate::{
eth::{
retry_rpc::{EthersRetryRpcApi, EthersRetryRpcClient},
rpc::EthRpcSigningClient,
rpc::EthRpcClient,
},
settings::Settings,
witness::common::chain_source::Header,
Expand Down Expand Up @@ -307,7 +307,7 @@ mod tests {
);
}

#[ignore = "requries connection to a node"]
#[ignore = "requires connection to a node"]
#[tokio::test]
async fn test_get_ingress_contract() {
task_scope::task_scope(|scope| {
Expand All @@ -318,9 +318,8 @@ mod tests {
"e7f1725E7734CE288F8367e1Bb143E90bb3F0512".parse::<Address>().unwrap();

let settings = Settings::new_test().unwrap();
let client = EthersRetryRpcClient::<EthRpcSigningClient>::new(
let client = EthersRetryRpcClient::<EthRpcClient>::new(
scope,
settings.eth.private_key_file,
settings.eth.nodes,
U256::from(1337u64),
)
Expand Down
16 changes: 5 additions & 11 deletions engine/src/witness/eth/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ mod tests {
use super::super::eth_source::EthSource;

use crate::{
eth::{retry_rpc::EthersRetryRpcClient, rpc::EthRpcSigningClient},
settings::{self, NodeContainer, WsHttpEndpoints},
eth::{retry_rpc::EthersRetryRpcClient, rpc::EthRpcClient},
settings::{NodeContainer, WsHttpEndpoints},
state_chain_observer::client::StateChainClient,
witness::common::{chain_source::extension::ChainSourceExt, epoch_source::EpochSource},
};
Expand All @@ -197,21 +197,15 @@ mod tests {
async fn test_key_manager_witnesser() {
task_scope(|scope| {
async {
let eth_settings = settings::Eth {
nodes: NodeContainer {
let retry_client = EthersRetryRpcClient::<EthRpcClient>::new(
scope,
NodeContainer {
primary: WsHttpEndpoints {
ws_endpoint: "ws://localhost:8546".into(),
http_endpoint: "http://localhost:8545".into(),
},
backup: None,
},
private_key_file: PathBuf::from_str("/some/key/file").unwrap(),
};

let retry_client = EthersRetryRpcClient::<EthRpcSigningClient>::new(
scope,
eth_settings.private_key_file,
eth_settings.nodes,
U256::from(1337u64),
)
.unwrap();
Expand Down