pub struct MultiChainCoordinator { /* private fields */ }Expand description
Tracks and coordinates multiple chain indexer instances.
This is a state-management layer: it stores the runtime state of each
chain and provides query/mutation primitives. The actual indexer tasks
(which require an RPC provider) are started by the caller using the config
returned from [chain_state].
Implementations§
Source§impl MultiChainCoordinator
impl MultiChainCoordinator
Sourcepub fn new(config: MultiChainConfig) -> Self
pub fn new(config: MultiChainConfig) -> Self
Create a new coordinator from the given config.
All chains in config.chains are registered in the IndexerState::Idle
state — they are not started automatically.
Sourcepub async fn add_chain(&self, config: IndexerConfig) -> Result<(), IndexerError>
pub async fn add_chain(&self, config: IndexerConfig) -> Result<(), IndexerError>
Register a new chain at runtime.
Returns an error if a chain with the same id already exists.
Sourcepub async fn remove_chain(&self, chain_id: &str) -> Result<(), IndexerError>
pub async fn remove_chain(&self, chain_id: &str) -> Result<(), IndexerError>
Remove a chain from the coordinator.
The caller is responsible for ensuring the underlying task is stopped before calling this method. Returns an error if the chain is not found.
Sourcepub async fn pause_chain(&self, chain_id: &str) -> Result<(), IndexerError>
pub async fn pause_chain(&self, chain_id: &str) -> Result<(), IndexerError>
Pause a chain by transitioning it to IndexerState::Stopping.
Only chains in an active state (Backfilling, Live, ReorgRecovery) can be paused. Returns an error if the chain is not found or not active.
Sourcepub async fn resume_chain(&self, chain_id: &str) -> Result<(), IndexerError>
pub async fn resume_chain(&self, chain_id: &str) -> Result<(), IndexerError>
Resume a paused or stopped chain by transitioning it back to
IndexerState::Backfilling.
Returns an error if the chain is not found or is already active.
Sourcepub async fn update_state(
&self,
chain_id: &str,
new_state: IndexerState,
error: Option<String>,
) -> Result<(), IndexerError>
pub async fn update_state( &self, chain_id: &str, new_state: IndexerState, error: Option<String>, ) -> Result<(), IndexerError>
Update the state of a chain. Called by the underlying indexer task.
Sourcepub async fn record_block(
&self,
chain_id: &str,
block_number: u64,
events: u64,
) -> Result<(), IndexerError>
pub async fn record_block( &self, chain_id: &str, block_number: u64, events: u64, ) -> Result<(), IndexerError>
Record a new block processed by a chain.
Sourcepub async fn health(&self) -> Vec<ChainHealth>
pub async fn health(&self) -> Vec<ChainHealth>
Returns health snapshots for every registered chain.
Sourcepub async fn chain_health(&self, chain_id: &str) -> Option<ChainHealth>
pub async fn chain_health(&self, chain_id: &str) -> Option<ChainHealth>
Returns health for a specific chain by id.
Sourcepub async fn chain_state(&self, chain_id: &str) -> Option<ChainInstance>
pub async fn chain_state(&self, chain_id: &str) -> Option<ChainInstance>
Returns a clone of the runtime state for a single chain.
Sourcepub async fn active_chains(&self) -> Vec<String>
pub async fn active_chains(&self) -> Vec<String>
Returns the ids of all chains that are actively indexing.
Sourcepub async fn is_all_healthy(&self) -> bool
pub async fn is_all_healthy(&self) -> bool
Returns true when every registered chain is healthy (active, no error).
Sourcepub async fn all_past_block(&self, min_block: u64) -> bool
pub async fn all_past_block(&self, min_block: u64) -> bool
Returns true when every registered chain has reached at least
min_block.
Sourcepub async fn chain_count(&self) -> usize
pub async fn chain_count(&self) -> usize
Returns the number of registered chains.
Sourcepub fn config(&self) -> &MultiChainConfig
pub fn config(&self) -> &MultiChainConfig
Returns the coordinator config.