Skip to content

Commit

Permalink
NDEV-2043: Replace library feature with target_os = "solana"
Browse files Browse the repository at this point in the history
  • Loading branch information
andreisilviudragnea committed Sep 25, 2023
1 parent b04820f commit 88a25cb
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ WORKDIR /opt/evm_loader
ARG REVISION
ENV NEON_REVISION=${REVISION}
RUN cargo fmt --check && \
cargo clippy --no-default-features --release && \
cargo build --no-default-features --release && \
cargo clippy --release && \
cargo build --release && \
cargo build-bpf --features devnet && cp target/deploy/evm_loader.so target/deploy/evm_loader-devnet.so && \
cargo build-bpf --features testnet && cp target/deploy/evm_loader.so target/deploy/evm_loader-testnet.so && \
cargo build-bpf --features govertest && cp target/deploy/evm_loader.so target/deploy/evm_loader-govertest.so && \
Expand Down
2 changes: 1 addition & 1 deletion evm_loader/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
thiserror = "1.0"
anyhow = "1.0"
bincode = "1.3.1"
evm-loader = { path = "../program", default-features = false, features = ["log", "library"] }
evm-loader = { path = "../program", default-features = false, features = ["log", "async-trait", "serde_json"] }
solana-sdk = "=1.16.14"
solana-client = "=1.16.14"
solana-clap-utils = "=1.16.14"
Expand Down
10 changes: 6 additions & 4 deletions evm_loader/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ emergency = []
no-entrypoint = []
test-bpf = []
custom-heap = []
default = ["custom-heap", "maybe-async/is_sync"]

library = ["serde_json", "maybe-async", "async-trait"]
default = ["custom-heap"]

[dependencies]
linked_list_allocator = { version = "0.10", default-features = false }
Expand All @@ -58,9 +56,13 @@ ethnum = { version = "1.4", default-features = false, features = ["serde"] }
const_format = { version = "0.2.21" }
cfg-if = { version = "1.0" }
log = { version = "0.4", default-features = false, optional = true }
maybe-async = { version = "0.2.7", optional = true }
maybe-async = "0.2.7"
async-trait = { version = "0.1.73", optional = true }

[target.'cfg(target_os = "solana")'.dependencies.maybe-async]
version = "0.2.7"
features = ["is_sync"]

[lib]
crate-type = ["cdylib", "lib"]

