Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM remove receipt type #719

Merged
merged 18 commits into from
Aug 23, 2023
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ borsh = { version = "0.10.3", features = ["rc", "bytes"] }
# TODO: Consider replacing this serialization format
# https://github.com/Sovereign-Labs/sovereign-sdk/issues/283
bincode = "1.3.3"
bcs = "0.1.5"
byteorder = "1.4.3"
bytes = "1.2.1"
hex = "0.4.3"
Expand All @@ -74,7 +75,7 @@ proptest-derive = "0.3.0"
rand = "0.8"
rayon = "1.5.2"
rocksdb = { version = "0.21.0", features = ["lz4"] }
serde = { version = "1.0.185", features = ["derive", "rc"] }
serde = { version = "1.0.185", features = ["derive", "rc"]}
serde_json = { version = "1.0" }
sha2 = "0.10.6"
digest = "0.10.6"
Expand Down
19 changes: 13 additions & 6 deletions module-system/module-implementations/sov-evm/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use ethers_core::types::{OtherFields, TransactionReceipt};
use revm::primitives::{CfgEnv, U256};
use sov_modules_api::CallResponse;
use sov_state::WorkingSet;
Expand All @@ -8,7 +9,7 @@ use crate::evm::executor::{self};
use crate::evm::transaction::{BlockEnv, EvmTransactionSignedEcRecovered};
use crate::evm::{contract_address, EvmChainCfg, RawEvmTransaction};
use crate::experimental::SpecIdWrapper;
use crate::{Evm, TransactionReceipt};
use crate::Evm;

