Skip to content

Commit

Permalink
Add metrics and update code comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jul 1, 2024
1 parent 03a9dce commit cfb3ebc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ impl<E: EthSpec> PeerInfo<E> {
.map_or(false, |s| s.get(**id as usize).unwrap_or(false))
}
Subnet::DataColumn(_) => {
// There's no metadata field for data column subnets, we use the `csc` enr field
// along with `node_id` to determine whether peer SHOULD be subscribed to a
// given subnet.
// TODO(das): Pending spec PR https://github.com/ethereum/consensus-specs/pull/3821
return true;
}
}
Expand Down
6 changes: 5 additions & 1 deletion beacon_node/lighthouse_network/src/types/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ mod test {
drop(peers_db_write_lock);

let custody_subnets = (0..spec.data_column_sidecar_subnet_count)
.filter(|col_index| !globals.custody_peers_for_column(*col_index, &spec).is_empty())
.filter(|col_index| {
!globals
.custody_peers_for_column(*col_index, &spec)
.is_empty()
})
.count();

// The single peer's custody subnet should match custody_requirement.
Expand Down
5 changes: 5 additions & 0 deletions beacon_node/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ lazy_static! {
"Number of connected peers per sync status type",
&["sync_status"]
);
pub static ref PEERS_PER_COLUMN_SUBNET: Result<IntGaugeVec> = try_create_int_gauge_vec(
"peers_per_column_subnet",
"Number of connected peers per column subnet",
&["subnet_id"]
);
pub static ref SYNCING_CHAINS_COUNT: Result<IntGaugeVec> = try_create_int_gauge_vec(
"sync_range_chains",
"Number of Syncing chains in range, per range type",
Expand Down
13 changes: 11 additions & 2 deletions beacon_node/network/src/sync/range_sync/chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::batch::{BatchInfo, BatchProcessingResult, BatchState};
use crate::metrics::PEERS_PER_COLUMN_SUBNET;
use crate::network_beacon_processor::ChainSegmentProcessId;
use crate::sync::network_context::RangeRequestId;
use crate::sync::{
Expand All @@ -7,6 +8,7 @@ use crate::sync::{
use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::BeaconChainTypes;
use fnv::FnvHashMap;
use lighthouse_metrics::set_int_gauge;
use lighthouse_network::{PeerAction, PeerId, Subnet};
use rand::seq::SliceRandom;
use slog::{crit, debug, o, warn};
Expand Down Expand Up @@ -397,7 +399,9 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
}
}
} else if !self.good_peers_on_custody_subnets(self.processing_target, network) {
// If there's no good custody peers for this epoch, batch won't be created
// This is to handle the case where no batch was sent for the current processing
// target when there is no custody peers available. This is a valid state and should not
// return an error.
return Ok(KeepChain);
} else {
return Err(RemoveChain::WrongChainState(format!(
Expand Down Expand Up @@ -1044,7 +1048,12 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
.read()
.good_peers_on_subnet(Subnet::DataColumn(subnet_id))
.count();
debug!(self.log, "Peers found on custody subnet"; "subnet_id" => ?subnet_id, "peer_count" => peer_count);

set_int_gauge(
&PEERS_PER_COLUMN_SUBNET,
&[&subnet_id.to_string()],
peer_count as i64,
);
peer_count > 0
});
peers_on_all_custody_subnets
Expand Down

0 comments on commit cfb3ebc

Please sign in to comment.