Skip to content

Commit 6c260cb

Browse files
committed
Remove unnecessary lock around request submission
There is no need to lock the executor to submit request to pool. The submission channel is MPMC queue which handles synchronization internally. There was a non-atomic counter of requests processed, this was fixed in execution.
1 parent def11af commit 6c260cb

File tree

8 files changed

+16
-31
lines changed

8 files changed

+16
-31
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

monad-ethcall/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ alloy-sol-types = { workspace = true }
2020
futures = { workspace = true }
2121
hex = { workspace = true }
2222
serde = { workspace = true, features = ["derive"] }
23-
tokio = { workspace = true }
2423
tracing = { workspace = true }
2524

2625
[build-dependencies]

monad-ethcall/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use monad_chain_config::{
3232
MONAD_TESTNET2_CHAIN_ID, MONAD_TESTNET_CHAIN_ID,
3333
};
3434
use serde::{Deserialize, Serialize};
35-
use tokio::sync::Mutex;
3635
use tracing::{info, warn};
3736

3837
#[allow(dead_code, non_camel_case_types, non_upper_case_globals)]
@@ -191,7 +190,7 @@ pub async fn eth_call(
191190
sender: Address,
192191
block_number: u64,
193192
block_id: Option<[u8; 32]>,
194-
eth_call_executor: Arc<Mutex<EthCallExecutor>>,
193+
eth_call_executor: Arc<EthCallExecutor>,
195194
state_override_set: &StateOverrideSet,
196195
tracer: MonadTracer,
197196
gas_specified: bool,
@@ -308,15 +307,11 @@ pub async fn eth_call(
308307
let (send, recv) = channel();
309308
let sender_ctx = Box::new(SenderContext { sender: send });
310309

311-
// hold lock on executor while submitting the task
312-
let executor_lock = eth_call_executor.lock().await;
313-
let eth_call_executor = executor_lock.eth_call_executor;
314-
315310
unsafe {
316311
let sender_ctx_ptr = Box::into_raw(sender_ctx);
317312

318313
bindings::monad_eth_call_executor_submit(
319-
eth_call_executor,
314+
eth_call_executor.eth_call_executor,
320315
chain_config,
321316
rlp_encoded_tx.as_ptr(),
322317
rlp_encoded_tx.len(),
@@ -335,9 +330,6 @@ pub async fn eth_call(
335330
)
336331
};
337332

338-
// lock is dropped after the task has been submitted
339-
drop(executor_lock);
340-
341333
let result = match recv.await {
342334
Ok(r) => r,
343335
Err(e) => {

monad-rpc/src/handlers/eth/call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl CallParams {
618618
#[tracing::instrument(level = "debug")]
619619
async fn prepare_eth_call<T: Triedb + TriedbPath>(
620620
triedb_env: &T,
621-
eth_call_executor: Arc<Mutex<EthCallExecutor>>,
621+
eth_call_executor: Arc<EthCallExecutor>,
622622
chain_id: u64,
623623
eth_call_provider_gas_limit: u64,
624624
mut params: CallParams,
@@ -735,7 +735,7 @@ async fn prepare_eth_call<T: Triedb + TriedbPath>(
735735
#[rpc(method = "eth_call", ignore = "chain_id", ignore = "eth_call_executor")]
736736
pub async fn monad_eth_call<T: Triedb + TriedbPath>(
737737
triedb_env: &T,
738-
eth_call_executor: Arc<Mutex<EthCallExecutor>>,
738+
eth_call_executor: Arc<EthCallExecutor>,
739739
chain_id: u64,
740740
eth_call_provider_gas_limit: u64,
741741
params: MonadEthCallParams,
@@ -771,7 +771,7 @@ pub async fn monad_eth_call<T: Triedb + TriedbPath>(
771771
#[allow(non_snake_case)]
772772
pub async fn monad_debug_traceCall<T: Triedb + TriedbPath>(
773773
triedb_env: &T,
774-
eth_call_executor: Arc<Mutex<EthCallExecutor>>,
774+
eth_call_executor: Arc<EthCallExecutor>,
775775
chain_id: u64,
776776
eth_call_gas_limit: u64,
777777
params: MonadDebugTraceCallParams,

monad-rpc/src/handlers/eth/gas.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use monad_rpc_docs::rpc;
2626
use monad_triedb_utils::triedb_env::{BlockKey, FinalizedBlockKey, ProposedBlockKey, Triedb};
2727
use monad_types::{BlockId, Hash, SeqNum};
2828
use serde::Deserialize;
29-
use tokio::sync::Mutex;
3029
use tracing::trace;
3130

3231
use crate::{
@@ -43,7 +42,7 @@ trait EthCallProvider {
4342
async fn eth_call(
4443
&self,
4544
txn: TxEnvelope,
46-
eth_call_executor: Option<Arc<Mutex<EthCallExecutor>>>,
45+
eth_call_executor: Option<Arc<EthCallExecutor>>,
4746
) -> CallResult;
4847
}
4948

@@ -80,7 +79,7 @@ impl EthCallProvider for GasEstimator {
8079
async fn eth_call(
8180
&self,
8281
txn: TxEnvelope,
83-
eth_call_executor: Option<Arc<Mutex<EthCallExecutor>>>,
82+
eth_call_executor: Option<Arc<EthCallExecutor>>,
8483
) -> CallResult {
8584
let (block_number, block_id) = match self.block_key {
8685
BlockKey::Finalized(FinalizedBlockKey(SeqNum(n))) => (n, None),
@@ -111,7 +110,7 @@ impl EthCallProvider for GasEstimator {
111110

112111
async fn estimate_gas<T: EthCallProvider>(
113112
provider: &T,
114-
eth_call_executor: Option<Arc<Mutex<EthCallExecutor>>>,
113+
eth_call_executor: Option<Arc<EthCallExecutor>>,
115114
call_request: &mut CallRequest,
116115
original_tx_gas: U256,
117116
provider_gas_limit: u64,
@@ -231,7 +230,7 @@ pub struct MonadEthEstimateGasParams {
231230
/// Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.
232231
pub async fn monad_eth_estimateGas<T: Triedb>(
233232
triedb_env: &T,
234-
eth_call_executor: Arc<Mutex<EthCallExecutor>>,
233+
eth_call_executor: Arc<EthCallExecutor>,
235234
chain_id: u64,
236235
provider_gas_limit: u64,
237236
params: MonadEthEstimateGasParams,
@@ -467,11 +466,7 @@ mod tests {
467466
}
468467

469468
impl EthCallProvider for MockGasEstimator {
470-
async fn eth_call(
471-
&self,
472-
txn: TxEnvelope,
473-
_: Option<Arc<Mutex<EthCallExecutor>>>,
474-
) -> CallResult {
469+
async fn eth_call(&self, txn: TxEnvelope, _: Option<Arc<EthCallExecutor>>) -> CallResult {
475470
if txn.gas_limit() >= self.gas_used + self.gas_refund {
476471
CallResult::Success(SuccessCallResult {
477472
gas_used: self.gas_used,

monad-rpc/src/handlers/resources.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use actix_web::{
2323
use monad_archive::prelude::ArchiveReader;
2424
use monad_ethcall::EthCallExecutor;
2525
use monad_triedb_utils::triedb_env::TriedbEnv;
26-
use tokio::sync::{Mutex, Semaphore};
26+
use tokio::sync::Semaphore;
2727
use tracing_actix_web::RootSpanBuilder;
2828

2929
use super::eth::call::EthCallStatsTracker;
@@ -36,7 +36,7 @@ use crate::{
3636
pub struct MonadRpcResources {
3737
pub txpool_bridge_client: EthTxPoolBridgeClient,
3838
pub triedb_reader: Option<TriedbEnv>,
39-
pub eth_call_executor: Option<Arc<Mutex<EthCallExecutor>>>,
39+
pub eth_call_executor: Option<Arc<EthCallExecutor>>,
4040
pub eth_call_executor_fibers: usize,
4141
pub eth_call_stats_tracker: Option<Arc<EthCallStatsTracker>>,
4242
pub archive_reader: Option<ArchiveReader>,
@@ -62,7 +62,7 @@ impl MonadRpcResources {
6262
pub fn new(
6363
txpool_bridge_client: EthTxPoolBridgeClient,
6464
triedb_reader: Option<TriedbEnv>,
65-
eth_call_executor: Option<Arc<Mutex<EthCallExecutor>>>,
65+
eth_call_executor: Option<Arc<EthCallExecutor>>,
6666
eth_call_executor_fibers: usize,
6767
archive_reader: Option<ArchiveReader>,
6868
chain_id: u64,

monad-rpc/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ async fn main() -> std::io::Result<()> {
270270
};
271271

272272
let eth_call_executor = args.triedb_path.clone().as_deref().map(|path| {
273-
Arc::new(tokio::sync::Mutex::new(EthCallExecutor::new(
273+
Arc::new(EthCallExecutor::new(
274274
low_pool_config,
275275
high_pool_config,
276276
args.eth_call_executor_node_lru_max_mem,
277277
path,
278-
)))
278+
))
279279
});
280280

281281
let meter_provider: Option<opentelemetry_sdk::metrics::SdkMeterProvider> =

monad-triedb-utils/src/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn rlp_decode_account(account_rlp: Vec<u8>) -> Option<EthAccount> {
4747
return None;
4848
};
4949

50-
let mut is_delegated = false;
50+
let is_delegated = false;
5151
let code_hash = if buf.is_empty() {
5252
None
5353
} else {

0 commit comments

Comments
 (0)