Skip to content

Commit

Permalink
refactor: remove get_preconfirmations method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Bostoen authored and merklefruit committed May 29, 2024
1 parent e39dedf commit fdfadca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 50 deletions.
33 changes: 1 addition & 32 deletions bolt-sidecar/src/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use secp256k1::{
use thiserror::Error;
use tracing::info;

use super::types::{GetPreconfirmationsAtSlotParams, PreconfirmationRequestParams, Slot};
use super::types::{PreconfirmationRequestParams, Slot};

/// Default size of the preconfirmation cache (implemented as a LRU).
const DEFAULT_PRECONFIRMATION_CACHE_SIZE: usize = 1000;
Expand Down Expand Up @@ -46,11 +46,6 @@ pub trait PreconfirmationRpc {
&self,
params: serde_json::Value,
) -> Result<serde_json::Value, PreconfirmationError>;

async fn get_preconfirmation_requests(
&self,
params: serde_json::Value,
) -> Result<serde_json::Value, PreconfirmationError>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -109,30 +104,4 @@ impl PreconfirmationRpc for JsonRpcApi {
"signature": signature,
}))
}

async fn get_preconfirmation_requests(
&self,
params: serde_json::Value,
) -> Result<serde_json::Value, PreconfirmationError> {
let Some(params) = params.as_array().and_then(|a| a.first()).cloned() else {
return Err(PreconfirmationError::Custom(
"request params must be an array with a single object".to_string(),
));
};

let params = serde_json::from_value::<GetPreconfirmationsAtSlotParams>(params)?;
info!(?params, "received get preconfirmation requests");

let mut slot_requests = Vec::new();

{
if let Some(preconfs) = self.cache.write().get(&params.slot) {
for preconf in preconfs {
slot_requests.push(serde_json::to_value(preconf)?);
}
}
} // Drop the lock

Ok(serde_json::json!(slot_requests))
}
}
1 change: 0 additions & 1 deletion bolt-sidecar/src/json_rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async fn handle_rpc_request(

let res = match req.method.as_str() {
"eth_requestPreconfirmation" => rpc_api.request_preconfirmation(req.params).await?,
"eth_getPreconfirmations" => rpc_api.get_preconfirmation_requests(req.params).await?,
_ => {
error!(method = ?req.method, "RPC method not found");
return Err(warp::reject::custom(JsonRpcError {
Expand Down
6 changes: 0 additions & 6 deletions bolt-sidecar/src/json_rpc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ impl PreconfirmationRequestParams {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct GetPreconfirmationsAtSlotParams {
pub slot: Slot,
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct JsonRpcError {
pub code: i64,
Expand Down
13 changes: 2 additions & 11 deletions bolt-sidecar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ use eyre::Context;
use tracing::{info, warn};

mod json_rpc;
mod opts;
use json_rpc::start_server;

#[derive(Parser)]
struct Opts {
/// Port to listen on for incoming JSON-RPC requests.
#[clap(short = 'p', long, default_value = "8000")]
port: u16,
/// Private key to use for signing preconfirmation requests.
#[clap(short = 'k', long)]
private_key: Option<String>,
}

#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt::init();

info!("Starting sidecar");

let opts = Opts::parse();
let opts = opts::Opts::parse();

let pk = if let Some(pk) = opts.private_key {
Some(secp256k1::SecretKey::from_str(&pk).context("Invalid private key")?)
Expand Down
11 changes: 11 additions & 0 deletions bolt-sidecar/src/opts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use clap::Parser;

#[derive(Parser)]
pub(super) struct Opts {
/// Port to listen on for incoming JSON-RPC requests.
#[clap(short = 'p', long, default_value = "8000")]
pub(super) port: u16,
/// Private key to use for signing preconfirmation requests.
#[clap(short = 'k', long)]
pub(super) private_key: Option<String>,
}

0 comments on commit fdfadca

Please sign in to comment.