Skip to content

Commit

Permalink
EVM remove receipt type (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad authored and preston-evans98 committed Sep 14, 2023
1 parent d6e3bf5 commit 08fa36f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 99 deletions.
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 @@ -65,6 +65,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 @@ -75,7 +76,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 @@ -46,24 +47,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
13 changes: 6 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,11 @@ 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::codec::BcsCodec,
>,
}

impl<C: sov_modules_api::Context> sov_modules_api::Module for Evm<C> {
Expand Down
5 changes: 3 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,9 @@ 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.as_fixed_bytes(), 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.

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/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)
}
}
20 changes: 20 additions & 0 deletions module-system/sov-state/src/codec/bcs_codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::codec::StateValueCodec;

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

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

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

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

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

impl<V> StateValueCodec<V> for BorshCodec
where
V: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type Error = 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::Error> {
V::try_from_slice(bytes)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! Serialization and deserialization -related logic.
mod bcs_codec;
mod borsh_codec;

pub use bcs_codec::BcsCodec;
pub use borsh_codec::BorshCodec;

/// A trait for types that can serialize and deserialize values for storage
/// access.
pub trait StateValueCodec<V> {
Expand Down Expand Up @@ -34,22 +40,3 @@ pub trait StateValueCodec<V> {
.unwrap()
}
}

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

impl<V> StateValueCodec<V> for BorshCodec
where
V: borsh::BorshSerialize + borsh::BorshDeserialize,
{
type Error = 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::Error> {
V::try_from_slice(bytes)
}
}

0 comments on commit 08fa36f

Please sign in to comment.