Expand Down
10 changes: 5 additions & 5 deletions evm_loader/program/src/account_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::types::Address;
use ethnum::U256;
use maybe_async::maybe_async;
use solana_program::account_info::AccountInfo;
#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
use {
crate::account::EthereumStorage, solana_program::clock::Clock, std::cell::RefCell,
std::collections::HashSet,
Expand All @@ -15,11 +15,11 @@ use solana_program::slot_history::Slot;
use std::cmp::Ordering;
use std::collections::HashMap;

#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
mod apply;
#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
mod backend;
#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
mod base;

#[derive(Debug)]
Expand All @@ -37,7 +37,7 @@ pub enum AccountsReadiness {
NeedMoreReallocations,
}

#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
pub struct ProgramAccountStorage<'a> {
program_id: &'a Pubkey,
operator: &'a Pubkey,
Expand Down
16 changes: 8 additions & 8 deletions evm_loader/program/src/evm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::Range;
use solana_program::program_memory::{sol_memcpy, sol_memset};

use crate::error::Error;
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
use crate::evm::tracing::TracerTypeOpt;

use super::utils::checked_next_multiple_of_32;
Expand All @@ -20,22 +20,22 @@ pub struct Memory {
data: *mut u8,
capacity: usize,
size: usize,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer: TracerTypeOpt,
}

impl Memory {
pub fn new(#[cfg(feature = "library")] tracer: TracerTypeOpt) -> Self {
pub fn new(#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt) -> Self {
Self::with_capacity(
MEMORY_CAPACITY,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
)
}

pub fn with_capacity(
capacity: usize,
#[cfg(feature = "library")] tracer: TracerTypeOpt,
#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt,
) -> Self {
unsafe {
let layout = Layout::from_size_align_unchecked(capacity, MEMORY_ALIGN);
Expand All @@ -48,7 +48,7 @@ impl Memory {
data,
capacity,
size: 0,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
}
}
Expand All @@ -70,13 +70,13 @@ impl Memory {
data,
capacity,
size: v.len(),
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer: None,
}
}
}

#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
pub fn to_vec(&self) -> Vec<u8> {
let slice = unsafe { std::slice::from_raw_parts(self.data, self.size) };
slice.to_vec()
Expand Down
44 changes: 22 additions & 22 deletions evm_loader/program/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_program::log::sol_log_data;

pub use buffer::Buffer;

#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
use crate::evm::tracing::TracerTypeOpt;
use crate::{
error::{build_revert_message, Error, Result},
Expand All @@ -28,19 +28,19 @@ mod opcode;
mod opcode_table;
mod precompile;
mod stack;
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
pub mod tracing;
mod utils;

macro_rules! tracing_event {
($self:ident, $x:expr) => {
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
if let Some(tracer) = &$self.tracer {
tracer.borrow_mut().event($x);
}
};
($self:ident, $condition:expr, $x:expr) => {
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
if let Some(tracer) = &$self.tracer {
if $condition {
tracer.borrow_mut().event($x);
Expand All @@ -51,7 +51,7 @@ macro_rules! tracing_event {

macro_rules! trace_end_step {
($self:ident, $return_data:expr) => {
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
if let Some(tracer) = &$self.tracer {
tracer
.borrow_mut()
Expand All @@ -62,7 +62,7 @@ macro_rules! trace_end_step {
}
};
($self:ident, $condition:expr; $return_data_getter:expr) => {
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
if $condition {
trace_end_step!($self, $return_data_getter)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ pub struct Machine<B: Database> {
#[serde(skip)]
phantom: PhantomData<*const B>,

#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
#[serde(skip)]
tracer: TracerTypeOpt,
}
Expand All @@ -167,7 +167,7 @@ impl<B: Database> Machine<B> {
cursor.position().try_into().map_err(Error::from)
}

#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
pub fn deserialize_from(buffer: &[u8], backend: &B) -> Result<Self> {
fn reinit_buffer<B: Database>(buffer: &mut Buffer, backend: &B) {
if let Some((key, range)) = buffer.uninit_data() {
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<B: Database> Machine<B> {
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "library")] tracer: TracerTypeOpt,
#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt,
) -> Result<Self> {
let origin_nonce = backend.nonce(&origin).await?;

Expand Down Expand Up @@ -235,7 +235,7 @@ impl<B: Database> Machine<B> {
trx,
origin,
backend,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
)
.await
Expand All @@ -244,7 +244,7 @@ impl<B: Database> Machine<B> {
trx,
origin,
backend,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
)
.await
Expand All @@ -256,7 +256,7 @@ impl<B: Database> Machine<B> {
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "library")] tracer: TracerTypeOpt,
#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt,
) -> Result<Self> {
assert!(trx.target().is_some());

Expand Down Expand Up @@ -285,19 +285,19 @@ impl<B: Database> Machine<B> {
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
memory: Memory::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
pc: 0_usize,
is_static: false,
reason: Reason::Call,
parent: None,
phantom: PhantomData,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
})
}
Expand All @@ -307,7 +307,7 @@ impl<B: Database> Machine<B> {
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "library")] tracer: TracerTypeOpt,
#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt,
) -> Result<Self> {
assert!(trx.target().is_none());

Expand Down Expand Up @@ -337,11 +337,11 @@ impl<B: Database> Machine<B> {
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
memory: Memory::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
pc: 0_usize,
Expand All @@ -351,7 +351,7 @@ impl<B: Database> Machine<B> {
call_data: Buffer::empty(),
parent: None,
phantom: PhantomData,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer,
})
}
Expand Down Expand Up @@ -450,19 +450,19 @@ impl<B: Database> Machine<B> {
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
self.tracer.clone(),
),
memory: Memory::new(
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
self.tracer.clone(),
),
pc: 0_usize,
is_static: self.is_static,
reason,
parent: None,
phantom: PhantomData,
#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
tracer: self.tracer.clone(),
};

Expand Down
8 changes: 4 additions & 4 deletions evm_loader/program/src/evm/opcode_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use super::{database::Database, opcode::Action, Machine};

macro_rules! opcode_table {
($( $opcode:literal, $opname:literal, $op:path;)*) => {
#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
type OpCode<B> = fn(&mut Machine<B>, &mut B) -> Result<Action>;

#[cfg(not(feature = "library"))]
#[cfg(target_os = "solana")]
impl<B: Database> Machine<B> {
const OPCODES: [OpCode<B>; 256] = {
let mut opcodes: [OpCode<B>; 256] = [Self::opcode_unknown; 256];
Expand All @@ -24,7 +24,7 @@ macro_rules! opcode_table {
}
}

#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
impl<B: Database> Machine<B> {
pub async fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result<Action> {
match opcode {
Expand All @@ -34,7 +34,7 @@ macro_rules! opcode_table {
}
}

#[cfg(feature = "library")]
#[cfg(not(target_os = "solana"))]
pub const OPNAMES: [&str; 256] = {
let mut opnames: [&str; 256] = ["<invalid>"; 256];

Expand Down
Loading

0 comments on commit 88a25cb

Please sign in to comment.