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
456 changes: 444 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tokio = "1.46.0"
tokio-util = "0.7.16"
console-subscriber = "0.4"
pin-project = "1.1.10"
jsonrpsee = { version = "0.26.0", features = ["http-client"] }

ethereum_ssz = "0.9.0"
ethereum_ssz_derive = "0.9.0"
Expand Down
4 changes: 2 additions & 2 deletions finalizer/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,10 +1271,10 @@ async fn process_execution_requests<
}

fn verify_deposit_request<R: Storage + Metrics + Clock + Spawner + governor::clock::Clock + Rng>(
context: &ContextCell<R>,
#[allow(unused)] context: &ContextCell<R>,
deposit_request: &DepositRequest,
protocol_version_digest: Digest,
new_height: u64,
#[allow(unused)] new_height: u64,
validator_minimum_stake: u64,
) -> bool {
if deposit_request.amount != validator_minimum_stake {
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tokio-util.workspace = true
# stake and checkpoint bin deps
alloy = "1.0.23"
ethereum_ssz.workspace = true
reqwest.workspace = true
jsonrpsee.workspace = true

# testnet bin deps
alloy-node-bindings.workspace = true
Expand Down
22 changes: 11 additions & 11 deletions node/src/bin/stake_and_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use commonware_cryptography::Sha256;
use commonware_cryptography::{Hasher, PrivateKeyExt, Signer, bls12381, ed25519::PrivateKey};
use commonware_runtime::{Clock, Metrics as _, Runner as _, Spawner as _, tokio as cw_tokio};
use futures::{FutureExt, pin_mut};
use jsonrpsee::http_client::HttpClientBuilder;
use ssz::Decode;
use std::collections::VecDeque;
use std::time::Duration;
Expand All @@ -33,13 +34,13 @@ use std::{
};
use summit::args::{RunFlags, run_node_local};
use summit::engine::VALIDATOR_MINIMUM_STAKE;
use summit_rpc::SummitApiClient;
use summit_types::PROTOCOL_VERSION;
use summit_types::checkpoint::Checkpoint;
use summit_types::consensus_state::ConsensusState;
use summit_types::execution_request::DepositRequest;
use summit_types::execution_request::compute_deposit_data_root;
use summit_types::reth::Reth;
use summit_types::rpc::CheckpointRes;
use tokio::sync::mpsc;
use tracing::Level;

Expand Down Expand Up @@ -624,26 +625,25 @@ fn copy_dir_all(src: &str, dst: &str) -> std::io::Result<()> {
}

async fn get_latest_height(rpc_port: u16) -> Result<u64, Box<dyn std::error::Error>> {
let url = format!("http://localhost:{}/get_latest_height", rpc_port);
let response = reqwest::get(&url).await?.text().await?;
Ok(response.parse()?)
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;
let height = client.get_latest_height().await?;
Ok(height)
}

async fn get_latest_checkpoint(
rpc_port: u16,
) -> Result<Option<Checkpoint>, Box<dyn std::error::Error>> {
let url = format!("http://localhost:{}/get_latest_checkpoint", rpc_port);
let response = reqwest::get(&url).await;
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;

match response {
Ok(resp) if resp.status().is_success() => {
let checkpoint_resp: CheckpointRes = resp.json().await?;
// let bytes = from_hex_formatted(&hex_str).ok_or("Failed to decode hex")?;
match client.get_latest_checkpoint().await {
Ok(checkpoint_resp) => {
let checkpoint = Checkpoint::from_ssz_bytes(&checkpoint_resp.checkpoint)
.map_err(|e| format!("Failed to decode checkpoint: {:?}", e))?;
Ok(Some(checkpoint))
}
_ => Ok(None),
Err(_) => Ok(None),
}
}

Expand Down
22 changes: 11 additions & 11 deletions node/src/bin/stake_and_join_with_outdated_ckpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use commonware_cryptography::Sha256;
use commonware_cryptography::{Hasher, PrivateKeyExt, Signer, bls12381, ed25519::PrivateKey};
use commonware_runtime::{Clock, Metrics as _, Runner as _, Spawner as _, tokio as cw_tokio};
use futures::{FutureExt, pin_mut};
use jsonrpsee::http_client::HttpClientBuilder;
use ssz::Decode;
use std::collections::VecDeque;
use std::time::Duration;
Expand All @@ -33,13 +34,13 @@ use std::{
};
use summit::args::{RunFlags, run_node_local};
use summit::engine::VALIDATOR_MINIMUM_STAKE;
use summit_rpc::SummitApiClient;
use summit_types::PROTOCOL_VERSION;
use summit_types::checkpoint::Checkpoint;
use summit_types::consensus_state::ConsensusState;
use summit_types::execution_request::DepositRequest;
use summit_types::execution_request::compute_deposit_data_root;
use summit_types::reth::Reth;
use summit_types::rpc::CheckpointRes;
use tokio::sync::mpsc;
use tracing::Level;

Expand Down Expand Up @@ -649,26 +650,25 @@ fn copy_dir_all(src: &str, dst: &str) -> std::io::Result<()> {
}

async fn get_latest_epoch(rpc_port: u16) -> Result<u64, Box<dyn std::error::Error>> {
let url = format!("http://localhost:{}/get_latest_epoch", rpc_port);
let response = reqwest::get(&url).await?.text().await?;
Ok(response.parse()?)
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;
let epoch = client.get_latest_epoch().await?;
Ok(epoch)
}

async fn get_latest_checkpoint(
rpc_port: u16,
) -> Result<Option<Checkpoint>, Box<dyn std::error::Error>> {
let url = format!("http://localhost:{}/get_latest_checkpoint", rpc_port);
let response = reqwest::get(&url).await;
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;

match response {
Ok(resp) if resp.status().is_success() => {
let checkpoint_resp: CheckpointRes = resp.json().await?;
// let bytes = from_hex_formatted(&hex_str).ok_or("Failed to decode hex")?;
match client.get_latest_checkpoint().await {
Ok(checkpoint_resp) => {
let checkpoint = Checkpoint::from_ssz_bytes(&checkpoint_resp.checkpoint)
.map_err(|e| format!("Failed to decode checkpoint: {:?}", e))?;
Ok(Some(checkpoint))
}
_ => Ok(None),
Err(_) => Ok(None),
}
}

Expand Down
32 changes: 18 additions & 14 deletions node/src/bin/withdraw_and_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use commonware_codec::DecodeExt;
use commonware_runtime::{Clock, Metrics as _, Runner as _, Spawner as _, tokio as cw_tokio};
use commonware_utils::from_hex_formatted;
use futures::{FutureExt, pin_mut};
use jsonrpsee::core::ClientError;
use jsonrpsee::http_client::HttpClientBuilder;
use std::collections::VecDeque;
use std::time::Duration;
use std::{
Expand All @@ -31,6 +33,7 @@ use std::{
};
use summit::args::{RunFlags, run_node_local};
use summit::engine::{BLOCKS_PER_EPOCH, VALIDATOR_MINIMUM_STAKE, VALIDATOR_WITHDRAWAL_NUM_EPOCHS};
use summit_rpc::SummitApiClient;
use summit_types::PublicKey;
use summit_types::reth::Reth;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -296,9 +299,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check that the validator was removed from the consensus state
let rpc_port = get_node_flags(0).rpc_port;
let validator_balance = get_validator_balance(rpc_port, "f205c8c88d5d1753843dd0fc9810390efd00d6f752dd555c0ad4000bfcac2226".to_string()).await;
if let Err(msg) = validator_balance {
assert_eq!(msg.to_string(), "Validator not found");
println!("Validator that withdrew is not on the consensus state anymore");
if let Err(e) = validator_balance {
// Parse the JSON-RPC error
if let Some(ClientError::Call(err)) = e.downcast_ref::<ClientError>() {
assert_eq!(err.message(), "Validator not found");
println!("Success: validator that withdrew is not on the consensus state anymore");
} else {
panic!("Expected JSON-RPC Call error with 'Validator not found', got: {}", e);
}
} else {
panic!("Validator should not be on the consensus state anymore");
}
Expand Down Expand Up @@ -357,23 +365,19 @@ where
}

async fn get_latest_height(rpc_port: u16) -> Result<u64, Box<dyn std::error::Error>> {
let url = format!("http://localhost:{}/get_latest_height", rpc_port);
let response = reqwest::get(&url).await?.text().await?;
Ok(response.parse()?)
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;
let height = client.get_latest_height().await?;
Ok(height)
}

async fn get_validator_balance(
rpc_port: u16,
public_key: String,
) -> Result<u64, Box<dyn std::error::Error>> {
let url = format!(
"http://localhost:{}/get_validator_balance?public_key={}",
rpc_port, public_key
);
let response = reqwest::get(&url).await?.text().await?;
let Ok(balance) = response.parse() else {
return Err(response.into());
};
let url = format!("http://localhost:{}", rpc_port);
let client = HttpClientBuilder::default().build(&url)?;
let balance = client.get_validator_balance(public_key).await?;
Ok(balance)
}

Expand Down
15 changes: 14 additions & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ alloy-primitives.workspace = true
tokio = { workspace = true, features = ["net"] }
tokio-util.workspace = true
futures.workspace = true
axum = { version = "0.8.4"}
async-trait = "0.1"
jsonrpsee = { version = "0.26.0", features = ["server", "client", "macros"] }
jsonrpsee-core = "0.26.0"
jsonrpsee-types = "0.26.0"
commonware-consensus = { workspace = true }
commonware-cryptography = { workspace = true }
commonware-utils = { workspace = true }
Expand All @@ -26,3 +29,13 @@ dirs = "5.0.1"
serde = { workspace = true }
serde_json = { workspace = true }
tracing.workspace = true
tower = { workspace = true }
tower-http = { version = "0.6", features = ["cors"] }
http = { workspace = true }
hyper = "1.0"
bytes = { workspace = true }
http-body-util = { workspace = true }

[dev-dependencies]
tempfile = "3"
tokio = { workspace = true, features = ["net", "rt-multi-thread", "macros"] }
51 changes: 51 additions & 0 deletions rpc/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::types::{
CheckpointInfoRes, CheckpointRes, DepositTransactionResponse, PublicKeysResponse,
};
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;

#[rpc(server, client)]
pub trait SummitApi {
#[method(name = "health")]
async fn health(&self) -> RpcResult<String>;

#[method(name = "getPublicKeys")]
async fn get_public_keys(&self) -> RpcResult<PublicKeysResponse>;

#[method(name = "getCheckpoint")]
async fn get_checkpoint(&self, epoch: u64) -> RpcResult<CheckpointRes>;

#[method(name = "getLatestCheckpoint")]
async fn get_latest_checkpoint(&self) -> RpcResult<CheckpointRes>;

#[method(name = "getLatestCheckpointInfo")]
async fn get_latest_checkpoint_info(&self) -> RpcResult<CheckpointInfoRes>;

#[method(name = "getLatestHeight")]
async fn get_latest_height(&self) -> RpcResult<u64>;

#[method(name = "getLatestEpoch")]
async fn get_latest_epoch(&self) -> RpcResult<u64>;

#[method(name = "getValidatorBalance")]
async fn get_validator_balance(&self, public_key: String) -> RpcResult<u64>;

#[method(name = "getDepositSignature")]
async fn get_deposit_signature(
&self,
amount: u64,
address: String,
) -> RpcResult<DepositTransactionResponse>;
}

#[rpc(server, client)]
pub trait SummitGenesisApi {
#[method(name = "health")]
async fn health(&self) -> RpcResult<String>;

#[method(name = "getPublicKeys")]
async fn get_public_keys(&self) -> RpcResult<PublicKeysResponse>;

#[method(name = "sendGenesis")]
async fn send_genesis(&self, genesis_content: String) -> RpcResult<String>;
}
Loading