Skip to content

Commit

Permalink
[pallet-revive] revive json-rpc small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Oct 31, 2024
1 parent 5f782a4 commit f1e5537
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion substrate/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ pub use sc_transaction_pool::TransactionPoolOptions;
pub use sc_transaction_pool_api::{error::IntoPoolError, InPoolTransaction, TransactionPool};
#[doc(hidden)]
pub use std::{ops::Deref, result::Result, sync::Arc};
pub use task_manager::{SpawnTaskHandle, Task, TaskManager, TaskRegistry, DEFAULT_GROUP_NAME};
pub use task_manager::{
SpawnEssentialTaskHandle, SpawnTaskHandle, Task, TaskManager, TaskRegistry, DEFAULT_GROUP_NAME,
};
use tokio::runtime::Handle;

const DEFAULT_PROTOCOL_ID: &str = "sup";
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/revive/rpc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ pub fn run(cmd: CliCommand) -> anyhow::Result<()> {
let tokio_handle = tokio_runtime.handle();
let signals = tokio_runtime.block_on(async { Signals::capture() })?;
let mut task_manager = TaskManager::new(tokio_handle.clone(), prometheus_registry)?;
let spawn_handle = task_manager.spawn_handle();
let essential_spawn_handle = task_manager.spawn_essential_handle();

let gen_rpc_module = || {
let signals = tokio_runtime.block_on(async { Signals::capture() })?;
let fut = Client::from_url(&node_rpc_url, &spawn_handle).fuse();
let fut = Client::from_url(&node_rpc_url, &essential_spawn_handle).fuse();
pin_mut!(fut);

match tokio_handle.block_on(signals.try_until_signal(fut)) {
Expand All @@ -125,7 +125,7 @@ pub fn run(cmd: CliCommand) -> anyhow::Result<()> {

// Prometheus metrics.
if let Some(PrometheusConfig { port, registry }) = prometheus_config.clone() {
spawn_handle.spawn(
task_manager.spawn_handle().spawn(
"prometheus-endpoint",
None,
prometheus_endpoint::init_prometheus(port, registry).map(drop),
Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use pallet_revive::{
},
EthContractResult,
};
use sc_service::SpawnTaskHandle;
use sp_runtime::traits::{BlakeTwo256, Hash};
use sp_weights::Weight;
use std::{
Expand Down Expand Up @@ -165,7 +164,7 @@ impl From<ClientError> for ErrorObjectOwned {

/// The number of recent blocks maintained by the cache.
/// For each block in the cache, we also store the EVM transaction receipts.
pub const CACHE_SIZE: usize = 10;
pub const CACHE_SIZE: usize = 256;

impl<const N: usize> BlockCache<N> {
fn latest_block(&self) -> Option<&Arc<SubstrateBlock>> {
Expand Down Expand Up @@ -344,7 +343,10 @@ async fn extract_block_timestamp(block: &SubstrateBlock) -> Option<u64> {
impl Client {
/// Create a new client instance.
/// The client will subscribe to new blocks and maintain a cache of [`CACHE_SIZE`] blocks.
pub async fn from_url(url: &str, spawn_handle: &SpawnTaskHandle) -> Result<Self, ClientError> {
pub async fn from_url(
url: &str,
spawn_handle: &sc_service::SpawnEssentialTaskHandle,
) -> Result<Self, ClientError> {
log::info!(target: LOG_TARGET, "Connecting to node at: {url} ...");
let inner: Arc<ClientInner> = Arc::new(ClientInner::from_url(url).await?);
log::info!(target: LOG_TARGET, "Connected to node at: {url}");
Expand Down

0 comments on commit f1e5537

Please sign in to comment.