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

Commit

Permalink
add support for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Jul 27, 2023
1 parent 6dff7cf commit 83c4705
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
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

0 comments on commit 83c4705

Please sign in to comment.