bp_resolver.rs

Overview

The bp_resolver.rs file implements a concrete version of the BPResolver trait, responsible for resolving and retrieving the network addresses of "block producers" (BPs) based on thread identifiers within a distributed system. It serves as a bridge between the dynamic set of peers currently connected (received via a Tokio watch channel) and the persistent repository that maps threads to their corresponding BP node identifiers.

The main functionality centers around mapping thread IDs to their associated BP network addresses (SocketAddr), enabling other components in the system to route messages or requests to the correct BP nodes. This file is particularly concerned with keeping the BP resolution up-to-date as the set of peers changes over time.


Structs and Traits

BPResolverImpl


Trait Implementation: BPResolver for BPResolverImpl

The trait BPResolver defines the contract for resolving block producer addresses, which BPResolverImpl fulfills.

Method: resolve

fn resolve(&mut self, thread_id: Option<String>) -> Vec<SocketAddr>

Key Dependencies and Interactions


Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

classDiagram
class BPResolver {
<<trait>>
+resolve(thread_id: Option<String>) Vec<SocketAddr>
}
class BPResolverImpl {
-peers_rx: watch::Receiver<HashMap<NodeIdentifier, Vec<PeerData>>>
-repository: Arc<Mutex<RepositoryImpl>>
+new(peers_rx, repository)
+resolve(thread_id: Option<String>) Vec<SocketAddr>
}
class RepositoryImpl {
+get_nodes_by_threads() HashMap<ThreadId, Option<NodeIdentifier>>
}
BPResolverImpl ..|> BPResolver
BPResolverImpl --> RepositoryImpl : uses (via mutex)
BPResolverImpl --> "watch::Receiver" : listens to peer updates

This diagram illustrates the relationship between BPResolverImpl, the BPResolver trait it implements, its dependency on the RepositoryImpl, and its consumption of peer data through a Tokio watch channel receiver. The key method resolve is highlighted within the trait and the implementation.