Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration - submit and registered event #76

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions Node/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ chrono = "0.4"
p2p-network = { path = "../p2pNode/p2pNetwork" }
bincode = "1.3"
serde_bytes = "0.11"
clap = "4.5"
futures-util = "0.3"

[dev-dependencies]
mockito = "1.4"
53 changes: 51 additions & 2 deletions Node/src/ethereum_l1/execution_layer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::slot_clock::SlotClock;
use crate::utils::config;
use alloy::{
contract::EventPoller,
network::{Ethereum, EthereumWallet, NetworkWallet},
primitives::{Address, Bytes, FixedBytes, U256},
providers::ProviderBuilder,
Expand All @@ -14,6 +15,7 @@ use alloy::{
use anyhow::Error;
use beacon_api_client::ProposerDuty;
use ecdsa::SigningKey;
use futures_util::StreamExt;
use k256::Secp256k1;
use rand_core::{OsRng, RngCore};
use std::str::FromStr;
Expand Down Expand Up @@ -203,7 +205,7 @@ impl ExecutionLayer {
Ok(())
}

pub async fn register(&self) -> Result<(), Error> {
pub async fn register_preconfer(&self) -> Result<(), Error> {
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(self.wallet.clone())
Expand Down Expand Up @@ -307,6 +309,53 @@ impl ExecutionLayer {
Ok(())
}

pub async fn watch_for_registered_event(
&self,
) -> Result<
EventPoller<
alloy::transports::http::Http<reqwest::Client>,
PreconfRegistry::PreconferRegistered,
>,
Error,
> {
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(self.wallet.clone())
.on_http(self.rpc_url.clone());

let registry = PreconfRegistry::new(self.contract_addresses.avs.preconf_registry, provider);
let registered_filter = registry.PreconferRegistered_filter().watch().await?;
tracing::debug!("Subscribed to registered event");

Ok(registered_filter)
}

pub async fn wait_for_the_registered_event(
&self,
registered_filter: EventPoller<
alloy::transports::http::Http<reqwest::Client>,
PreconfRegistry::PreconferRegistered,
>,
) -> Result<(), Error> {
let mut stream = registered_filter.into_stream();
while let Some(log) = stream.next().await {
match log {
Ok(log) => {
tracing::info!("Received PreconferRegistered for: {}", log.0.preconfer);
if log.0.preconfer == self.avs_node_address {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should clearly define what preconfer, avs_node, and validator mean, and ensure we're using these terms consistently throughout the codebase.

tracing::info!("Preconfer registered!");
break;
}
}
Err(e) => {
tracing::error!("Error receiving log: {:?}", e);
}
}
}

Ok(())
}

#[cfg(test)]
pub fn new_from_pk(
rpc_url: reqwest::Url,
Expand Down Expand Up @@ -414,7 +463,7 @@ mod tests {
let private_key = anvil.keys()[0].clone();
let el = ExecutionLayer::new_from_pk(rpc_url, private_key).unwrap();

let result = el.register().await;
let result = el.register_preconfer().await;
assert!(result.is_ok(), "Register method failed: {:?}", result.err());
}
}
40 changes: 28 additions & 12 deletions Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@ mod ethereum_l1;
mod mev_boost;
mod node;
mod p2p_network;
mod registration;
mod taiko;
mod utils;

use anyhow::Error;
use clap::Parser;
use node::block_proposed_receiver::BlockProposedEventReceiver;
use std::sync::Arc;
use tokio::sync::mpsc;

const MESSAGE_QUEUE_SIZE: usize = 100;

#[derive(Parser)]
struct Cli {
#[clap(long, help = "Start registration as a preconfer")]
register: bool,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
init_logging();
let args = Cli::parse();
let config = utils::config::Config::read_env_variables();

let ethereum_l1 = ethereum_l1::EthereumL1::new(
&config.mev_boost_url,
&config.avs_node_ecdsa_private_key,
&config.contract_addresses,
&config.l1_beacon_url,
config.l1_slot_duration_sec,
config.l1_slots_per_epoch,
config.preconf_registry_expiry_sec,
)
.await?;

if args.register {
let registration = registration::Registration::new(ethereum_l1);
registration.register().await?;
return Ok(());
}

let (node_to_p2p_tx, node_to_p2p_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let (p2p_to_node_tx, p2p_to_node_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let (node_tx, node_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
Expand All @@ -27,22 +53,12 @@ async fn main() -> Result<(), Error> {
&config.taiko_driver_url,
config.block_proposed_receiver_timeout_sec,
));
let ethereum_l1 = Arc::new(
ethereum_l1::EthereumL1::new(
&config.mev_boost_url,
&config.avs_node_ecdsa_private_key,
&config.contract_addresses,
&config.l1_beacon_url,
config.l1_slot_duration_sec,
config.l1_slots_per_epoch,
config.preconf_registry_expiry_sec,
)
.await?,
);

let mev_boost = mev_boost::MevBoost::new(&config.mev_boost_url);
let block_proposed_event_checker =
BlockProposedEventReceiver::new(taiko.clone(), node_tx.clone());
BlockProposedEventReceiver::start(block_proposed_event_checker).await;
let ethereum_l1 = Arc::new(ethereum_l1);
let node = node::Node::new(
node_rx,
node_to_p2p_tx,
Expand Down
32 changes: 32 additions & 0 deletions Node/src/registration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::ethereum_l1::EthereumL1;
use anyhow::Error;

pub struct Registration {
ethereum_l1: EthereumL1,
}

impl Registration {
pub fn new(ethereum_l1: EthereumL1) -> Self {
Self { ethereum_l1 }
}

pub async fn register(&self) -> Result<(), Error> {
let registered_filter = self
.ethereum_l1
.execution_layer
.watch_for_registered_event()
.await?;

self.ethereum_l1
.execution_layer
.register_preconfer()
.await?;

self.ethereum_l1
.execution_layer
.wait_for_the_registered_event(registered_filter)
.await?;

Ok(())
}
}