Skip to content

Commit eebadc3

Browse files
refactor(probe): name the inspector constructor bound
The three argument constructor signature was written out in the public bound, the scripted test alias and the test stub. A BuildInspector trait states it once. Renames the registry lookup to find_inspector_builder: it builds nothing, it answers whether a chain has a probe and how.
1 parent e6f9987 commit eebadc3

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

  • crates/foreign-chain-health-check/src

crates/foreign-chain-health-check/src/probe.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,12 @@ impl ProbeReport {
101101
}
102102
}
103103

104-
/// Probe every configured provider concurrently, building each provider's inspector with
105-
/// `new_inspector`. The node injects [`rpc_inspector`].
106-
///
107104
/// Each provider is tried up to `max_retries` times, `timeout_sec` per try, and only for as long as
108105
/// the failures stay transient. This returns within the largest configured `timeout_sec *
109106
/// max_retries`, plus the [`foreign_chain_inspector::RETRY_BACKOFF`] between tries.
110107
pub async fn probe_all_providers<I>(
111108
config: &ForeignChainsConfig,
112-
new_inspector: impl Fn(
113-
ForeignChain,
114-
&ForeignChainConfig,
115-
&ForeignChainProviderConfig,
116-
) -> anyhow::Result<I>
117-
+ Sync,
109+
new_inspector: impl BuildInspector<I>,
118110
) -> ProbeReport
119111
where
120112
I: NetworkFingerprintInspector + Clone + Send + Sync + 'static,
@@ -124,7 +116,7 @@ where
124116
let probe_attempts = config
125117
.iter_chains()
126118
.map(|(chain, chain_config)| async move {
127-
if new_rpc_inspector(chain).is_none() {
119+
if find_inspector_builder(chain).is_none() {
128120
return rows_of(chain, chain_config, ProviderStatus::ProbeNotImplemented);
129121
}
130122
probe_chain(chain, chain_config, |provider| {
@@ -139,13 +131,24 @@ where
139131
.into()
140132
}
141133

134+
/// Builds one provider's inspector. The node supplies [`rpc_inspector`]; a test supplies its own.
135+
pub trait BuildInspector<I>:
136+
Fn(ForeignChain, &ForeignChainConfig, &ForeignChainProviderConfig) -> anyhow::Result<I> + Sync
137+
{
138+
}
139+
140+
impl<F, I> BuildInspector<I> for F where
141+
F: Fn(ForeignChain, &ForeignChainConfig, &ForeignChainProviderConfig) -> anyhow::Result<I>
142+
+ Sync
143+
{
144+
}
145+
142146
/// Builds one provider's inspector for a chain whose probe exists.
143-
type NewRpcInspector =
147+
type InspectorBuilder =
144148
fn(&ForeignChainConfig, &ForeignChainProviderConfig) -> anyhow::Result<RpcInspector>;
145149

146-
/// How to build a chain's inspector, or `None` when no probe exists for the chain. The single
147-
/// source of truth for which chains the probe covers.
148-
fn new_rpc_inspector(chain: ForeignChain) -> Option<NewRpcInspector> {
150+
/// The single source of truth for which chains the probe covers.
151+
fn find_inspector_builder(chain: ForeignChain) -> Option<InspectorBuilder> {
149152
Some(match chain {
150153
ForeignChain::Starknet => |_, provider| {
151154
Ok(RpcInspector::Starknet(StarknetInspector::new(http_client(
@@ -255,7 +258,7 @@ pub fn rpc_inspector(
255258
chain_config: &ForeignChainConfig,
256259
provider: &ForeignChainProviderConfig,
257260
) -> anyhow::Result<RpcInspector> {
258-
let Some(new_inspector) = new_rpc_inspector(chain) else {
261+
let Some(new_inspector) = find_inspector_builder(chain) else {
259262
anyhow::bail!("no probe exists for {chain:?}");
260263
};
261264
new_inspector(chain_config, provider)
@@ -592,14 +595,7 @@ mod tests {
592595
// The scripted tests below run under a paused tokio clock; see `foreign_chain_inspector::mock`
593596
// for why that must never be combined with the httpmock or tonic tests in this module.
594597

595-
type NewScripted = Box<
596-
dyn Fn(
597-
ForeignChain,
598-
&ForeignChainConfig,
599-
&ForeignChainProviderConfig,
600-
) -> anyhow::Result<ScriptedInspector>
601-
+ Sync,
602-
>;
598+
type NewScripted = Box<dyn BuildInspector<ScriptedInspector>>;
603599

604600
/// A `new_inspector` for scripted tests: each provider gets the inspector scripted for its
605601
/// URL, and a provider without one fails its setup.

0 commit comments

Comments
 (0)