Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions Dockerfile.devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG RUST_VERSION=1.83.0
FROM rust:${RUST_VERSION}-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . anchor
ARG FEATURES=spec-minimal
ARG PROFILE=release
ARG CARGO_USE_GIT_CLI=true
ENV FEATURES=$FEATURES
ENV PROFILE=$PROFILE
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_USE_GIT_CLI
RUN cd anchor && make

FROM ubuntu:22.04
RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
jq \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/anchor /usr/local/bin/anchor
WORKDIR /usr/local/bin
30 changes: 14 additions & 16 deletions anchor/eth/src/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,20 @@ impl EventProcessor {
)
})?;

// Make sure the data is the expected length
if data.len() != 704 {
debug!(operator_id = ?operator_id, expected = 704, actual = data.len(), "Invalid public key data length");
return Err(ExecutionError::InvalidEvent(format!(
"Invalid public key data length. Expected 704, got {}",
data.len()
)));
}

// Remove abi encoding information and then convert to valid utf8 string
let data = &data[64..];
let data = String::from_utf8(data.to_vec()).map_err(|e| {
debug!(operator_id = ?operator_id, error = %e, "Failed to convert to UTF8 String");
ExecutionError::InvalidEvent(format!("Failed to convert to UTF8 String: {e}"))
})?;
let data = data.trim_matches(char::from(0)).to_string();
// If the data is 704 bytes, remove the ssv encoding. Else, just parse the key
let data = if data.len() == 704 {
let data = &data[64..];
let data = String::from_utf8(data.to_vec()).map_err(|e| {
debug!(operator_id = ?operator_id, error = %e, "Failed to convert to UTF8 String");
ExecutionError::InvalidEvent(format!("Failed to convert to UTF8 String: {e}"))
})?;
data.trim_matches(char::from(0)).to_string()
} else {
String::from_utf8(data.to_vec()).map_err(|e| {
debug!(operator_id = ?operator_id, error = %e, "Failed to convert to UTF8 String");
ExecutionError::InvalidEvent(format!("Failed to convert to UTF8 String: {e}"))
})?
};

// Construct the Operator and insert it into the database
let operator = Operator::new(&data, operator_id, owner).map_err(|e| {
Expand Down
2 changes: 1 addition & 1 deletion anchor/eth/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl SsvEventSyncer {
}

// Construct a future that will fetch logs in the range from_block..to_block
#[instrument(skip(self, deployment_address))]
#[instrument(skip(self, deployment_address, events))]
fn fetch_logs(
&self,
from_block: u64,
Expand Down
27 changes: 25 additions & 2 deletions anchor/network/src/discovery.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;
use std::fs::File;
use std::future::Future;
use std::io::Write;
use std::net::{SocketAddrV4, SocketAddrV6};
use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Instant;
Expand All @@ -21,7 +24,7 @@ use libp2p::swarm::{
THandlerOutEvent, ToSwarm,
};
use lighthouse_network::discovery::enr_ext::{QUIC6_ENR_KEY, QUIC_ENR_KEY};
use lighthouse_network::discovery::DiscoveredPeers;
use lighthouse_network::discovery::{DiscoveredPeers, ENR_FILENAME};
use lighthouse_network::CombinedKeyExt;
use tokio::sync::mpsc;
use tracing::{debug, error, info, trace, warn};
Expand Down Expand Up @@ -130,7 +133,7 @@ impl Discovery {
local_keypair: Keypair,
network_config: &Config,
) -> Result<Self, DiscoveryError> {
let _enr_dir = match network_config.network_dir.to_str() {
let enr_dir = match network_config.network_dir.to_str() {
Some(path) => String::from(path),
None => String::from(""),
};
Expand All @@ -155,6 +158,7 @@ impl Discovery {
CombinedKey::from_libp2p(local_keypair).map_err(|e| EnrKey(e.to_string()))?;

let enr = build_enr(&enr_key, network_config).map_err(EnrBuild)?;
save_enr_to_disk(Path::new(&enr_dir), &enr);

info!(%enr, "Created local ENR");

Expand Down Expand Up @@ -598,6 +602,25 @@ pub fn build_enr(enr_key: &CombinedKey, config: &Config) -> Result<Enr, Error> {
Ok(enr)
}

/// Saves an ENR to disk
pub fn save_enr_to_disk(dir: &Path, enr: &Enr) {
let _ = std::fs::create_dir_all(dir);
Copy link

Copilot AI Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling errors from create_dir_all instead of ignoring them. Logging or propagating the error may help diagnose filesystem permission issues.

Suggested change
let _ = std::fs::create_dir_all(dir);
if let Err(e) = std::fs::create_dir_all(dir) {
warn!(
directory = format!("{:?}", dir),
error = %e,
"Could not create directory"
);
return;
}

Copilot uses AI. Check for mistakes.
match File::create(dir.join(Path::new(ENR_FILENAME)))
.and_then(|mut f| f.write_all(enr.to_base64().as_bytes()))
{
Ok(_) => {
debug!("ENR written to disk");
}
Err(e) => {
warn!(
file = format!("{:?}{:?}",dir, ENR_FILENAME),
error = %e,
"Could not write ENR to file"
);
}
}
}

fn committee_bitfield(enr: &Enr) -> Result<Bitfield<Fixed<U128>>, &'static str> {
let bitfield_bytes: Bytes = enr
.get_decodable("subnets")
Expand Down
Loading