Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Aug 21, 2024
1 parent 5be3755 commit 052845a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
47 changes: 38 additions & 9 deletions beacon_node/lighthouse_network/src/peer_manager/peerdb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::discovery::enr::PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY;
use crate::discovery::CombinedKey;
use crate::rpc::{MetaData, MetaDataV2};
use crate::EnrExt;
use crate::{metrics, multiaddr::Multiaddr, types::Subnet, Enr, Gossipsub, PeerId};
use peer_info::{ConnectionDirection, PeerConnectionStatus, PeerInfo};
Expand All @@ -14,7 +15,7 @@ use std::{
fmt::Formatter,
};
use sync_status::SyncStatus;
use types::{ChainSpec, EthSpec};
use types::{ChainSpec, DataColumnSubnetId, EthSpec};

pub mod client;
pub mod peer_info;
Expand Down Expand Up @@ -683,15 +684,20 @@ impl<E: EthSpec> PeerDB<E> {
let enr_key = CombinedKey::generate_secp256k1();
let mut enr = Enr::builder().build(&enr_key).unwrap();
let peer_id = enr.peer_id();
let node_id = enr.node_id().raw().into();

if supernode {
enr.insert(
PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY,
&spec.data_column_sidecar_subnet_count,
&enr_key,
)
.expect("u64 can be encoded");
}
let custody_subnet_count = if supernode {
spec.data_column_sidecar_subnet_count
} else {
spec.custody_requirement
};

enr.insert(
PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY,
&custody_subnet_count,
&enr_key,
)
.expect("u64 can be encoded");

self.update_connection_state(
&peer_id,
Expand All @@ -701,6 +707,29 @@ impl<E: EthSpec> PeerDB<E> {
direction: ConnectionDirection::Outgoing,
},
);
let peer = self.peers.get_mut(&peer_id).expect("peer exists");

// Need to insert an empty metadata to pass the condition `on_subnet_metadata`
peer.set_meta_data(MetaData::V2(MetaDataV2 {
seq_number: 0,
attnets: <_>::default(),
syncnets: <_>::default(),
}));

for subnet in
DataColumnSubnetId::compute_custody_columns::<E>(node_id, custody_subnet_count, spec)
{
// Need to pass the tests on PeerInfo
// - on_subnet_metadata: no action, `Subnet::DataColumn` returns true
// - on_subnet_gossipsub: subnets field contains subnet
// - is_good_gossipsub_peer: score >= 0, which equals default score
// peer.set_meta_data(crate::rpc::MetaData::V2(crate::rpc::MetaDataV2 {
// seq_number: 0,
// attnets: <_>::default(),
// syncnets: <_>::default(),
// }));
peer.insert_subnet(Subnet::DataColumn(subnet.into()));
}

peer_id
}
Expand Down
11 changes: 2 additions & 9 deletions beacon_node/network/src/sync/block_lookups/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,8 @@ impl<T: BeaconChainTypes> RequestState<T> for CustodyRequestState<T::EthSpec> {
downloaded_block: Option<Arc<SignedBeaconBlock<T::EthSpec>>>,
cx: &mut SyncNetworkContext<T>,
) -> Result<LookupRequestResult, LookupRequestError> {
let x = cx
.custody_lookup_request(id, self.block_root, downloaded_block)
.map_err(LookupRequestError::SendFailedNetwork);
match x.as_ref().unwrap() {
LookupRequestResult::RequestSent { .. } => println!("RequestSent"),
LookupRequestResult::NoRequestNeeded(s) => println!("NoRequestNeeded {}", s),
LookupRequestResult::Pending(s) => println!("Pending {}", s),
}
x
cx.custody_lookup_request(id, self.block_root, downloaded_block)
.map_err(LookupRequestError::SendFailedNetwork)
}

fn send_for_processing(
Expand Down
8 changes: 8 additions & 0 deletions beacon_node/network/src/sync/block_lookups/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ impl TestRig {
}
// One supernode peer to ensure all columns have at least one peer
self.new_connected_supernode_peer();

// ensure we have peers in each subnet
for i in 0..self.harness.spec.data_column_sidecar_subnet_count {
let peers = self
.network_globals
.custody_peers_for_column(i, &self.harness.spec);
println!("peers column {} {:?}", i, peers);
}
}

fn parent_chain_processed_success(
Expand Down

0 comments on commit 052845a

Please sign in to comment.