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
61 changes: 9 additions & 52 deletions crates/core/src/rpc/admin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
collections::HashMap,
net::SocketAddr,
time::{Duration, SystemTime},
};
use std::{collections::HashMap, net::SocketAddr, time::Duration};

use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_derive::rpc;
Expand All @@ -13,7 +9,7 @@ use txtx_addon_network_svm_types::subgraph::PluginConfig;
use uuid::Uuid;

use super::{RunloopContext, not_implemented_err, not_implemented_err_async};
use crate::PluginManagerCommand;
use crate::{PluginManagerCommand, rpc::State};

#[rpc]
pub trait AdminRpc {
Expand Down Expand Up @@ -190,45 +186,6 @@ pub trait AdminRpc {
#[rpc(meta, name = "rpcAddress")]
fn rpc_addr(&self, meta: Self::Metadata) -> Result<Option<SocketAddr>>;

/// Sets a filter for log messages in the system.
///
/// This RPC method allows the user to configure the logging level or filters applied to the logs
/// generated by the system. It enables fine-grained control over which log messages are captured
/// and how they are displayed or stored.
///
/// ## Parameters
/// - `filter`: A string representing the desired log filter. This could be a log level (e.g., `info`, `debug`, `error`),
/// or a more complex filter expression depending on the system’s logging configuration.
///
/// ## Returns
/// - `()` — A unit result indicating the operation was successful.
///
/// ## Example Request (JSON-RPC)
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "id": 105,
/// "method": "setLogFilter",
/// "params": ["debug"]
/// }
/// ```
///
/// ## Example Response
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "result": null,
/// "id": 105
/// }
/// ```
///
/// # Notes
/// - The `filter` parameter should be consistent with the logging framework used by the system.
/// - Valid filter values might include common log levels such as `trace`, `debug`, `info`, `warn`, `error`, or other custom filters.
/// - This method allows dynamic control of the log output, so it should be used cautiously in production environments.
#[rpc(name = "setLogFilter")]
fn set_log_filter(&self, filter: String) -> Result<()>;

/// Returns the system start time.
///
/// This RPC method retrieves the timestamp of when the system was started, represented as
Expand Down Expand Up @@ -258,10 +215,10 @@ pub trait AdminRpc {
/// ```
///
/// # Notes
/// - The result is a `SystemTime` in UTC, reflecting the moment the system was initialized.
/// - The result is a `String` in UTC, reflecting the moment the system was initialized.
/// - This method is useful for monitoring system uptime and verifying system health.
#[rpc(meta, name = "startTime")]
fn start_time(&self, meta: Self::Metadata) -> Result<SystemTime>;
fn start_time(&self, meta: Self::Metadata) -> Result<String>;

// #[rpc(meta, name = "startProgress")]
// fn start_progress(&self, meta: Self::Metadata) -> Result<ValidatorStartProgress>;
Expand Down Expand Up @@ -902,12 +859,12 @@ impl AdminRpc for SurfpoolAdminRpc {
not_implemented_err("rpc_addr")
}

fn set_log_filter(&self, _filter: String) -> Result<()> {
not_implemented_err("set_log_filter")
}
fn start_time(&self, meta: Self::Metadata) -> Result<String> {
let svm_locker = meta.get_svm_locker()?;
let system_time = svm_locker.get_start_time();

fn start_time(&self, _meta: Self::Metadata) -> Result<SystemTime> {
not_implemented_err("start_time")
let datetime_utc: chrono::DateTime<chrono::Utc> = system_time.into();
Ok(datetime_utc.to_rfc3339())
}

fn add_authorized_voter(&self, _meta: Self::Metadata, _keypair_file: String) -> Result<()> {
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/surfnet/locker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::{BTreeMap, HashMap, HashSet},
sync::Arc,
time::SystemTime,
};

use bincode::serialized_size;
Expand Down Expand Up @@ -2864,6 +2865,10 @@ impl SurfnetSvmLocker {
) -> BTreeMap<String, AccountSnapshot> {
self.with_svm_reader(|svm_reader| svm_reader.export_snapshot(config))
}

pub fn get_start_time(&self) -> SystemTime {
self.with_svm_reader(|svm_reader| svm_reader.start_time)
}
}

/// Helpers for writing program accounts
Expand Down
4 changes: 3 additions & 1 deletion crates/core/src/surfnet/svm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
cmp::max,
collections::{BTreeMap, BinaryHeap, HashMap, HashSet, VecDeque},
str::FromStr,
str::FromStr, time::SystemTime,
};

use agave_feature_set::{FeatureSet, enable_extend_program_checked};
Expand Down Expand Up @@ -224,6 +224,7 @@ pub struct SurfnetSvm {
pub logs_subscriptions: Vec<LogsSubscriptionData>,
pub updated_at: u64,
pub slot_time: u64,
pub start_time: SystemTime,
pub accounts_by_owner: HashMap<Pubkey, Vec<Pubkey>>,
pub account_associated_data: HashMap<Pubkey, AccountAdditionalDataV3>,
pub token_accounts: HashMap<Pubkey, TokenAccount>,
Expand Down Expand Up @@ -320,6 +321,7 @@ impl SurfnetSvm {
logs_subscriptions: Vec::new(),
updated_at: Utc::now().timestamp_millis() as u64,
slot_time: DEFAULT_SLOT_TIME_MS,
start_time: SystemTime::now(),
accounts_by_owner,
account_associated_data: HashMap::new(),
token_accounts: HashMap::new(),
Expand Down
12 changes: 0 additions & 12 deletions crates/types/src/rpc_endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -1323,18 +1323,6 @@
"params": [],
"returns": "A list of plugin names."
},
{
"method": "setLogFilter",
"description": "Sets the log filter for the node.",
"params": [
{
"name": "filter",
"type": "string",
"description": "The log filter to set."
}
],
"returns": null
},
{
"method": "addAuthorizedVoter",
"description": "Adds an authorized voter.",
Expand Down