Skip to content

Commit

Permalink
Develop -> feat/ci-cd-new-runner (#573)
Browse files Browse the repository at this point in the history
* NDEV-3421 Do not check accounts for rent-exempt (#571)

Co-authored-by: Semen Medvedev <[email protected]>

* add methods to the RPC client (#564)

* add methods to the erc client

* async send rpc client

---------

Co-authored-by: s-medvedev <[email protected]>
Co-authored-by: Semen Medvedev <[email protected]>
Co-authored-by: Vladimir Bugaev <[email protected]>
  • Loading branch information
4 people authored Nov 22, 2024
1 parent 3d45eb9 commit f00e5b1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 27 deletions.
10 changes: 5 additions & 5 deletions evm_loader/lib-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use abi_stable::{

#[repr(C)]
#[derive(StableAbi)]
#[sabi(kind(Prefix(prefix_ref = NeonEVMLib_Ref)))]
#[sabi(kind(Prefix(prefix_ref = NeonEVMLibRef)))]
#[sabi(missing_field(panic))]
pub struct NeonEVMLib {
pub hash: extern "C" fn() -> RString,
Expand All @@ -28,8 +28,8 @@ pub struct NeonEVMLib {
}

#[allow(clippy::use_self)]
impl RootModule for NeonEVMLib_Ref {
abi_stable::declare_root_module_statics! {NeonEVMLib_Ref}
impl RootModule for NeonEVMLibRef {
abi_stable::declare_root_module_statics! {NeonEVMLibRef}

const BASE_NAME: &'static str = "neon-lib-interface";
const NAME: &'static str = "neon-lib-interface";
Expand All @@ -46,14 +46,14 @@ pub enum NeonEVMLibLoadError {

pub fn load_libraries<P>(
directory: P,
) -> Result<HashMap<String, NeonEVMLib_Ref>, NeonEVMLibLoadError>
) -> Result<HashMap<String, NeonEVMLibRef>, NeonEVMLibLoadError>
where
P: AsRef<Path>,
{
let paths = std::fs::read_dir(directory)?;
let mut result = HashMap::new();
for path in paths {
let lib = NeonEVMLib_Ref::load_from_file(&path?.path())?;
let lib = NeonEVMLibRef::load_from_file(&path?.path())?;
let hash = lib.hash()();

result.insert(hash.into_string(), lib);
Expand Down
5 changes: 0 additions & 5 deletions evm_loader/lib/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,6 @@ impl<'a, T: Rpc> EmulatorAccountStorage<'_, T> {
let new_lamports = new_acc.lamports;
let new_size = new_acc.get_length();

if new_acc.is_busy() && new_lamports < self.rent.minimum_balance(new_acc.get_length()) {
info!("Account {pubkey} is not rent exempt");
return Err(ProgramError::AccountNotRentExempt.into());
}

let old_lamports = lamports_after_upgrade.unwrap_or(original_lamports);
old_lamports_sum += old_lamports;
new_lamports_sum += new_lamports;
Expand Down
10 changes: 5 additions & 5 deletions evm_loader/lib/src/build_info_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use build_info::chrono::{DateTime, Utc};
use build_info::semver::Version;
use build_info::VersionControl::Git;
use build_info::{BuildInfo, OptimizationLevel};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SlimBuildInfo {
timestamp: DateTime<Utc>,
profile: String,
Expand All @@ -15,18 +15,18 @@ pub struct SlimBuildInfo {
version_control: GitInfo,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
struct CrateInfo {
name: String,
version: Version,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
struct CompilerInfo {
version: Version,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
struct GitInfo {
commit_id: String,
dirty: bool,
Expand Down
6 changes: 3 additions & 3 deletions evm_loader/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ use abi::_MODULE_WM_;
use abi_stable::export_root_module;
pub use config::Config;
pub use errors::NeonError;
use neon_lib_interface::NeonEVMLib_Ref;
use neon_lib_interface::NeonEVMLibRef;

pub type NeonResult<T> = Result<T, NeonError>;

const MODULE: NeonEVMLib_Ref = NeonEVMLib_Ref(_MODULE_WM_.static_as_prefix());
const MODULE: NeonEVMLibRef = NeonEVMLibRef(_MODULE_WM_.static_as_prefix());

#[export_root_module]
#[must_use]
pub const fn get_root_module() -> NeonEVMLib_Ref {
pub const fn get_root_module() -> NeonEVMLibRef {
MODULE
}

Expand Down
27 changes: 26 additions & 1 deletion evm_loader/rpc-client/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use async_trait::async_trait;
use jsonrpsee_core::{client::ClientT, rpc_params};
use jsonrpsee_http_client::{HttpClient, HttpClientBuilder};
use neon_lib::build_info_common::SlimBuildInfo;
use neon_lib::commands::simulate_solana::SimulateSolanaResponse;
use neon_lib::types::SimulateSolanaRequest;
use neon_lib::LibMethod;
use neon_lib::{
commands::{
Expand Down Expand Up @@ -52,7 +55,7 @@ impl Default for NeonRpcHttpClientBuilder {
}
}

#[async_trait(?Send)]
#[async_trait]
impl NeonRpcClient for NeonRpcHttpClient {
async fn emulate(&self, params: EmulateApiRequest) -> NeonRpcClientResult<EmulateResponse> {
self.request(LibMethod::Emulate, params).await
Expand Down Expand Up @@ -90,6 +93,21 @@ impl NeonRpcClient for NeonRpcHttpClient {
async fn trace(&self, params: EmulateApiRequest) -> NeonRpcClientResult<serde_json::Value> {
self.request(LibMethod::Trace, params).await
}

async fn simulate_solana(
&self,
params: SimulateSolanaRequest,
) -> NeonRpcClientResult<SimulateSolanaResponse> {
self.request(LibMethod::SimulateSolana, params).await
}

async fn build_info(&self) -> NeonRpcClientResult<SlimBuildInfo> {
self.custom_request_without_params("build_info").await
}

async fn lib_build_info(&self) -> NeonRpcClientResult<SlimBuildInfo> {
self.custom_request_without_params("lib_build_info").await
}
}

impl NeonRpcHttpClient {
Expand All @@ -110,4 +128,11 @@ impl NeonRpcHttpClient {
{
Ok(self.client.request(method.into(), rpc_params![]).await?)
}

async fn custom_request_without_params<R>(&self, method: &str) -> NeonRpcClientResult<R>
where
R: DeserializeOwned,
{
Ok(self.client.request(method, rpc_params![]).await?)
}
}
15 changes: 11 additions & 4 deletions evm_loader/rpc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ pub use error::NeonRpcClientError;

use async_trait::async_trait;
use neon_lib::{
build_info_common::SlimBuildInfo,
commands::{
emulate::EmulateResponse, get_balance::GetBalanceResponse, get_config::GetConfigResponse,
get_contract::GetContractResponse, get_holder::GetHolderResponse,
get_storage_at::GetStorageAtReturn,
get_storage_at::GetStorageAtReturn, simulate_solana::SimulateSolanaResponse,
},
types::{
EmulateApiRequest, GetBalanceRequest, GetContractRequest, GetHolderRequest,
GetStorageAtRequest,
GetStorageAtRequest, SimulateSolanaRequest,
},
};

type NeonRpcClientResult<T> = Result<T, NeonRpcClientError>;

#[async_trait(?Send)]
pub trait NeonRpcClient {
#[async_trait]
pub trait NeonRpcClient: Sync + Send + 'static {
async fn emulate(&self, params: EmulateApiRequest) -> NeonRpcClientResult<EmulateResponse>;
async fn balance(
&self,
Expand All @@ -41,4 +42,10 @@ pub trait NeonRpcClient {
params: GetStorageAtRequest,
) -> NeonRpcClientResult<GetStorageAtReturn>;
async fn trace(&self, params: EmulateApiRequest) -> NeonRpcClientResult<serde_json::Value>;
async fn simulate_solana(
&self,
params: SimulateSolanaRequest,
) -> NeonRpcClientResult<SimulateSolanaResponse>;
async fn build_info(&self) -> NeonRpcClientResult<SlimBuildInfo>;
async fn lib_build_info(&self) -> NeonRpcClientResult<SlimBuildInfo>;
}
4 changes: 2 additions & 2 deletions evm_loader/rpc/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use neon_lib_interface::NeonEVMLib_Ref;
use neon_lib_interface::NeonEVMLibRef;
use std::collections::HashMap;

pub struct Context {
pub libraries: HashMap<String, NeonEVMLib_Ref>,
pub libraries: HashMap<String, NeonEVMLibRef>,
}
4 changes: 2 additions & 2 deletions evm_loader/rpc/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub mod trace;
use crate::context::Context;
use jsonrpc_v2::Data;
use neon_lib::LibMethod;
use neon_lib_interface::{types::NeonEVMLibError, NeonEVMLib_Ref};
use neon_lib_interface::{types::NeonEVMLibError, NeonEVMLibRef};
use serde::Serialize;
use serde_json::Value;

fn get_library(context: &Data<Context>) -> Result<&NeonEVMLib_Ref, jsonrpc_v2::Error> {
fn get_library(context: &Data<Context>) -> Result<&NeonEVMLibRef, jsonrpc_v2::Error> {
// just for testing
let hash = context
.libraries
Expand Down

0 comments on commit f00e5b1

Please sign in to comment.