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: Fix Sequencer Nonce #1014

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions full-node/sov-ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ pub use sov_evm::DevSigner;
#[cfg(feature = "experimental")]
pub mod experimental {
use std::array::TryFromSliceError;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use borsh::ser::BorshSerialize;
use demo_stf::runtime::{DefaultContext, Runtime};
use ethers::types::{Bytes, H256};
use jsonrpsee::types::ErrorObjectOwned;
use jsonrpsee::RpcModule;
use reth_primitives::{
Address as RethAddress, TransactionSignedNoHash as RethTransactionSignedNoHash, U128, U256,
};
use reth_primitives::{TransactionSignedNoHash as RethTransactionSignedNoHash, U128, U256};
use reth_rpc_types::{CallRequest, TransactionRequest, TypedTransactionRequest};
use sov_evm::{CallMessage, Evm, RlpEvmTransaction};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
Expand Down Expand Up @@ -58,7 +55,7 @@ pub mod experimental {
}

pub struct Ethereum<C: sov_modules_api::Context, Da: DaService> {
nonces: Mutex<HashMap<RethAddress, u64>>,
nonce: Mutex<u64>,
cemozerr marked this conversation as resolved.
Show resolved Hide resolved
da_service: Da,
batch_builder: Arc<Mutex<EthBatchBuilder>>,
eth_rpc_config: EthRpcConfig,
Expand All @@ -67,14 +64,14 @@ pub mod experimental {

impl<C: sov_modules_api::Context, Da: DaService> Ethereum<C, Da> {
fn new(
nonces: Mutex<HashMap<RethAddress, u64>>,
nonce: Mutex<u64>,
da_service: Da,
batch_builder: Arc<Mutex<EthBatchBuilder>>,
eth_rpc_config: EthRpcConfig,
storage: C::Storage,
) -> Self {
Self {
nonces,
nonce,
da_service,
batch_builder,
eth_rpc_config,
Expand All @@ -91,12 +88,8 @@ pub mod experimental {
let signed_transaction: RethTransactionSignedNoHash = raw_tx.clone().try_into()?;

let tx_hash = signed_transaction.hash();
let sender = signed_transaction
.recover_signer()
.ok_or(sov_evm::EthApiError::InvalidTransactionSignature)?;

let mut nonces = self.nonces.lock().unwrap();
let nonce = *nonces.entry(sender).and_modify(|n| *n += 1).or_insert(0);
let mut nonce = self.nonce.lock().unwrap();

let tx = CallMessage { tx: raw_tx };
let message = <Runtime<DefaultContext, Da::Spec> as EncodeCall<
Expand All @@ -106,8 +99,11 @@ pub mod experimental {
let tx = Transaction::<DefaultContext>::new_signed_tx(
&self.eth_rpc_config.sov_tx_signer_priv_key,
message,
nonce,
*nonce,
);

*nonce += 1;

Ok((H256::from(tx_hash), tx.try_to_vec()?))
}

Expand Down