mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-17 10:48:28 +00:00
Merge remote-tracking branch 'sigp/unstable' into gloas-range-sync
This commit is contained in:
@@ -793,12 +793,39 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the connection state. MUST ONLY BE USED IN TESTS.
|
||||
pub fn __add_connected_peer_testing_only(
|
||||
/// Adds a connected peer to the PeerDB and sets the custody subnets.
|
||||
/// WARNING: This updates the connection state. MUST ONLY BE USED IN TESTS.
|
||||
pub fn __add_connected_peer_with_custody_subnets(
|
||||
&mut self,
|
||||
supernode: bool,
|
||||
spec: &ChainSpec,
|
||||
enr_key: CombinedKey,
|
||||
) -> PeerId {
|
||||
let peer_id = self.__add_connected_peer(supernode, enr_key, spec);
|
||||
|
||||
let subnets = if supernode {
|
||||
(0..spec.data_column_sidecar_subnet_count)
|
||||
.map(|subnet_id| subnet_id.into())
|
||||
.collect()
|
||||
} else {
|
||||
let node_id = peer_id_to_node_id(&peer_id).expect("convert peer_id to node_id");
|
||||
compute_subnets_for_node::<E>(node_id.raw(), spec.custody_requirement, spec)
|
||||
.expect("should compute custody subnets")
|
||||
};
|
||||
|
||||
let peer_info = self.peers.get_mut(&peer_id).expect("peer exists");
|
||||
peer_info.set_custody_subnets(subnets);
|
||||
|
||||
peer_id
|
||||
}
|
||||
|
||||
/// Adds a connected peer to the PeerDB and updates the connection state.
|
||||
/// MUST ONLY BE USED IN TESTS.
|
||||
pub fn __add_connected_peer(
|
||||
&mut self,
|
||||
supernode: bool,
|
||||
enr_key: CombinedKey,
|
||||
spec: &ChainSpec,
|
||||
) -> PeerId {
|
||||
let mut enr = Enr::builder().build(&enr_key).unwrap();
|
||||
let peer_id = enr.peer_id();
|
||||
@@ -835,24 +862,21 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
},
|
||||
);
|
||||
|
||||
if supernode {
|
||||
let peer_info = self.peers.get_mut(&peer_id).expect("peer exists");
|
||||
let all_subnets = (0..spec.data_column_sidecar_subnet_count)
|
||||
.map(|subnet_id| subnet_id.into())
|
||||
.collect();
|
||||
peer_info.set_custody_subnets(all_subnets);
|
||||
} else {
|
||||
let peer_info = self.peers.get_mut(&peer_id).expect("peer exists");
|
||||
let node_id = peer_id_to_node_id(&peer_id).expect("convert peer_id to node_id");
|
||||
let subnets =
|
||||
compute_subnets_for_node::<E>(node_id.raw(), spec.custody_requirement, spec)
|
||||
.expect("should compute custody subnets");
|
||||
peer_info.set_custody_subnets(subnets);
|
||||
}
|
||||
|
||||
peer_id
|
||||
}
|
||||
|
||||
/// MUST ONLY BE USED IN TESTS.
|
||||
pub fn __set_custody_subnets(
|
||||
&mut self,
|
||||
peer_id: &PeerId,
|
||||
custody_subnets: HashSet<DataColumnSubnetId>,
|
||||
) -> Result<(), String> {
|
||||
self.peers
|
||||
.get_mut(peer_id)
|
||||
.map(|info| info.set_custody_subnets(custody_subnets))
|
||||
.ok_or_else(|| "Cannot set custody subnets, peer not found".to_string())
|
||||
}
|
||||
|
||||
/// The connection state of the peer has been changed. Modify the peer in the db to ensure all
|
||||
/// variables are in sync with libp2p.
|
||||
/// Updating the state can lead to a `BanOperation` which needs to be processed via the peer
|
||||
|
||||
Reference in New Issue
Block a user