Skip to content

Commit 8ae1f0c

Browse files
committed
drop hashmap and inline get_ssz_value_offset_for_fork
1 parent 29c2a83 commit 8ae1f0c

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

crates/common/src/utils.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#[cfg(feature = "testing-flags")]
22
use std::cell::Cell;
33
use std::{
4-
collections::HashMap,
54
fmt::Display,
65
net::Ipv4Addr,
76
str::FromStr,
@@ -17,7 +16,6 @@ use axum::http::HeaderValue;
1716
use bytes::Bytes;
1817
use futures::StreamExt;
1918
use headers_accept::Accept;
20-
use lazy_static::lazy_static;
2119
use lh_bls::Signature;
2220
pub use lh_types::ForkName;
2321
use lh_types::{
@@ -62,24 +60,6 @@ pub const WILDCARD: &str = "*/*";
6260
const MILLIS_PER_SECOND: u64 = 1_000;
6361
pub const CONSENSUS_VERSION_HEADER: &str = "Eth-Consensus-Version";
6462

65-
lazy_static! {
66-
static ref SSZ_VALUE_OFFSETS_BY_FORK: HashMap<ForkName, usize> = {
67-
let mut map: HashMap<ForkName, usize> = HashMap::new();
68-
let forks = [
69-
ForkName::Bellatrix,
70-
ForkName::Capella,
71-
ForkName::Deneb,
72-
ForkName::Electra,
73-
ForkName::Fulu,
74-
];
75-
for fork in forks {
76-
let offset = get_ssz_value_offset_for_fork(fork).unwrap(); // If there isn't a supported fork, this needs to be updated prior to release so panicking is fine
77-
map.insert(fork, offset);
78-
}
79-
map
80-
};
81-
}
82-
8363
#[derive(Debug, Error)]
8464
pub enum ResponseReadError {
8565
#[error(
@@ -978,8 +958,7 @@ pub fn get_bid_value_from_signed_builder_bid_ssz(
978958
response_bytes: &[u8],
979959
fork: ForkName,
980960
) -> Result<U256, SszValueError> {
981-
let value_offset = SSZ_VALUE_OFFSETS_BY_FORK
982-
.get(&fork)
961+
let value_offset = get_ssz_value_offset_for_fork(fork)
983962
.ok_or(SszValueError::UnsupportedFork { name: fork.to_string() })?;
984963

985964
// Sanity check the response length so we don't panic trying to slice it
@@ -992,7 +971,7 @@ pub fn get_bid_value_from_signed_builder_bid_ssz(
992971
}
993972

994973
// Extract the value bytes and convert to U256
995-
let value_bytes = &response_bytes[*value_offset..end_offset];
974+
let value_bytes = &response_bytes[value_offset..end_offset];
996975
let value = U256::from_le_slice(value_bytes);
997976
Ok(value)
998977
}

0 commit comments

Comments
 (0)