Skip to content

Commit

Permalink
fix: block eth_sendRawTransaction to fix `eth_getTransactionCount(.…
Browse files Browse the repository at this point in the history
….., "pending")` temporarily
  • Loading branch information
chaoticlonghair authored and Flouse committed Nov 13, 2023
1 parent 083b496 commit 4c3be3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{sync::Arc, time::Duration};

use ckb_types::core::cell::{CellProvider, CellStatus};
use ckb_types::prelude::Entity;
Expand All @@ -13,7 +13,8 @@ use protocol::types::{
MIN_TRANSACTION_GAS_LIMIT, U256,
};
use protocol::{
async_trait, ckb_blake2b_256, codec::ProtocolCodec, lazy::PROTOCOL_VERSION, ProtocolResult,
async_trait, ckb_blake2b_256, codec::ProtocolCodec, lazy::PROTOCOL_VERSION, tokio::time::sleep,
ProtocolResult, MEMPOOL_REFRESH_TIMEOUT,
};

use core_executor::system_contract::DataProvider;
Expand Down Expand Up @@ -315,6 +316,10 @@ impl<Adapter: APIAdapter + 'static> Web3RpcServer for Web3RpcImpl<Adapter> {
.await
.map_err(|e| RpcError::Internal(e.to_string()))?;

// TODO `eth_getTransactionCount(..., "pending")` should be synchronous with
// `eth_sendRawTransaction`. Temporary solution for axonweb3/axon#1544.
sleep(Duration::from_millis(MEMPOOL_REFRESH_TIMEOUT)).await;

Ok(hash)
}

Expand Down
4 changes: 2 additions & 2 deletions core/mempool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use parking_lot::{Mutex, RwLock};

use protocol::tokio::{self, time::sleep};
use protocol::types::{BlockNumber, Bytes, Hash, PackedTxHashes, SignedTransaction, H160, U256};
use protocol::ProtocolResult;
use protocol::{ProtocolResult, MEMPOOL_REFRESH_TIMEOUT};

use crate::tx_wrapper::{PendingQueue, TxPtr, TxWrapper};
use crate::MemPoolError;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl PriorityPool {
}
}

sleep(Duration::from_millis(50)).await;
sleep(Duration::from_millis(MEMPOOL_REFRESH_TIMEOUT)).await;
}
});

Expand Down
2 changes: 2 additions & 0 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub use {
trie,
};

pub const MEMPOOL_REFRESH_TIMEOUT: u64 = 50;

#[derive(Copy, Clone, Debug)]
pub enum ProtocolErrorKind {
// traits
Expand Down

0 comments on commit 4c3be3d

Please sign in to comment.