#[cfg_attr(
feature = "native",
Expand Down Expand Up @@ -45,24 +46,30 @@ impl<C: sov_modules_api::Context> Evm<C> {
let receipt = TransactionReceipt {
transaction_hash: hash.into(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
transaction_index: 0,
transaction_index: 0u64.into(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
block_hash: Default::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
block_number: Some(0),
block_number: Some(0u64.into()),
from: evm_tx_recovered.signer().into(),
to: evm_tx_recovered.to(),
to: evm_tx_recovered.to().map(|to| to.into()),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
cumulative_gas_used: Default::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
gas_used: Default::default(),
contract_address: contract_address(result).map(|addr| addr.into()),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
status: Some(1),
status: Some(1u64.into()),
root: Default::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
transaction_type: Some(1),
transaction_type: Some(1u64.into()),
effective_gas_price: Default::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
logs_bloom: Default::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
other: OtherFields::default(),
// TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504
logs: Default::default(),
};

self.receipts
Expand Down
10 changes: 3 additions & 7 deletions module-system/module-implementations/sov-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ pub mod genesis;
#[cfg(feature = "experimental")]
pub mod query;
#[cfg(feature = "experimental")]
mod receipt;
#[cfg(feature = "experimental")]
#[cfg(test)]
mod tests;
#[cfg(feature = "experimental")]
pub use experimental::{AccountData, Evm, EvmConfig, SpecIdWrapper};
#[cfg(feature = "experimental")]
pub use receipt::TransactionReceipt;
#[cfg(feature = "experimental")]
pub use revm::primitives::SpecId;

#[cfg(feature = "experimental")]
mod experimental {
use std::collections::HashMap;

use derive_more::{From, Into};
use ethers::types::TransactionReceipt;
use revm::primitives::{SpecId, KECCAK_EMPTY, U256};
use sov_modules_api::{Error, ModuleInfo};
use sov_state::WorkingSet;
Expand All @@ -32,8 +29,6 @@ mod experimental {
use super::evm::transaction::BlockEnv;
use super::evm::{DbAccount, EthAddress};
use crate::evm::{Bytes32, EvmChainCfg, RawEvmTransaction};
use crate::TransactionReceipt;

#[derive(Clone, Debug)]
pub struct AccountData {
pub address: EthAddress,
Expand Down Expand Up @@ -92,7 +87,8 @@ mod experimental {
pub(crate) transactions: sov_state::StateMap<Bytes32, RawEvmTransaction>,

#[state]
pub(crate) receipts: sov_state::StateMap<Bytes32, TransactionReceipt>,
pub(crate) receipts:
sov_state::StateMap<ethereum_types::H256, TransactionReceipt, sov_state::BcsCodec>,
}

impl<C: sov_modules_api::Context> sov_modules_api::Module for Evm<C> {
Expand Down
4 changes: 2 additions & 2 deletions module-system/module-implementations/sov-evm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl<C: sov_modules_api::Context> Evm<C> {
working_set: &mut WorkingSet<C::Storage>,
) -> RpcResult<Option<TransactionReceipt>> {
info!("evm module: eth_getTransactionReceipt");
let receipt = self.receipts.get(&hash.into(), working_set);
Ok(receipt.map(|r| r.into()))
let receipt = self.receipts.get(&hash, working_set);
Ok(receipt)
}

//https://github.com/paradigmxyz/reth/blob/f577e147807a783438a3f16aad968b4396274483/crates/rpc/rpc/src/eth/api/transactions.rs#L502
Expand Down
64 changes: 0 additions & 64 deletions module-system/module-implementations/sov-evm/src/receipt.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ where
#[address]
pub address: C::Address,

#[state(codec_builder = "sov_state::codec::BorshCodec::default")]
#[state(codec_builder = "sov_state::BorshCodec::default")]
pub state_in_first_struct_1: StateMap<C::PublicKey, u32>,
}

Expand Down
1 change: 1 addition & 0 deletions module-system/sov-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resolver = "2"
[dependencies]
anyhow = { workspace = true }
borsh = { workspace = true }
bcs = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
sov-rollup-interface = { path = "../../rollup-interface", version = "0.1" }
Expand Down
35 changes: 35 additions & 0 deletions module-system/sov-state/src/bcs_codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::codec::{StateKeyCodec, StateValueCodec};

/// A [`StateCodec`] that uses [`bcs`] for all keys and values.
#[derive(Debug, Default, PartialEq, Eq, Clone, borsh::BorshDeserialize, borsh::BorshSerialize)]
pub struct BcsCodec;

impl<K> StateKeyCodec<K> for BcsCodec
where
K: serde::Serialize + for<'de> serde::Deserialize<'de>,
{
type KeyError = bcs::Error;

fn encode_key(&self, key: &K) -> Vec<u8> {
bcs::to_bytes(key).expect("Failed to serialize key")
}

fn try_decode_key(&self, bytes: &[u8]) -> Result<K, Self::KeyError> {
bcs::from_bytes(bytes)
}
}

impl<V> StateValueCodec<V> for BcsCodec
where
V: serde::Serialize + for<'de> serde::Deserialize<'de>,
{
type ValueError = bcs::Error;

fn encode_value(&self, value: &V) -> Vec<u8> {
bcs::to_bytes(value).expect("Failed to serialize value")
}

fn try_decode_value(&self, bytes: &[u8]) -> Result<V, Self::ValueError> {
bcs::from_bytes(bytes)
}
}
35 changes: 35 additions & 0 deletions module-system/sov-state/src/borsh_codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::codec::{StateKeyCodec, StateValueCodec};

/// A [`StateCodec`] that uses [`borsh`] for all keys and values.
#[derive(Debug, Default, PartialEq, Eq, Clone, borsh::BorshDeserialize, borsh::BorshSerialize)]
pub struct BorshCodec;

impl<K> StateKeyCodec<K> for BorshCodec
where
K: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type KeyError = std::io::Error;

fn encode_key(&self, key: &K) -> Vec<u8> {
key.try_to_vec().expect("Failed to serialize key")
}

fn try_decode_key(&self, bytes: &[u8]) -> Result<K, Self::KeyError> {
K::try_from_slice(bytes)
}
}

impl<V> StateValueCodec<V> for BorshCodec
where
V: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type ValueError = std::io::Error;

fn encode_value(&self, value: &V) -> Vec<u8> {
value.try_to_vec().expect("Failed to serialize value")
}

fn try_decode_value(&self, bytes: &[u8]) -> Result<V, Self::ValueError> {
V::try_from_slice(bytes)
}
}
34 changes: 0 additions & 34 deletions module-system/sov-state/src/codec.rs
neysofu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,6 @@ pub trait StateCodec<K, V>: StateKeyCodec<K> + StateValueCodec<V> {}

impl<K, V, C> StateCodec<K, V> for C where C: StateKeyCodec<K> + StateValueCodec<V> {}

/// A [`StateCodec`] that uses [`borsh`] for all keys and values.
#[derive(Debug, Default, PartialEq, Eq, Clone, borsh::BorshDeserialize, borsh::BorshSerialize)]
pub struct BorshCodec;

impl<K> StateKeyCodec<K> for BorshCodec
where
K: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type KeyError = std::io::Error;

fn encode_key(&self, key: &K) -> Vec<u8> {
key.try_to_vec().expect("Failed to serialize key")
}

fn try_decode_key(&self, bytes: &[u8]) -> Result<K, Self::KeyError> {
K::try_from_slice(bytes)
}
}

impl<V> StateValueCodec<V> for BorshCodec
where
V: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type ValueError = std::io::Error;

fn encode_value(&self, value: &V) -> Vec<u8> {
value.try_to_vec().expect("Failed to serialize value")
}

fn try_decode_value(&self, bytes: &[u8]) -> Result<V, Self::ValueError> {
V::try_from_slice(bytes)
}
}

/// A [`StateCodec`] that uses two different codecs under the hood, one for keys
/// and one for values.
#[derive(Default, Debug, Clone)]
Expand Down
4 changes: 4 additions & 0 deletions module-system/sov-state/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod bcs_codec;
mod borsh_codec;
pub mod codec;
mod internal_cache;
mod map;
Expand Down Expand Up @@ -27,6 +29,8 @@ mod state_tests;
use std::fmt::Display;
use std::str;

pub use bcs_codec::BcsCodec;
pub use borsh_codec::BorshCodec;
pub use map::StateMap;
#[cfg(feature = "native")]
pub use prover_storage::{delete_storage, ProverStorage};
Expand Down
3 changes: 2 additions & 1 deletion module-system/sov-state/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::marker::PhantomData;

use thiserror::Error;

use crate::codec::{BorshCodec, StateCodec};
use crate::borsh_codec::BorshCodec;
use crate::codec::StateCodec;
use crate::storage::StorageKey;
use crate::{Prefix, Storage, WorkingSet};

Expand Down
3 changes: 2 additions & 1 deletion module-system/sov-state/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::marker::PhantomData;
use borsh::{BorshDeserialize, BorshSerialize};
use thiserror::Error;

use crate::codec::{BorshCodec, StateKeyCodec, StateValueCodec};
use crate::borsh_codec::BorshCodec;
use crate::codec::{StateKeyCodec, StateValueCodec};
use crate::{Prefix, Storage, WorkingSet};

/// Container for a single value.
Expand Down