diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index be9045650..ed3814394 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -14,7 +14,6 @@ env: DHUBU: ${{secrets.DHUBU}} DHUBP: ${{secrets.DHUBP}} BUILD_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" - INDEXER_DB_PASSWORD: ${{secrets.INDEXER_DB_PASSWORD}} concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/evm_loader/Cargo.lock b/evm_loader/Cargo.lock index 1e8cd968a..45f237c9e 100644 --- a/evm_loader/Cargo.lock +++ b/evm_loader/Cargo.lock @@ -113,12 +113,6 @@ version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" -[[package]] -name = "array-init" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" - [[package]] name = "arrayref" version = "0.3.7" @@ -1241,12 +1235,6 @@ dependencies = [ "toml", ] -[[package]] -name = "fallible-iterator" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" - [[package]] name = "fastrand" version = "1.9.0" @@ -1680,7 +1668,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2", "tokio", "tower-service", "tracing", @@ -2028,15 +2016,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" -[[package]] -name = "md-5" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" -dependencies = [ - "digest 0.10.6", -] - [[package]] name = "memchr" version = "2.5.0" @@ -2255,7 +2234,6 @@ dependencies = [ "hex", "lazy_static", "log", - "postgres", "rand 0.8.5", "scroll", "serde", @@ -2270,7 +2248,6 @@ dependencies = [ "spl-token", "thiserror", "tokio", - "tokio-postgres", "tracing", ] @@ -2602,24 +2579,6 @@ dependencies = [ "num", ] -[[package]] -name = "phf" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_shared" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project" version = "1.1.0" @@ -2687,52 +2646,6 @@ dependencies = [ "universal-hash", ] -[[package]] -name = "postgres" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bed5017bc2ff49649c0075d0d7a9d676933c1292480c1d137776fb205b5cd18" -dependencies = [ - "bytes", - "fallible-iterator", - "futures-util", - "log", - "tokio", - "tokio-postgres", -] - -[[package]] -name = "postgres-protocol" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b7fa9f396f51dffd61546fd8573ee20592287996568e6175ceb0f8699ad75d" -dependencies = [ - "base64 0.21.0", - "byteorder", - "bytes", - "fallible-iterator", - "hmac 0.12.1", - "md-5", - "memchr", - "rand 0.8.5", - "sha2 0.10.6", - "stringprep", -] - -[[package]] -name = "postgres-types" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f028f05971fe20f512bcc679e2c10227e57809a3af86a7606304435bc8896cd6" -dependencies = [ - "array-init", - "bytes", - "chrono", - "fallible-iterator", - "postgres-protocol", - "uuid", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2839,7 +2752,7 @@ dependencies = [ "futures-util", "libc", "quinn-proto", - "socket2 0.4.9", + "socket2", "tokio", "tracing", ] @@ -3578,12 +3491,6 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - [[package]] name = "sized-chunks" version = "0.6.5" @@ -3619,16 +3526,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "socket2" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d283f86695ae989d1e18440a943880967156325ba025f05049946bff47bcc2b" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "solana-account-decoder" version = "1.14.20" @@ -3987,7 +3884,7 @@ dependencies = [ "rand 0.7.3", "serde", "serde_derive", - "socket2 0.4.9", + "socket2", "solana-logger", "solana-sdk", "solana-version", @@ -4416,16 +4313,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stringprep" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "strsim" version = "0.8.0" @@ -4654,7 +4541,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.4.9", + "socket2", "tokio-macros", "windows-sys 0.45.0", ] @@ -4680,30 +4567,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-postgres" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e89f6234aa8fd43779746012fcf53603cdb91fdd8399aa0de868c2d56b6dde1" -dependencies = [ - "async-trait", - "byteorder", - "bytes", - "fallible-iterator", - "futures-channel", - "futures-util", - "log", - "parking_lot", - "percent-encoding", - "phf", - "pin-project-lite", - "postgres-protocol", - "postgres-types", - "socket2 0.5.2", - "tokio", - "tokio-util", -] - [[package]] name = "tokio-rustls" version = "0.23.4" @@ -5055,12 +4918,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" - [[package]] name = "valuable" version = "0.1.0" diff --git a/evm_loader/api/src/api_context.rs b/evm_loader/api/src/api_context.rs index 4cb3b81fc..409638aff 100644 --- a/evm_loader/api/src/api_context.rs +++ b/evm_loader/api/src/api_context.rs @@ -1,7 +1,6 @@ use crate::NeonApiState; -use hex::FromHex; -use neon_lib::rpc::{CallDbClient, TrxDbClient}; -use neon_lib::{context, rpc, NeonError}; +use neon_lib::rpc::CallDbClient; +use neon_lib::{rpc, NeonError}; use std::sync::Arc; pub async fn build_rpc_client( @@ -23,13 +22,3 @@ pub async fn build_call_db_client( CallDbClient::new(state.tracer_db.clone(), slot).await?, )) } - -pub async fn build_hash_rpc_client( - state: &NeonApiState, - hash: &str, -) -> Result, NeonError> { - let hash = <[u8; 32]>::from_hex(context::truncate_0x(hash))?; - Ok(Arc::new( - TrxDbClient::new(state.tracer_db.clone(), state.indexer_db.clone(), hash).await, - )) -} diff --git a/evm_loader/api/src/api_server/handlers/emulate.rs b/evm_loader/api/src/api_server/handlers/emulate.rs index f47b6c9dd..6403c940f 100644 --- a/evm_loader/api/src/api_server/handlers/emulate.rs +++ b/evm_loader/api/src/api_server/handlers/emulate.rs @@ -3,7 +3,7 @@ use std::convert::Into; use crate::api_server::handlers::process_error; use crate::{ - api_context, commands::emulate as EmulateCommand, context, + api_context, commands::emulate as EmulateCommand, context::Context, types::request_models::EmulateRequestModel, NeonApiState, }; @@ -21,7 +21,7 @@ pub async fn emulate( Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), }; - let context = context::create(rpc_client, state.config.clone()); + let context = Context::new(rpc_client, state.config.clone()); let (token, chain, steps, accounts, solana_accounts) = parse_emulation_params(&state.config, &context, &emulate_request.emulation_params).await; diff --git a/evm_loader/api/src/api_server/handlers/emulate_hash.rs b/evm_loader/api/src/api_server/handlers/emulate_hash.rs deleted file mode 100644 index 64a60b173..000000000 --- a/evm_loader/api/src/api_server/handlers/emulate_hash.rs +++ /dev/null @@ -1,58 +0,0 @@ -use axum::{http::StatusCode, Json}; -use std::convert::Into; - -use crate::{ - api_context, commands::emulate as EmulateCommand, context, - types::request_models::EmulateHashRequestModel, NeonApiState, -}; - -use super::{parse_emulation_params, process_error, process_result}; - -#[tracing::instrument(skip(state))] -pub async fn emulate_hash( - axum::extract::State(state): axum::extract::State, - Json(emulate_hash_request): Json, -) -> (StatusCode, Json) { - let rpc_client = - match api_context::build_hash_rpc_client(&state, &emulate_hash_request.hash).await { - Ok(rpc_client) => rpc_client, - Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), - }; - - let tx = match rpc_client.get_transaction_data().await { - Ok(tx) => tx, - Err(e) => { - return process_error( - StatusCode::BAD_REQUEST, - &crate::errors::NeonError::SolanaClientError(e), - ) - } - }; - - let context = context::create(rpc_client, state.config.clone()); - - let (token, chain, steps, accounts, solana_accounts) = parse_emulation_params( - &state.config, - &context, - &emulate_hash_request.emulation_params, - ) - .await; - - process_result( - &EmulateCommand::execute( - context.rpc_client.as_ref(), - state.config.evm_loader, - tx, - token, - chain, - steps, - state.config.commitment, - &accounts, - &solana_accounts, - &None, - None, - ) - .await - .map_err(Into::into), - ) -} diff --git a/evm_loader/api/src/api_server/handlers/get_ether_account_data.rs b/evm_loader/api/src/api_server/handlers/get_ether_account_data.rs index a1517dc70..b16854bc7 100644 --- a/evm_loader/api/src/api_server/handlers/get_ether_account_data.rs +++ b/evm_loader/api/src/api_server/handlers/get_ether_account_data.rs @@ -1,6 +1,6 @@ use crate::api_server::handlers::process_error; use crate::commands::get_ether_account_data as GetEtherAccountDataCommand; -use crate::{api_context, context, types::request_models::GetEtherRequest, NeonApiState}; +use crate::{api_context, context::Context, types::request_models::GetEtherRequest, NeonApiState}; use axum::{ extract::{Query, State}, http::StatusCode, @@ -19,8 +19,7 @@ pub async fn get_ether_account_data( Ok(rpc_client) => rpc_client, Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), }; - - let context = context::create(rpc_client, state.config.clone()); + let context = Context::new(rpc_client, state.config.clone()); process_result( &GetEtherAccountDataCommand::execute( diff --git a/evm_loader/api/src/api_server/handlers/get_storage_at.rs b/evm_loader/api/src/api_server/handlers/get_storage_at.rs index c9a5d7775..f32ebd5d0 100644 --- a/evm_loader/api/src/api_server/handlers/get_storage_at.rs +++ b/evm_loader/api/src/api_server/handlers/get_storage_at.rs @@ -1,5 +1,7 @@ use crate::api_server::handlers::process_error; -use crate::{api_context, context, types::request_models::GetStorageAtRequest, NeonApiState}; +use crate::{ + api_context, context::Context, types::request_models::GetStorageAtRequest, NeonApiState, +}; use axum::{ extract::{Query, State}, http::StatusCode, @@ -21,7 +23,7 @@ pub async fn get_storage_at( Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), }; - let context = context::create(rpc_client, state.config.clone()); + let context = Context::new(rpc_client, state.config.clone()); process_result( &GetStorageAtCommand::execute( diff --git a/evm_loader/api/src/api_server/handlers/mod.rs b/evm_loader/api/src/api_server/handlers/mod.rs index 9887388d7..3eb743233 100644 --- a/evm_loader/api/src/api_server/handlers/mod.rs +++ b/evm_loader/api/src/api_server/handlers/mod.rs @@ -17,12 +17,9 @@ use std::str::FromStr; use tracing::error; pub mod emulate; -pub mod emulate_hash; pub mod get_ether_account_data; pub mod get_storage_at; pub mod trace; -pub mod trace_hash; -pub mod trace_next_block; #[derive(Debug)] pub struct NeonApiError(pub NeonError); diff --git a/evm_loader/api/src/api_server/handlers/trace.rs b/evm_loader/api/src/api_server/handlers/trace.rs index ba5803962..43cbf8403 100644 --- a/evm_loader/api/src/api_server/handlers/trace.rs +++ b/evm_loader/api/src/api_server/handlers/trace.rs @@ -3,7 +3,9 @@ use std::convert::Into; use crate::api_server::handlers::process_error; use crate::commands::trace::trace_transaction; -use crate::{api_context, context, types::request_models::TraceRequestModel, NeonApiState}; +use crate::{ + api_context, context::Context, types::request_models::TraceRequestModel, NeonApiState, +}; use super::{parse_emulation_params, process_result}; @@ -20,7 +22,7 @@ pub async fn trace( Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), }; - let context = context::create(rpc_client, state.config.clone()); + let context = Context::new(rpc_client, state.config.clone()); let (token, chain, steps, accounts, solana_accounts) = parse_emulation_params( &state.config, diff --git a/evm_loader/api/src/api_server/handlers/trace_hash.rs b/evm_loader/api/src/api_server/handlers/trace_hash.rs deleted file mode 100644 index ccf89b1c6..000000000 --- a/evm_loader/api/src/api_server/handlers/trace_hash.rs +++ /dev/null @@ -1,59 +0,0 @@ -use std::convert::Into; - -use crate::{api_context, context, types::request_models::TraceHashRequestModel, NeonApiState}; -use axum::{http::StatusCode, Json}; -use neon_lib::commands::trace::trace_transaction; - -use super::{parse_emulation_params, process_error, process_result}; - -#[tracing::instrument(skip(state))] -pub async fn trace_hash( - axum::extract::State(state): axum::extract::State, - Json(trace_hash_request): Json, -) -> (StatusCode, Json) { - let rpc_client = match api_context::build_hash_rpc_client( - &state, - &trace_hash_request.emulate_hash_request.hash, - ) - .await - { - Ok(rpc_client) => rpc_client, - Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), - }; - - let tx = match rpc_client.get_transaction_data().await { - Ok(tx) => tx, - Err(e) => { - return process_error( - StatusCode::BAD_REQUEST, - &crate::errors::NeonError::SolanaClientError(e), - ) - } - }; - - let context = context::create(rpc_client, state.config.clone()); - - let (token, chain, steps, accounts, solana_accounts) = parse_emulation_params( - &state.config, - &context, - &trace_hash_request.emulate_hash_request.emulation_params, - ) - .await; - - process_result( - &trace_transaction( - context.rpc_client.as_ref(), - state.config.evm_loader, - tx, - token, - chain, - steps, - state.config.commitment, - &accounts, - &solana_accounts, - trace_hash_request.trace_config.unwrap_or_default().into(), - ) - .await - .map_err(Into::into), - ) -} diff --git a/evm_loader/api/src/api_server/handlers/trace_next_block.rs b/evm_loader/api/src/api_server/handlers/trace_next_block.rs deleted file mode 100644 index 1a82e7e34..000000000 --- a/evm_loader/api/src/api_server/handlers/trace_next_block.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::{ - api_context, api_server::handlers::process_error, commands::trace::trace_block, context, - errors, types::request_models::TraceNextBlockRequestModel, NeonApiState, -}; -use axum::http::StatusCode; -use axum::Json; -use std::sync::Arc; - -use super::{parse_emulation_params, process_result}; - -#[tracing::instrument(skip(state))] -pub async fn trace_next_block( - axum::extract::State(state): axum::extract::State, - Json(trace_next_block_request): Json, -) -> (StatusCode, Json) { - let rpc_client = - match api_context::build_call_db_client(&state, trace_next_block_request.slot).await { - Ok(rpc_client) => rpc_client, - Err(e) => return process_error(StatusCode::BAD_REQUEST, &e), - }; - - let context = context::create(rpc_client, Arc::clone(&state.config)); - - let (token, chain, steps, accounts, solana_accounts) = parse_emulation_params( - &state.config, - &context, - &trace_next_block_request.emulation_params, - ) - .await; - - // TODO: Query next block (which parent = slot) instead of getting slot + 1: - let transactions = match state - .indexer_db - .get_block_transactions(trace_next_block_request.slot + 1) - .await - { - Ok(transactions) => transactions, - Err(e) => { - return process_error( - StatusCode::INTERNAL_SERVER_ERROR, - &errors::NeonError::PostgresError(e), - ) - } - }; - - process_result( - &trace_block( - context.rpc_client.as_ref(), - state.config.evm_loader, - transactions, - token, - chain, - steps, - state.config.commitment, - &accounts, - &solana_accounts, - &trace_next_block_request.trace_config.unwrap_or_default(), - ) - .await - .map_err(Into::into), - ) -} diff --git a/evm_loader/api/src/api_server/routes.rs b/evm_loader/api/src/api_server/routes.rs index e82fdeec5..85a0d9a5b 100644 --- a/evm_loader/api/src/api_server/routes.rs +++ b/evm_loader/api/src/api_server/routes.rs @@ -7,9 +7,8 @@ use tower::ServiceBuilder; // use evm_loader::types::Address; use crate::{ api_server::handlers::{ - emulate::emulate, emulate_hash::emulate_hash, - get_ether_account_data::get_ether_account_data, get_storage_at::get_storage_at, - trace::trace, trace_hash::trace_hash, trace_next_block::trace_next_block, + emulate::emulate, get_ether_account_data::get_ether_account_data, + get_storage_at::get_storage_at, trace::trace, }, NeonApiState, }; @@ -17,14 +16,9 @@ use crate::{ pub fn register() -> Router { ServiceBuilder::new().service::>( Router::new() - .route("/emulate", post(emulate)) - .route("/emulate-hash", post(emulate_hash)) - .route("/emulate_hash", post(emulate_hash)) // Obsolete + .route("/emulate", post(emulate)) // Obsolete .route("/get-storage-at", get(get_storage_at)) .route("/get-ether-account-data", get(get_ether_account_data)) - .route("/trace", post(trace)) - .route("/trace-hash", post(trace_hash)) - .route("/trace_hash", post(trace_hash)) // Obsolete - .route("/trace-next-block", post(trace_next_block)), + .route("/trace", post(trace)), ) } diff --git a/evm_loader/api/src/api_server/state.rs b/evm_loader/api/src/api_server/state.rs index f4a96ef67..1b49fe103 100644 --- a/evm_loader/api/src/api_server/state.rs +++ b/evm_loader/api/src/api_server/state.rs @@ -1,22 +1,20 @@ use crate::Config; -use neon_lib::types::{IndexerDb, TracerDb}; +use neon_lib::types::TracerDb; use solana_client::nonblocking::rpc_client::RpcClient; use std::sync::Arc; #[derive(Clone)] pub struct State { pub tracer_db: TracerDb, - pub indexer_db: IndexerDb, pub rpc_client: Arc, pub config: Arc, } impl State { - pub async fn new(config: Config) -> Self { + pub fn new(config: Config) -> Self { let db_config = config.db_config.as_ref().expect("db-config not found"); Self { tracer_db: TracerDb::new(db_config), - indexer_db: IndexerDb::new(db_config).await, rpc_client: Arc::new(RpcClient::new_with_commitment( config.json_rpc_url.clone(), config.commitment, diff --git a/evm_loader/api/src/main.rs b/evm_loader/api/src/main.rs index 4b84e81bd..206c952de 100644 --- a/evm_loader/api/src/main.rs +++ b/evm_loader/api/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> NeonApiResult<()> { let config = config::create_from_api_config(&api_config)?; - let state: NeonApiState = Arc::new(api_server::state::State::new(config).await); + let state: NeonApiState = Arc::new(api_server::state::State::new(config)); let app = Router::new() .nest("/api", api_server::routes::register()) diff --git a/evm_loader/cli/src/context.rs b/evm_loader/cli/src/context.rs deleted file mode 100644 index ed48d4c4a..000000000 --- a/evm_loader/cli/src/context.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::sync::Arc; - -use clap::ArgMatches; -use hex::FromHex; -use neon_lib::context::truncate_0x; -pub use neon_lib::context::*; -use neon_lib::rpc; -use neon_lib::rpc::CallDbClient; -use neon_lib::rpc::TrxDbClient; -use neon_lib::types::{IndexerDb, TracerDb}; -use neon_lib::Config; -use neon_lib::NeonError; -use solana_client::nonblocking::rpc_client::RpcClient; - -/// # Errors -pub async fn create_from_config_and_options<'a>( - options: &'a ArgMatches<'a>, - config: Arc, - slot: &'a Option, -) -> Result { - let (cmd, params) = options.subcommand(); - - let rpc_client: Arc = match (cmd, params) { - ("emulate-hash" | "trace-hash" | "emulate_hash" | "trace_hash", Some(params)) => { - let hash = params.value_of("hash").expect("hash not found"); - let hash = <[u8; 32]>::from_hex(truncate_0x(hash)).expect("hash cast error"); - - let db_config = config.db_config.as_ref().expect("db-config not found"); - Arc::new( - TrxDbClient::new( - TracerDb::new(db_config), - IndexerDb::new(db_config).await, - hash, - ) - .await, - ) - } - _ => { - if let Some(slot) = slot { - Arc::new( - CallDbClient::new( - TracerDb::new(config.db_config.as_ref().expect("db-config not found")), - *slot, - ) - .await?, - ) - } else { - Arc::new(RpcClient::new_with_commitment( - config.json_rpc_url.clone(), - config.commitment, - )) - } - } - }; - - Ok(neon_lib::context::create(rpc_client, config.clone())) -} diff --git a/evm_loader/cli/src/main.rs b/evm_loader/cli/src/main.rs index 25a57962c..b4cbd76ed 100644 --- a/evm_loader/cli/src/main.rs +++ b/evm_loader/cli/src/main.rs @@ -2,7 +2,6 @@ #![deny(clippy::all, clippy::pedantic)] mod config; -mod context; mod logs; mod program_options; @@ -12,20 +11,19 @@ use neon_lib::{ get_ether_account_data, get_neon_elf, get_neon_elf::CachedElfParams, get_storage_at, init_environment, trace, }, - errors, rpc, + errors, types::{self, AccessListItem}, + Context, }; use clap::ArgMatches; pub use config::Config; -pub use context::Context; use std::io::Read; use ethnum::U256; -use evm_loader::evm::tracing::{TraceCallConfig, TraceConfig}; +use evm_loader::evm::tracing::TraceCallConfig; use serde_json::json; use solana_clap_utils::input_parsers::{pubkey_of, value_of, values_of}; -use solana_client::client_error::{ClientError, ClientErrorKind}; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::pubkey::Pubkey; use std::str::FromStr; @@ -34,8 +32,7 @@ use tokio::time::Instant; use crate::{ errors::NeonError, - rpc::Rpc, - types::{IndexerDb, TraceNextBlockParams, TransactionHashParams, TransactionParams, TxParams}, + types::{TransactionParams, TxParams}, }; use evm_loader::types::Address; @@ -47,10 +44,9 @@ async fn run<'a>(options: &'a ArgMatches<'a>) -> NeonCliResult { .map(|slot_str| slot_str.parse().expect("slot parse error")); let (cmd, params) = options.subcommand(); let config = Arc::new(config::create(options)?); - let context: Context = - context::create_from_config_and_options(options, config.clone(), &slot).await?; + let context = Context::new_from_config(config.clone(), slot).await?; - execute(cmd, params, &config, &context, slot).await + execute(cmd, params, &config, &context).await } fn print_result(result: &NeonCliResult) { @@ -103,7 +99,6 @@ async fn execute<'a>( params: Option<&'a ArgMatches<'a>>, config: &'a Config, context: &'a Context, - slot: Option, ) -> NeonCliResult { match (cmd, params) { ("emulate", Some(params)) => { @@ -126,26 +121,6 @@ async fn execute<'a>( .await .map(|result| json!(result)) } - ("emulate-hash", Some(params)) => { - let tx = context.rpc_client.get_transaction_data().await?; - let (token, chain, steps, accounts, solana_accounts) = - parse_tx_params(config, context, params).await; - emulate::execute( - context.rpc_client.as_ref(), - config.evm_loader, - tx, - token, - chain, - steps, - config.commitment, - &accounts, - &solana_accounts, - &None, - None, - ) - .await - .map(|result| json!(result)) - } ("trace", Some(params)) => { let (tx, trace_call_config) = parse_tx(params); let (token, chain, steps, accounts, solana_accounts) = @@ -165,61 +140,6 @@ async fn execute<'a>( .await .map(|trace| json!(trace)) } - ("trace-hash", Some(params)) => { - let (tx, trace_config) = parse_tx_hash(context.rpc_client.as_ref()).await; - let (token, chain, steps, accounts, solana_accounts) = - parse_tx_params(config, context, params).await; - trace::trace_transaction( - context.rpc_client.as_ref(), - config.evm_loader, - tx, - token, - chain, - steps, - config.commitment, - &accounts, - &solana_accounts, - trace_config.into(), - ) - .await - .map(|trace| json!(trace)) - } - ("trace-next-block", Some(params)) => { - let slot = slot.expect("SLOT argument is not provided"); - let trace_block_params: Option = read_from_stdin() - .unwrap_or_else(|err| { - panic!("Unable to parse `TraceBlockBySlotParams` from STDIN, error: {err:?}") - }); - let trace_config = trace_block_params - .map(|params| params.trace_config.unwrap_or_default()) - .unwrap_or_default(); - let (token, chain, steps, accounts, solana_accounts) = - parse_tx_params(config, context, params).await; - let indexer_db = - IndexerDb::new(config.db_config.as_ref().expect("db-config is required")).await; - let transactions = indexer_db - .get_block_transactions(slot + 1) - .await - .map_err(|e| { - ClientError::from(ClientErrorKind::Custom(format!( - "get_block_transactions error: {e}" - ))) - })?; - trace::trace_block( - context.rpc_client.as_ref(), - config.evm_loader, - transactions, - token, - chain, - steps, - config.commitment, - &accounts, - &solana_accounts, - &trace_config, - ) - .await - .map(|traces| json!(traces)) - } ("create-ether-account", Some(params)) => { let ether = address_of(params, "ether").expect("ether parse error"); let rpc_client = context @@ -340,20 +260,6 @@ fn parse_tx(params: &ArgMatches) -> (TxParams, TraceCallConfig) { (tx_params, trace_config) } -async fn parse_tx_hash(rpc_client: &dyn Rpc) -> (TxParams, TraceConfig) { - let tx = rpc_client.get_transaction_data().await.unwrap(); - let transaction_params: Option = - read_from_stdin().unwrap_or_else(|err| { - panic!("Unable to parse `TransactionHashParams` from STDIN, error: {err:?}") - }); - - let trace_config = transaction_params - .map(|params| params.trace_config.unwrap_or_default()) - .unwrap_or_default(); - - (tx, trace_config) -} - pub async fn parse_tx_params<'a>( config: &Config, context: &Context, diff --git a/evm_loader/cli/src/program_options.rs b/evm_loader/cli/src/program_options.rs index f8bea1704..ce0e2b39f 100644 --- a/evm_loader/cli/src/program_options.rs +++ b/evm_loader/cli/src/program_options.rs @@ -1,8 +1,6 @@ use clap::{crate_description, crate_name, App, AppSettings, Arg, ArgMatches, SubCommand}; use ethnum::U256; use evm_loader::types::Address; -use hex::FromHex; -use neon_lib::context::truncate_0x; use solana_clap_utils::input_validators::{is_url_or_moniker, is_valid_pubkey}; use std::fmt::Display; @@ -44,16 +42,6 @@ where .map_err(|e| e.to_string()) } -fn is_valid_h256(string: T) -> Result<(), String> -where - T: AsRef, -{ - let str = truncate_0x(string.as_ref()); - <[u8; 32]>::from_hex(str) - .map(|_| ()) - .map_err(|e| e.to_string()) -} - fn is_amount(amount: U) -> Result<(), String> where T: std::str::FromStr, @@ -181,24 +169,6 @@ fn trx_params<'a, 'b>(cmd: &'static str, desc: &'static str) -> App<'a, 'b> { ) } -fn trx_hash<'a, 'b>(cmd: &'static str, alias: &'static str, desc: &'static str) -> App<'a, 'b> { - SubCommand::with_name(cmd) - .alias(alias) - .about(desc) - .arg( - Arg::with_name("hash") - .index(1) - .value_name("hash") - .takes_value(true) - .required(true) - .validator(is_valid_h256) - .help("Neon transaction hash"), - ) - .arg(token_mint_arg()) - .arg(chain_id_arg()) - .arg(max_steps_arg()) -} - #[allow(clippy::too_many_lines)] pub fn parse<'a>() -> ArgMatches<'a> { App::new(crate_name!()) @@ -226,7 +196,7 @@ pub fn parse<'a>() -> ArgMatches<'a> { .long("db_config") .takes_value(true) .global(true) - .help("Configuration file to use Postgress DB") + .help("Configuration file to use Tracer DB") ) .arg( Arg::with_name("slot") @@ -321,29 +291,6 @@ pub fn parse<'a>() -> ArgMatches<'a> { "Emulation transaction to collecting traces. Additional `TransactionParams` can be provided via STDIN as a JSON object.", ) ) - .subcommand( - trx_hash( - "emulate-hash", - "emulate_hash", - "Emulation transaction by hash. Additional `TransactionHashParams` can be provided via STDIN as a JSON object.", - ) - ) - .subcommand( - trx_hash( - "trace-hash", - "trace_hash", - "Emulation transaction by hash to collecting traces. Additional `TransactionHashParams` can be provided via STDIN as a JSON object.", - ) - ) - .subcommand( - SubCommand::with_name("trace-next-block") - .about("Tracing all transactions in the block next to a given block (slot) number. \ - For this command, SLOT argument is required. \ - Additional `TraceNextBlockParams` can be provided via STDIN as a JSON object.") - .arg(token_mint_arg()) - .arg(chain_id_arg()) - .arg(max_steps_arg()) - ) .subcommand( SubCommand::with_name("create-ether-account") .about("Create ethereum account") diff --git a/evm_loader/docker-compose-ci.yml b/evm_loader/docker-compose-ci.yml index 2580a89e9..a8f0e39c5 100644 --- a/evm_loader/docker-compose-ci.yml +++ b/evm_loader/docker-compose-ci.yml @@ -30,11 +30,6 @@ services: NEON_CHAIN_ID: 111 COMMITMENT: confirmed NEON_DB_CLICKHOUSE_URLS: "http://45.250.253.36:8123;http://45.250.253.38:8123" - NEON_DB_INDEXER_HOST: 45.250.253.32 - NEON_DB_INDEXER_PORT: 5432 - NEON_DB_INDEXER_DATABASE: indexer - NEON_DB_INDEXER_USER: postgres - NEON_DB_INDEXER_PASSWORD: $INDEXER_DB_PASSWORD KEYPAIR: /opt/operator-keypairs/id.json FEEPAIR: /opt/operator-keypairs/id.json image: ${EVM_LOADER_IMAGE} diff --git a/evm_loader/lib/Cargo.toml b/evm_loader/lib/Cargo.toml index 0123bd96a..9c0cf5ab2 100644 --- a/evm_loader/lib/Cargo.toml +++ b/evm_loader/lib/Cargo.toml @@ -28,8 +28,6 @@ ethnum = { version = "1.4", default-features = false, features = ["serde"] } goblin = { version = "0.6.0" } scroll = "0.11.0" tokio = { version = "1", features = ["full"] } -postgres = { version = "0.19", features = ["with-chrono-0_4", "array-impls"] } -tokio-postgres = { version = "0.7", features = ["with-uuid-0_8"] } lazy_static = "1.4" clickhouse = "0.11.5" tracing = "0.1" diff --git a/evm_loader/lib/src/config.rs b/evm_loader/lib/src/config.rs index be4f0dd33..f1293ff08 100644 --- a/evm_loader/lib/src/config.rs +++ b/evm_loader/lib/src/config.rs @@ -129,29 +129,9 @@ fn load_db_config_from_enviroment() -> ChDbConfig { .map(Some) .unwrap_or(None); - let indexer_host = - env::var("NEON_DB_INDEXER_HOST").expect("neon db indexer host valiable must be set"); - - let indexer_port = - env::var("NEON_DB_INDEXER_PORT").expect("neon db indexer port valiable must be set"); - - let indexer_database = env::var("NEON_DB_INDEXER_DATABASE") - .expect("neon db indexer database valiable must be set"); - - let indexer_user = - env::var("NEON_DB_INDEXER_USER").expect("neon db indexer user valiable must be set"); - - let indexer_password = env::var("NEON_DB_INDEXER_PASSWORD") - .expect("neon db indexer password valiable must be set"); - ChDbConfig { clickhouse_url, clickhouse_user, clickhouse_password, - indexer_host, - indexer_port, - indexer_database, - indexer_user, - indexer_password, } } diff --git a/evm_loader/lib/src/context.rs b/evm_loader/lib/src/context.rs index e05fe4ea9..0d2b8c4b4 100644 --- a/evm_loader/lib/src/context.rs +++ b/evm_loader/lib/src/context.rs @@ -5,6 +5,7 @@ use crate::{ Config, NeonError, }; use solana_clap_utils::keypair::signer_from_path; +use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::signature::Signer; pub fn truncate_0x(in_str: &str) -> &str { @@ -24,13 +25,39 @@ impl Context { pub fn signer(&self) -> Result, NeonError> { build_signer(&self.signer_config) } -} -#[must_use] -pub fn create(rpc_client: Arc, signer_config: Arc) -> Context { - Context { - rpc_client, - signer_config, + pub async fn new_from_config( + config: Arc, + slot: Option, + ) -> Result { + let rpc_client: Arc = if let Some(slot) = slot { + Arc::new( + rpc::CallDbClient::new( + crate::types::TracerDb::new( + config.db_config.as_ref().expect("db-config not found"), + ), + slot, + ) + .await?, + ) + } else { + Arc::new(RpcClient::new_with_commitment( + config.json_rpc_url.clone(), + config.commitment, + )) + }; + + Ok(Self { + rpc_client, + signer_config: config.clone(), + }) + } + + pub fn new(rpc_client: Arc, signer_config: Arc) -> Self { + Self { + rpc_client, + signer_config, + } } } diff --git a/evm_loader/lib/src/errors.rs b/evm_loader/lib/src/errors.rs index 207624186..abe19885c 100644 --- a/evm_loader/lib/src/errors.rs +++ b/evm_loader/lib/src/errors.rs @@ -13,7 +13,7 @@ use solana_sdk::signer::SignerError as SolanaSignerError; use thiserror::Error; use crate::commands::init_environment::EnvironmentError; -use crate::types::{ChError, PgError}; +use crate::types::ChError; /// Errors that may be returned by the neon-cli program. #[derive(Debug, Error)] @@ -93,8 +93,6 @@ pub enum NeonError { WrongEnvironment, #[error("Hex Error. {0}")] FromHexError(#[from] hex::FromHexError), - #[error("PostgreSQL Error: {0}")] - PostgresError(#[from] PgError), #[error("Panic: {0}")] Panic(String), #[error("ClickHouse: {0}")] @@ -135,7 +133,6 @@ impl NeonError { NeonError::IncorrectAddress(_) => 248, NeonError::IncorrectIndex(_) => 249, NeonError::TxParametersParsingError(_) => 250, - NeonError::PostgresError(_) => 251, NeonError::ClickHouse(_) => 252, NeonError::EarlySlot(_, _) => 253, } diff --git a/evm_loader/lib/src/rpc/db_call_client.rs b/evm_loader/lib/src/rpc/db_call_client.rs index 24e97e614..a84aa7dce 100644 --- a/evm_loader/lib/src/rpc/db_call_client.rs +++ b/evm_loader/lib/src/rpc/db_call_client.rs @@ -1,5 +1,5 @@ use super::{e, Rpc}; -use crate::types::{TracerDb, TxParams}; +use crate::types::TracerDb; use crate::NeonError; use async_trait::async_trait; use solana_client::{ @@ -192,12 +192,6 @@ impl Rpc for CallDbClient { )) } - async fn get_transaction_data(&self) -> ClientResult { - Err(e!( - "get_transaction_data() not implemented for db_call_client" - )) - } - fn as_any(&self) -> &dyn Any { self } diff --git a/evm_loader/lib/src/rpc/db_trx_client.rs b/evm_loader/lib/src/rpc/db_trx_client.rs deleted file mode 100644 index bf6da857a..000000000 --- a/evm_loader/lib/src/rpc/db_trx_client.rs +++ /dev/null @@ -1,217 +0,0 @@ -use super::{e, Rpc}; -use crate::types::{IndexerDb, TracerDb, TxParams}; -use async_trait::async_trait; -use solana_client::{ - client_error::Result as ClientResult, - client_error::{ClientError, ClientErrorKind}, - rpc_config::{RpcSendTransactionConfig, RpcTransactionConfig}, - rpc_response::{Response, RpcResponseContext, RpcResult}, -}; -use solana_sdk::{ - account::Account, - clock::{Slot, UnixTimestamp}, - commitment_config::CommitmentConfig, - hash::Hash, - pubkey::Pubkey, - signature::Signature, - transaction::Transaction, -}; -use solana_transaction_status::{ - EncodedConfirmedBlock, EncodedConfirmedTransactionWithStatusMeta, TransactionStatus, -}; -use std::any::Any; - -pub struct TrxDbClient { - pub hash: [u8; 32], - sol_sig: [u8; 64], - tracer_db: TracerDb, - indexer_db: IndexerDb, -} - -impl TrxDbClient { - pub async fn new(tracer_db: TracerDb, indexer_db: IndexerDb, hash: [u8; 32]) -> Self { - let sol_sig = indexer_db - .get_sol_sig(&hash) - .await - .unwrap_or_else(|_| panic!("get_sol_sig error, hash: 0x{}", hex::encode(hash))); - - Self { - hash, - sol_sig, - tracer_db, - indexer_db, - } - } -} - -#[async_trait] -impl Rpc for TrxDbClient { - fn commitment(&self) -> CommitmentConfig { - CommitmentConfig::default() - } - - async fn confirm_transaction_with_spinner( - &self, - _signature: &Signature, - _recent_blockhash: &Hash, - _commitment_config: CommitmentConfig, - ) -> ClientResult<()> { - Err(e!( - "confirm_transaction_with_spinner() not implemented for trx rpc client" - )) - } - - async fn get_account(&self, key: &Pubkey) -> ClientResult { - self.tracer_db - .get_account_by_sol_sig(key, &self.sol_sig) - .await - .map_err(|e| e!("load account error", key, e))? - .ok_or_else(|| e!("account not found", key)) - } - - async fn get_account_with_commitment( - &self, - key: &Pubkey, - _commitment: CommitmentConfig, - ) -> RpcResult> { - let account = self - .tracer_db - .get_account_by_sol_sig(key, &self.sol_sig) - .await - .map_err(|e| e!("load account error", key, e))?; - - let slot = self - .indexer_db - .get_slot(&self.hash) - .await - .map_err(|e| e!("get_slot error", e))?; - - let context = RpcResponseContext { - slot, - api_version: None, - }; - Ok(Response { - context, - value: account, - }) - } - - async fn get_multiple_accounts( - &self, - pubkeys: &[Pubkey], - ) -> ClientResult>> { - let mut result = Vec::new(); - for key in pubkeys { - let account = self - .tracer_db - .get_account_by_sol_sig(key, &self.sol_sig) - .await - .map_err(|e| e!("load account error", key, e))?; - result.push(account); - } - Ok(result) - } - - async fn get_account_data(&self, key: &Pubkey) -> ClientResult> { - Ok(self.get_account(key).await?.data) - } - - async fn get_block(&self, _slot: Slot) -> ClientResult { - Err(e!("get_block() not implemented for db_trx_client")) - } - - async fn get_block_time(&self, slot: Slot) -> ClientResult { - self.tracer_db - .get_block_time(slot) - .await - .map_err(|e| e!("get_block_time error", slot, e)) - } - - async fn get_latest_blockhash(&self) -> ClientResult { - Err(e!( - "get_latest_blockhash() not implemented for db_trx_client" - )) - } - - async fn get_minimum_balance_for_rent_exemption(&self, _data_len: usize) -> ClientResult { - Err(e!( - "get_minimum_balance_for_rent_exemption() not implemented for db_trx_client" - )) - } - - async fn get_slot(&self) -> ClientResult { - self.indexer_db - .get_slot(&self.hash) - .await - .map_err(|e| e!("get_slot error", e)) - } - - async fn get_signature_statuses( - &self, - _signatures: &[Signature], - ) -> RpcResult>> { - Err(e!( - "get_signature_statuses() not implemented for db_trx_client" - )) - } - - async fn get_transaction_with_config( - &self, - _signature: &Signature, - _config: RpcTransactionConfig, - ) -> ClientResult { - Err(e!( - "get_transaction_with_config() not implemented for db_trx_client" - )) - } - - async fn send_transaction(&self, _transaction: &Transaction) -> ClientResult { - Err(e!("send_transaction() not implemented for db_trx_client")) - } - - async fn send_and_confirm_transaction_with_spinner( - &self, - _transaction: &Transaction, - ) -> ClientResult { - Err(e!( - "send_and_confirm_transaction_with_spinner() not implemented for db_trx_client" - )) - } - - async fn send_and_confirm_transaction_with_spinner_and_commitment( - &self, - _transaction: &Transaction, - _commitment: CommitmentConfig, - ) -> ClientResult { - Err(e!("send_and_confirm_transaction_with_spinner_and_commitment() not implemented for db_trx_client")) - } - - async fn send_and_confirm_transaction_with_spinner_and_config( - &self, - _transaction: &Transaction, - _commitment: CommitmentConfig, - _config: RpcSendTransactionConfig, - ) -> ClientResult { - Err(e!("send_and_confirm_transaction_with_spinner_and_config() not implemented for db_trx_client")) - } - - async fn get_latest_blockhash_with_commitment( - &self, - _commitment: CommitmentConfig, - ) -> ClientResult<(Hash, u64)> { - Err(e!( - "get_latest_blockhash_with_commitment() not implemented for db_trx_client" - )) - } - - async fn get_transaction_data(&self) -> ClientResult { - self.indexer_db - .get_transaction_data(&self.hash) - .await - .map_err(|e| e!("load transaction error", self.hash, e)) - } - - fn as_any(&self) -> &dyn Any { - self - } -} diff --git a/evm_loader/lib/src/rpc/mod.rs b/evm_loader/lib/src/rpc/mod.rs index 05bbe2404..d6fcc1f7c 100644 --- a/evm_loader/lib/src/rpc/mod.rs +++ b/evm_loader/lib/src/rpc/mod.rs @@ -1,11 +1,8 @@ mod db_call_client; -mod db_trx_client; mod validator_client; pub use db_call_client::CallDbClient; -pub use db_trx_client::TrxDbClient; -use crate::types::TxParams; use crate::{NeonError, NeonResult}; use async_trait::async_trait; use solana_cli::cli::CliError; @@ -83,7 +80,7 @@ pub trait Rpc: Send + Sync { &self, commitment: CommitmentConfig, ) -> ClientResult<(Hash, u64)>; - async fn get_transaction_data(&self) -> ClientResult; + fn as_any(&self) -> &dyn Any; } diff --git a/evm_loader/lib/src/rpc/validator_client.rs b/evm_loader/lib/src/rpc/validator_client.rs index 73ded9193..ab4cbab12 100644 --- a/evm_loader/lib/src/rpc/validator_client.rs +++ b/evm_loader/lib/src/rpc/validator_client.rs @@ -1,9 +1,7 @@ -use super::{e, Rpc}; -use crate::types::TxParams; +use super::Rpc; use async_trait::async_trait; use solana_client::{ client_error::Result as ClientResult, - client_error::{ClientError, ClientErrorKind}, nonblocking::rpc_client::RpcClient, rpc_config::{RpcSendTransactionConfig, RpcTransactionConfig}, rpc_response::RpcResult, @@ -134,12 +132,6 @@ impl Rpc for RpcClient { self.get_latest_blockhash_with_commitment(commitment).await } - async fn get_transaction_data(&self) -> ClientResult { - Err(e!( - "get_transaction_data() not implemented for validator_client" - )) - } - fn as_any(&self) -> &dyn Any { self } diff --git a/evm_loader/lib/src/types/indexer_db.rs b/evm_loader/lib/src/types/indexer_db.rs deleted file mode 100644 index 9a716cee5..000000000 --- a/evm_loader/lib/src/types/indexer_db.rs +++ /dev/null @@ -1,176 +0,0 @@ -use { - super::{do_connect, ChDbConfig, PgError, PgResult, TxParams}, - ethnum::U256, - evm_loader::types::Address, - solana_sdk::clock::Slot, - std::{ - convert::{TryFrom, TryInto}, - sync::Arc, - }, - tokio_postgres::Client, -}; - -#[derive(Debug, Clone)] -pub struct IndexerDb { - pub client: Arc, -} - -const TXPARAMS_FIELDS: &str = - "from_addr, COALESCE(to_addr, contract), calldata, value, gas_limit, nonce"; - -impl IndexerDb { - pub async fn new(config: &ChDbConfig) -> Self { - let client = do_connect( - &config.indexer_host, - &config.indexer_port, - &config.indexer_database, - &config.indexer_user, - &config.indexer_password, - ) - .await; - Self { - client: Arc::new(client), - } - } - - pub async fn get_sol_sig(&self, hash: &[u8; 32]) -> PgResult<[u8; 64]> { - let hex = format!("0x{}", hex::encode(hash)); - let row = self - .client - .query_one( - "SELECT S.sol_sig from solana_neon_transactions S, solana_blocks B \ - where S.block_slot = B.block_slot \ - and B.is_active = true \ - and S.neon_sig = $1", - &[&hex], - ) - .await?; - let sol_sig_b58: &str = row.try_get(0)?; - let sol_sig_b58 = sol_sig_b58.to_string(); - let sol_sig = bs58::decode(sol_sig_b58) - .into_vec() - .map_err(|e| PgError::Custom(format!("sol_sig_b58 cast error: {e}")))?; - sol_sig - .as_slice() - .try_into() - .map_err(|e| PgError::Custom(format!("sol_sig cast error: {e}"))) - } - - pub async fn get_slot(&self, hash: &[u8; 32]) -> PgResult { - let hex = format!("0x{}", hex::encode(hash)); - let row = self - .client - .query_one( - "SELECT min(S.block_slot) from solana_neon_transactions S, solana_blocks B \ - where S.block_slot = B.block_slot \ - and B.is_active = true \ - and S.neon_sig = $1", - &[&hex], - ) - .await?; - let slot: i64 = row.try_get(0)?; - u64::try_from(slot).map_err(|e| PgError::Custom(format!("slot cast error: {e}"))) - } - - #[allow(unused)] - pub async fn get_slot_by_block_hash(&self, block_hash: &[u8; 32]) -> PgResult { - let hex = format!("0x{}", hex::encode(block_hash)); - let row = self - .client - .query_one( - "SELECT block_slot FROM solana_blocks WHERE block_hash = $1 AND is_active = TRUE", - &[&hex], - ) - .await?; - - let slot: i64 = row - .try_get(0) - .map_err(std::convert::Into::::into)?; - - slot.try_into() - .map_err(|e| PgError::Custom(format!("slot cast error: {e}"))) - } - - pub async fn get_transaction_data(&self, hash: &[u8; 32]) -> PgResult { - let hex = format!("0x{}", hex::encode(hash)); - - let row = self - .client - .query_one( - &format!( - "select distinct {TXPARAMS_FIELDS} \ - from neon_transactions as t, solana_blocks as b \ - where t.block_slot = b.block_slot \ - and b.is_active = TRUE \ - and t.neon_sig = $1" - ), - &[&hex], - ) - .await?; - - Self::extract_transaction(&row) - } - - pub async fn get_block_transactions(&self, slot: u64) -> PgResult> { - let slot: i64 = slot - .try_into() - .map_err(|e| PgError::Custom(format!("slot cast error: {e}")))?; - - let rows = self - .client - .query( - &format!( - "\ - SELECT {TXPARAMS_FIELDS} \ - FROM neon_transactions t \ - INNER JOIN solana_blocks b ON t.block_slot = b.block_slot \ - WHERE b.is_active = TRUE AND t.block_slot = $1 \ - ORDER BY tx_idx\ - " - ), - &[&slot], - ) - .await?; - - let mut transactions = vec![]; - for row in rows { - transactions.push(Self::extract_transaction(&row)?); - } - - Ok(transactions) - } - - fn extract_transaction(row: &tokio_postgres::Row) -> PgResult { - let from: String = row.try_get(0)?; - let to: String = row.try_get(1)?; - let data: String = row.try_get(2)?; - let value: String = row.try_get(3)?; - let gas_limit: String = row.try_get(4)?; - let nonce: String = row.try_get(5)?; - - let from = Address::from_hex(&from.as_str()[2..]) - .map_err(|e| PgError::Custom(format!("from_address cast error: {e}")))?; - let to = Address::from_hex(&to.as_str()[2..]) - .map_err(|e| PgError::Custom(format!("to_address cast error: {e}")))?; - let data = hex::decode(&data.as_str()[2..]) - .map_err(|e| PgError::Custom(format!("data cast error: {e}")))?; - let value: U256 = U256::from_str_hex(&value) - .map_err(|e| PgError::Custom(format!("value cast error: {e}")))?; - let gas_limit: U256 = U256::from_str_hex(&gas_limit) - .map_err(|e| PgError::Custom(format!("gas_limit cast error: {e}")))?; - let nonce: u64 = U256::from_str_hex(&nonce) - .map_err(|e| PgError::Custom(format!("nonce cast error: {e}")))? - .try_into() - .map_err(|e| PgError::Custom(format!("nonce cast error: {e}")))?; - - Ok(TxParams { - nonce: Some(nonce), - from, - to: Some(to), - data: Some(data), - value: Some(value), - gas_limit: Some(gas_limit), - access_list: None, - }) - } -} diff --git a/evm_loader/lib/src/types/mod.rs b/evm_loader/lib/src/types/mod.rs index 633b2e785..a3f014d7b 100644 --- a/evm_loader/lib/src/types/mod.rs +++ b/evm_loader/lib/src/types/mod.rs @@ -1,25 +1,19 @@ -mod indexer_db; pub mod request_models; mod tracer_ch_db; pub use evm_loader::types::Address; -pub use indexer_db::IndexerDb; use lazy_static::lazy_static; use solana_sdk::pubkey::Pubkey; use std::str::FromStr; use tokio::runtime::Runtime; use tokio::task::block_in_place; pub use tracer_ch_db::{ChError, ChResult, ClickHouseDb as TracerDb}; -use tracing::error; -use evm_loader::evm::tracing::{TraceCallConfig, TraceConfig}; +use evm_loader::evm::tracing::TraceCallConfig; use evm_loader::types::hexbytes::HexBytes; use { ethnum::U256, - postgres::NoTls, serde::{Deserialize, Deserializer, Serialize, Serializer}, - thiserror::Error, - tokio_postgres::{connect, Client}, }; #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone, Default)] @@ -27,11 +21,6 @@ pub struct ChDbConfig { pub clickhouse_url: Vec, pub clickhouse_user: Option, pub clickhouse_password: Option, - pub indexer_host: String, - pub indexer_port: String, - pub indexer_database: String, - pub indexer_user: String, - pub indexer_password: String, } #[derive(Clone, Serialize, Deserialize, Debug)] @@ -57,49 +46,6 @@ pub struct TransactionParams { pub trace_config: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TransactionHashParams { - pub trace_config: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TraceNextBlockParams { - pub trace_config: Option, -} - -pub async fn do_connect( - host: &String, - port: &String, - db: &String, - user: &String, - pass: &String, -) -> Client { - let authority = format!("host={host} port={port} dbname={db} user={user} password={pass}"); - - let mut attempt = 0; - let mut result = None; - - while attempt < 3 { - match connect(&authority, NoTls).await { - Ok(res) => { - result = Some(res); - break; - } - Err(e) => error!("Error connecting to database {authority}: {e}"), - }; - attempt += 1; - } - - let (client, connection) = result.expect("error to set DB connection"); - - tokio::spawn(async move { - if let Err(e) = connection.await { - eprintln!("connection error: {e}"); - } - }); - client -} - lazy_static! { pub static ref RT: Runtime = Runtime::new().unwrap(); } @@ -114,16 +60,6 @@ where } } -#[derive(Error, Debug)] -pub enum PgError { - #[error("postgres: {}", .0)] - Db(#[from] tokio_postgres::Error), - #[error("Custom: {0}")] - Custom(String), -} - -pub type PgResult = std::result::Result; - #[derive(Debug, Default, Clone, Copy)] pub struct PubkeyBase58(pub Pubkey); diff --git a/evm_loader/lib/src/types/request_models.rs b/evm_loader/lib/src/types/request_models.rs index d1b76da52..a1f3b180e 100644 --- a/evm_loader/lib/src/types/request_models.rs +++ b/evm_loader/lib/src/types/request_models.rs @@ -1,6 +1,6 @@ use crate::types::{PubkeyBase58, TxParams}; use ethnum::U256; -use evm_loader::evm::tracing::{TraceCallConfig, TraceConfig}; +use evm_loader::evm::tracing::TraceCallConfig; use evm_loader::types::Address; use serde::{Deserialize, Serialize}; use solana_sdk::debug_account_data::debug_account_data; @@ -104,31 +104,9 @@ pub struct EmulateRequestModel { pub slot: Option, } -#[derive(Deserialize, Serialize, Debug, Default)] -pub struct EmulateHashRequestModel { - #[serde(flatten)] - pub emulation_params: EmulationParamsRequestModel, - pub hash: String, -} - #[derive(Deserialize, Serialize, Debug, Default)] pub struct TraceRequestModel { #[serde(flatten)] pub emulate_request: EmulateRequestModel, pub trace_call_config: Option, } - -#[derive(Deserialize, Serialize, Debug, Default)] -pub struct TraceHashRequestModel { - #[serde(flatten)] - pub emulate_hash_request: EmulateHashRequestModel, - pub trace_config: Option, -} - -#[derive(Deserialize, Serialize, Debug, Default)] -pub struct TraceNextBlockRequestModel { - #[serde(flatten)] - pub emulation_params: EmulationParamsRequestModel, - pub slot: u64, - pub trace_config: Option, -}