fn extract_updates(
    network_context: Arc<NetworkContext>,
    encryptor: &Encryptor,
    node_set: ValidatorSet,
) -> Vec<ConnectivityRequest> {
    let role = network_context.role();

    // Decode addresses while ignoring bad addresses
    let new_peer_addrs: HashMap<_, _> = node_set
        .into_iter()
        .map(|info| {
            let peer_id = *info.account_address();
            let config = info.into_config();

            let addrs = match role {
                RoleType::Validator => {
                    let result = encryptor.decrypt(&config.validator_network_addresses, peer_id);
                    if let Err(EncryptorError::StorageError(_)) = result {
                        panic!(format!(
                            "Unable to initialize validator network addresses: {:?}",
                            result
                        ));
                    }
                    result.map_err(anyhow::Error::from)
                }
                RoleType::FullNode => config
                    .fullnode_network_addresses()
                    .map_err(anyhow::Error::from),
            }
            .map_err(|err| {
                inc_by_with_context(&DISCOVERY_COUNTS, &network_context, "read_failure", 1);

                warn!(
                    NetworkSchema::new(&network_context),
                    "OnChainDiscovery: Failed to parse any network address: peer: {}, err: {}",
                    peer_id,
                    err
                )
            })
            .unwrap_or_default();

            (peer_id, addrs)
        })
        .collect();

    // Retrieve public keys from addresses
    let new_peer_pubkeys: HashMap<_, _> = new_peer_addrs
        .iter()
        .map(|(peer_id, addrs)| {
            let pubkeys: HashSet<x25519::PublicKey> = addrs
                .iter()
                .filter_map(NetworkAddress::find_noise_proto)
                .collect();
            (*peer_id, pubkeys)
        })
        .collect();

    vec![
        ConnectivityRequest::UpdateAddresses(DiscoverySource::OnChain, new_peer_addrs),
        ConnectivityRequest::UpdateEligibleNodes(DiscoverySource::OnChain, new_peer_pubkeys),
    ]
}
/// Extracts a set of ConnectivityRequests from a ValidatorSet which are appropriate for a network with type role.
Extracts a set of ConnectivityRequests from a ValidatorSet which are appropriate for a network with type role.
Extracts a set of ConnectivityRequests from a ValidatorSet which are appropriate for a network with type role .
fn extract_updates(
    network_context: Arc<NetworkContext>,
    encryptor: &Encryptor,
    node_set: ValidatorSet,
) -> Vec<ConnectivityRequest> {
    let role = network_context.role();
    // Decode addresses while ignoring bad addresses
    let new_peer_addrs: HashMap<_, _> = node_set
        .into_iter()
        .map(|info| {
            let peer_id = *info.account_address();
            let config = info.into_config();
            let addrs = match role {
                RoleType::Validator => {
                    let result = encryptor.decrypt(&config.validator_network_addresses, peer_id);
                    if let Err(EncryptorError::StorageError(_)) = result {
                        panic!(format!(
                            "Unable to initialize validator network addresses: {:?}",
                            result
                        ));
                    }
                    result.map_err(anyhow::Error::from)
                }
                RoleType::FullNode => config
                    .fullnode_network_addresses()
                    .map_err(anyhow::Error::from),
            }
            .map_err(|err| {
                inc_by_with_context(&DISCOVERY_COUNTS, &network_context, "read_failure", 1);
                warn!(
                    NetworkSchema::new(&network_context),
                    "OnChainDiscovery: Failed to parse any network address: peer: {}, err: {}",
                    peer_id,
                    err
                )
            })
            .unwrap_or_default();
            (peer_id, addrs)
        })
        .collect();
    // Retrieve public keys from addresses
    let new_peer_pubkeys: HashMap<_, _> = new_peer_addrs
        .iter()
        .map(|(peer_id, addrs)| {
            let pubkeys: HashSet<x25519::PublicKey> = addrs
                .iter()
                .filter_map(NetworkAddress::find_noise_proto)
                .collect();
            (*peer_id, pubkeys)
        })
        .collect();
    vec![
        ConnectivityRequest::UpdateAddresses(DiscoverySource::OnChain, new_peer_addrs),
        ConnectivityRequest::UpdateEligibleNodes(DiscoverySource::OnChain, new_peer_pubkeys),
    ]
}
fn extract_updates ( network_context : Arc < NetworkContext > , encryptor : & Encryptor , node_set : ValidatorSet , ) -> Vec < ConnectivityRequest > { let role = network_context . role ( ) ; // Decode addresses while ignoring bad addresses let new_peer_addrs : HashMap < _ , _ > = node_set . into_iter ( ) . map ( | info | { let peer_id = * info . account_address ( ) ; let config = info . into_config ( ) ; let addrs = match role { RoleType :: Validator => { let result = encryptor . decrypt ( & config . validator_network_addresses , peer_id ) ; if let Err ( EncryptorError :: StorageError ( _ ) ) = result { panic ! ( format ( " " result ) ) ; } result . map_err ( anyhow :: Error :: from ) } RoleType :: FullNode => config . fullnode_network_addresses ( ) . map_err ( anyhow :: Error :: from ) , } . map_err ( | err | { inc_by_with_context ( & DISCOVERY_COUNTS , & network_context , " " , 1 ) ; warn ! ( NetworkSchema new ( network_context ) " " peer_id err ) } ) . unwrap_or_default ( ) ; ( peer_id , addrs ) } ) . collect ( ) ; // Retrieve public keys from addresses let new_peer_pubkeys : HashMap < _ , _ > = new_peer_addrs . iter ( ) . map ( | ( peer_id , addrs ) | { let pubkeys : HashSet < x25519 :: PublicKey > = addrs . iter ( ) . filter_map ( NetworkAddress :: find_noise_proto ) . collect ( ) ; ( * peer_id , pubkeys ) } ) . collect ( ) ; vec ! [ ConnectivityRequest UpdateAddresses ( DiscoverySource OnChain new_peer_addrs ) ConnectivityRequest UpdateEligibleNodes ( DiscoverySource OnChain new_peer_pubkeys ) ] }
Extracts a set of ConnectivityRequests from a ValidatorSet which are appropriate for a network with type role.
Extracts a set of ConnectivityRequests from a ValidatorSet which are appropriate for a network with type role .
network_context
Arc<NetworkContext>
encryptor
&Encryptor
node_set
ValidatorSet
network_context
Arc<NetworkContext>
encryptor
&Encryptor
node_set
ValidatorSet