Skip to content

Commit

Permalink
Revert "NDEV-3112. Optimize getting of deactivated features (#566)" (#…
Browse files Browse the repository at this point in the history
…605)

This reverts commit d55ea02.
  • Loading branch information
s-medvedev authored Jan 21, 2025
1 parent d55ea02 commit 5d08594
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 270 deletions.
1 change: 0 additions & 1 deletion evm_loader/Cargo.lock

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

3 changes: 0 additions & 3 deletions evm_loader/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use neon_lib::commands;
pub use neon_lib::config;
pub use neon_lib::errors;
pub use neon_lib::types;
pub use neon_lib::types::deactivated_features::set_deactivated_features_rpc;
use tracing_appender::non_blocking::NonBlockingBuilder;

use actix_request_identifier::RequestIdentifier;
Expand Down Expand Up @@ -59,8 +58,6 @@ async fn main() -> NeonApiResult<()> {
let api_config = config::load_api_config_from_environment();
let state: NeonApiState = Data::new(State::new(api_config).await);

set_deactivated_features_rpc(state.rpc_client.clone()).await;

let listener_addr = options
.value_of("host")
.map(std::borrow::ToOwned::to_owned)
Expand Down
33 changes: 22 additions & 11 deletions evm_loader/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use neon_lib::{
get_storage_at, init_environment, trace,
},
rpc::CloneRpcClient,
types::{deactivated_features::set_deactivated_features_rpc, BalanceAddress, EmulateRequest},
types::{BalanceAddress, EmulateRequest},
Config,
};

Expand Down Expand Up @@ -42,15 +42,10 @@ type NeonCliResult = Result<serde_json::Value, NeonError>;
async fn run(options: &ArgMatches<'_>) -> NeonCliResult {
let config = &config::create(options)?;

let rpc = build_rpc(options, config).await?;

set_deactivated_features_rpc(RpcEnum::CloneRpcClient(CloneRpcClient::new_from_config(
config,
)))
.await;

match options.subcommand() {
("emulate", Some(_)) => {
let rpc = build_rpc(options, config).await?;

let request = read_tx_from_stdin()?;
emulate::execute(
&rpc,
Expand All @@ -63,12 +58,16 @@ async fn run(options: &ArgMatches<'_>) -> NeonCliResult {
.map(|(result, _)| json!(result))
}
("trace", Some(_)) => {
let rpc = build_rpc(options, config).await?;

let request = read_tx_from_stdin()?;
trace::trace_transaction(&rpc, &config.db_config, &config.evm_loader, request)
.await
.map(|trace| json!(trace))
}
("get-ether-account-data", Some(params)) => {
let rpc = build_rpc(options, config).await?;

let address = address_of(params, "ether").unwrap();
let chain_id = value_of(params, "chain_id").unwrap();

Expand All @@ -80,6 +79,8 @@ async fn run(options: &ArgMatches<'_>) -> NeonCliResult {
.map(|result| json!(result))
}
("get-contract-account-data", Some(params)) => {
let rpc = build_rpc(options, config).await?;

let account = address_of(params, "address").unwrap();
let accounts = std::slice::from_ref(&account);

Expand All @@ -88,13 +89,17 @@ async fn run(options: &ArgMatches<'_>) -> NeonCliResult {
.map(|result| json!(result))
}
("get-holder-account-data", Some(params)) => {
let rpc = build_rpc(options, config).await?;

let account = pubkey_of(params, "account").unwrap();

get_holder::execute(&rpc, &config.evm_loader, account)
.await
.map(|result| json!(result))
}
("neon-elf-params", Some(params)) => {
let rpc = build_rpc(options, config).await?;

let program_location = params.value_of("program_location");
get_neon_elf::execute(config, &rpc, program_location)
.await
Expand Down Expand Up @@ -130,16 +135,22 @@ async fn run(options: &ArgMatches<'_>) -> NeonCliResult {
.map(|result| json!(result))
}
("get-storage-at", Some(params)) => {
let rpc = build_rpc(options, config).await?;

let contract_id = address_of(params, "contract_id").expect("contract_it parse error");
let index = u256_of(params, "index").expect("index parse error");

get_storage_at::execute(&rpc, &config.evm_loader, contract_id, index)
.await
.map(|hash| json!(hex::encode(hash.0)))
}
("config", Some(_)) => get_config::execute(&rpc, config.evm_loader)
.await
.map(|result| json!(result)),
("config", Some(_)) => {
let rpc = build_rpc(options, config).await?;

get_config::execute(&rpc, config.evm_loader)
.await
.map(|result| json!(result))
}
_ => unreachable!(),
}
}
Expand Down
1 change: 0 additions & 1 deletion evm_loader/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ lazy_static = "1.5.0"
elsa = "1.10.0"
arrayref = "0.3.8"
futures = "0.3.30"
once_cell = "1.19.0"

[dev-dependencies]
hex-literal = "0.4.1"
Expand Down
130 changes: 0 additions & 130 deletions evm_loader/lib/src/deactivated_features_tests.rs

This file was deleted.

3 changes: 1 addition & 2 deletions evm_loader/lib/src/rpc/db_call_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{e, Rpc, SliceConfig};
use crate::types::deactivated_features::get_deactivated_features_at_slot;
use crate::types::{TracerDb, TracerDbTrait};
use crate::NeonError;
use crate::NeonError::RocksDb;
Expand Down Expand Up @@ -74,6 +73,6 @@ impl Rpc for CallDbClient {
}

async fn get_deactivated_solana_features(&self) -> ClientResult<Vec<Pubkey>> {
get_deactivated_features_at_slot(Some(self.slot)).await
Ok(vec![]) // TODO
}
}
52 changes: 48 additions & 4 deletions evm_loader/lib/src/rpc/validator_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{
config::APIOptions, types::deactivated_features::get_deactivated_features_at_slot, Config,
};
use crate::{config::APIOptions, Config};

use super::{Rpc, SliceConfig};
use async_trait::async_trait;
Expand Down Expand Up @@ -169,6 +167,52 @@ impl Rpc for CloneRpcClient {
}

async fn get_deactivated_solana_features(&self) -> ClientResult<Vec<Pubkey>> {
get_deactivated_features_at_slot(None).await
use std::time::{Duration, Instant};
use tokio::sync::Mutex;

struct Cache {
data: Vec<Pubkey>,
timestamp: Instant,
}

static CACHE: Mutex<Option<Cache>> = Mutex::const_new(None);
let mut cache = CACHE.lock().await;

if let Some(cache) = cache.as_ref() {
if cache.timestamp.elapsed() < Duration::from_secs(24 * 60 * 60) {
return Ok(cache.data.clone());
}
}

let feature_keys: Vec<Pubkey> = solana_sdk::feature_set::FEATURE_NAMES
.keys()
.copied()
.collect();

let features = Rpc::get_multiple_accounts(self, &feature_keys).await?;

let mut result = Vec::with_capacity(feature_keys.len());
for (pubkey, feature) in feature_keys.iter().zip(features) {
let is_activated = feature
.and_then(|a| solana_sdk::feature::from_account(&a))
.and_then(|f| f.activated_at)
.is_some();

if !is_activated {
result.push(*pubkey);
}
}

for feature in &result {
debug!("Deactivated feature: {}", feature);
}

cache.replace(Cache {
data: result.clone(),
timestamp: Instant::now(),
});
drop(cache);

Ok(result)
}
}
Loading

0 comments on commit 5d08594

Please sign in to comment.