Skip to content

Commit 29abe9c

Browse files
committed
Fix custody subnet count encoding (sigp#5997)
Squashed commit of the following: commit 39cd0d3 Author: Jimmy Chen <[email protected]> Date: Wed Jun 26 22:36:16 2024 +1000 Fix csc encoding and decoding
1 parent a14b6c3 commit 29abe9c

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

beacon_node/lighthouse_network/src/discovery/enr.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl Eth2Enr for Enr {
6767
/// if the custody value is non-existent in the ENR, then we assume the minimum custody value
6868
/// defined in the spec.
6969
fn custody_subnet_count<E: EthSpec>(&self, spec: &ChainSpec) -> u64 {
70-
self.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
71-
.and_then(|custody_bytes| custody_bytes.try_into().map(u64::from_be_bytes).ok())
70+
self.get_decodable::<u64>(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
71+
.and_then(|r| r.ok())
7272
// If value supplied in ENR is invalid, fallback to `custody_requirement`
7373
.filter(|csc| csc <= &spec.data_column_sidecar_subnet_count)
7474
.unwrap_or(spec.custody_requirement)
@@ -245,8 +245,7 @@ pub fn build_enr<E: EthSpec>(
245245
spec.custody_requirement
246246
};
247247

248-
let csc_bytes = custody_subnet_count.to_be_bytes();
249-
builder.add_value(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY, &csc_bytes.as_slice());
248+
builder.add_value(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY, &custody_subnet_count);
250249

251250
builder
252251
.build(enr_key)
@@ -353,11 +352,11 @@ mod test {
353352
let config = NetworkConfig::default();
354353
let spec = E::default_spec();
355354
let (mut enr, enr_key) = build_enr_with_config(config, &spec);
356-
let invalid_subnet_count = 999u64;
355+
let invalid_subnet_count = 99u64;
357356

358357
enr.insert(
359358
PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY,
360-
&invalid_subnet_count.to_be_bytes().as_slice(),
359+
&invalid_subnet_count,
361360
&enr_key,
362361
)
363362
.unwrap();

beacon_node/lighthouse_network/src/peer_manager/peerdb.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,7 @@ impl<E: EthSpec> PeerDB<E> {
686686
if supernode {
687687
enr.insert(
688688
PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY,
689-
&spec
690-
.data_column_sidecar_subnet_count
691-
.to_be_bytes()
692-
.as_slice(),
689+
&spec.data_column_sidecar_subnet_count,
693690
&enr_key,
694691
)
695692
.expect("u64 can be encoded");

0 commit comments

Comments
 (0)