Skip to content

Commit 90ae97a

Browse files
committed
Changed chain IDs internally to U256
1 parent e0fa6cb commit 90ae97a

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

crates/common/src/config/pbs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ impl PbsConfig {
169169
if !matches!(chain, Chain::Custom { .. }) {
170170
let provider = ProviderBuilder::new().on_http(rpc_url.clone());
171171
let chain_id = provider.get_chain_id().await?;
172+
let chain_id_big = U256::from(chain_id);
172173
ensure!(
173-
chain_id == chain.id(),
174+
chain_id_big == chain.id(),
174175
"Rpc url is for the wrong chain, expected: {} ({:?}) got {}",
175176
chain.id(),
176177
chain,
177-
chain_id
178+
chain_id_big
178179
);
179180
}
180181
}

crates/common/src/types.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::PathBuf;
22

3-
use alloy::primitives::{aliases::B32, hex, Bytes, B256};
3+
use alloy::primitives::{aliases::B32, hex, Bytes, B256, U256};
44
use derive_more::{Deref, Display, From, Into};
55
use eyre::{bail, Context};
66
use serde::{Deserialize, Serialize};
@@ -72,7 +72,9 @@ impl std::fmt::Debug for Chain {
7272
}
7373

7474
impl Chain {
75-
pub fn id(&self) -> u64 {
75+
// Chain IDs are 256-bit unsigned integers because they need to support
76+
// Keccak256 hashes
77+
pub fn id(&self) -> U256 {
7678
match self {
7779
Chain::Mainnet => KnownChain::Mainnet.id(),
7880
Chain::Holesky => KnownChain::Holesky.id(),
@@ -146,13 +148,13 @@ pub enum KnownChain {
146148

147149
// Constants
148150
impl KnownChain {
149-
pub fn id(&self) -> u64 {
151+
pub fn id(&self) -> U256 {
150152
match self {
151-
KnownChain::Mainnet => 1,
152-
KnownChain::Holesky => 17000,
153-
KnownChain::Sepolia => 11155111,
154-
KnownChain::Helder => 167000,
155-
KnownChain::Hoodi => 560048,
153+
KnownChain::Mainnet => U256::from(1),
154+
KnownChain::Holesky => U256::from(17000),
155+
KnownChain::Sepolia => U256::from(11155111),
156+
KnownChain::Helder => U256::from(167000),
157+
KnownChain::Hoodi => U256::from(560048),
156158
}
157159
}
158160

crates/common/src/utils.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use alloy::{
9-
primitives::U256,
9+
primitives::{B256, U256},
1010
rpc::types::beacon::{BlsPublicKey, BlsSignature},
1111
};
1212
use axum::http::HeaderValue;
@@ -443,6 +443,22 @@ pub fn get_user_agent_with_version(req_headers: &HeaderMap) -> eyre::Result<Head
443443
Ok(HeaderValue::from_str(&format!("commit-boost/{HEADER_VERSION_VALUE} {}", ua))?)
444444
}
445445

446+
// Trait for converting from u64 to B256
447+
pub trait FromU64 {
448+
/// Converts a u64 to a B256 by left-padding with zeros
449+
fn from_u64(value: u64) -> B256;
450+
}
451+
452+
impl FromU64 for B256 {
453+
/// Converts a u64 into a B256 by left-padding with zeros
454+
fn from_u64(value: u64) -> B256 {
455+
let mut buffer = [0u8; 32];
456+
let bytes = value.to_be_bytes();
457+
buffer[24..].copy_from_slice(&bytes);
458+
B256::from(buffer)
459+
}
460+
}
461+
446462
#[cfg(unix)]
447463
pub async fn wait_for_signal() -> eyre::Result<()> {
448464
use tokio::signal::unix::{signal, SignalKind};

0 commit comments

Comments
 (0)