Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

add support for proxies #69

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions ismp-testsuite/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ impl IsmpHost for Host {
todo!()
}

fn allowed_proxies(&self) -> Vec<StateMachine> {
todo!()
}

fn store_allowed_proxies(&self, _allowed: Vec<StateMachine>) {
todo!()
}

fn unbonding_period(&self, _consensus_state_id: ConsensusStateId) -> Option<Duration> {
Some(Duration::from_secs(60 * 60 * 60))
}
Expand Down
10 changes: 8 additions & 2 deletions ismp/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::{
error::Error,
handlers::{validate_state_machine, MessageResult},
host::IsmpHost,
host::{IsmpHost, StateMachine},
messaging::RequestMessage,
module::{DispatchError, DispatchSuccess},
router::{Request, RequestResponse},
Expand All @@ -41,14 +41,20 @@ where
&msg.proof,
)?;

let check_source = |source: StateMachine| -> bool {
msg.proof.height.id.state_id == source || host.is_allowed_proxy(&source)
};

let router = host.ismp_router();
// If a receipt exists for any request then it's a duplicate and it is not dispatched
let result = msg
.requests
.into_iter()
.filter(|req| {
let req = Request::Post(req.clone());
host.request_receipt(&req).is_none() && !req.timed_out(state.timestamp())
host.request_receipt(&req).is_none() &&
!req.timed_out(state.timestamp()) &&
check_source(req.source_chain())
})
.map(|request| {
let cb = router.module_for_id(request.to.clone())?;
Expand Down
17 changes: 14 additions & 3 deletions ismp/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ pub trait IsmpHost {
Ok(())
}

/// return the state machines that are allowed to proxy requests.
fn allowed_proxies(&self) -> Vec<StateMachine>;

/// Store the whitelist of allowed proxies, this should overwrite the existing whitelist.
fn store_allowed_proxies(&self, allowed: Vec<StateMachine>);

/// Checks if the host allows this state machine to proxy requests.
fn is_allowed_proxy(&self, source: &StateMachine) -> bool {
self.allowed_proxies().iter().any(|proxy| proxy == source)
}

/// Return the unbonding period (i.e the time it takes for a validator's deposit to be unstaked
/// from the network)
fn unbonding_period(&self, consensus_state_id: ConsensusStateId) -> Option<Duration>;
Expand Down Expand Up @@ -224,9 +235,9 @@ impl ToString for StateMachine {
fn to_string(&self) -> String {
match self {
StateMachine::Ethereum(ethereum) => match ethereum {
Ethereum::ExecutionLayer => "ETHE".to_string(),
Ethereum::Arbitrum => "ARBI".to_string(),
Ethereum::Optimism => "OPTI".to_string(),
Ethereum::ExecutionLayer => "ETH".to_string(),
Ethereum::Arbitrum => "ARB".to_string(),
Ethereum::Optimism => "OP".to_string(),
Ethereum::Base => "BASE".to_string(),
},
StateMachine::Polkadot(id) => format!("POLKADOT-{id}"),
Expand Down