Skip to content

Commit

Permalink
deps: update substrate to polkadot-v1.7.0 (polkadot-evm#1300)
Browse files Browse the repository at this point in the history
* refactor: improve eth pubsub rpc

* deps: update substrate to polkadot-v1.7.0

* fix integration tests

* update some deps
  • Loading branch information
koushiro authored Feb 23, 2024
1 parent 0ca40f6 commit c5d6daa
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 649 deletions.
1,089 changes: 563 additions & 526 deletions Cargo.lock

Large diffs are not rendered by default.

146 changes: 73 additions & 73 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ where
from_number: NumberFor<B>,
current_number: NumberFor<B>,
},
Error(jsonrpsee::core::Error),
Error(jsonrpsee::types::ErrorObjectOwned),
}

let key = U256::from(index.value());
Expand Down
44 changes: 21 additions & 23 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ use std::{marker::PhantomData, sync::Arc};

use ethereum::TransactionV2 as EthereumTransaction;
use futures::{future, FutureExt as _, StreamExt as _};
use jsonrpsee::{core::traits::IdProvider, server::SubscriptionSink, types::SubscriptionResult};
use jsonrpsee::{core::traits::IdProvider, server::PendingSubscriptionSink};
// Substrate
use sc_client_api::{
backend::{Backend, StorageProvider},
client::BlockchainEvents,
};
use sc_network_sync::SyncingService;
use sc_rpc::SubscriptionTaskExecutor;
use sc_rpc::{
utils::{pipe_from_stream, to_sub_message},
SubscriptionTaskExecutor,
};
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool, TxHash};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -231,14 +234,7 @@ where
C: HeaderBackend<B> + StorageProvider<B, BE>,
BE: Backend<B> + 'static,
{
fn subscribe(
&self,
mut sink: SubscriptionSink,
kind: Kind,
params: Option<Params>,
) -> SubscriptionResult {
sink.accept()?;

fn subscribe(&self, pending: PendingSubscriptionSink, kind: Kind, params: Option<Params>) {
let filtered_params = match params {
Some(Params::Logs(filter)) => FilteredParams::new(Some(filter)),
_ => FilteredParams::default(),
Expand All @@ -255,29 +251,33 @@ where
Kind::NewHeads => {
let stream = block_notification_stream
.filter_map(move |notification| pubsub.notify_header(notification));
sink.pipe_from_stream(stream).await;
pipe_from_stream(pending, stream).await
}
Kind::Logs => {
let stream = block_notification_stream
.filter_map(move |notification| {
pubsub.notify_logs(notification, &filtered_params)
})
.flat_map(futures::stream::iter);
sink.pipe_from_stream(stream).await;
pipe_from_stream(pending, stream).await
}
Kind::NewPendingTransactions => {
let pool = pubsub.pool.clone();
let stream = pool
.import_notification_stream()
.filter_map(move |hash| pubsub.pending_transaction(&hash));
sink.pipe_from_stream(stream).await;
pipe_from_stream(pending, stream).await;
}
Kind::Syncing => {
let Ok(sink) = pending.accept().await else {
return;
};
// On connection subscriber expects a value.
// Because import notifications are only emitted when the node is synced or
// in case of reorg, the first event is emitted right away.
let sync_status = pubsub.syncing_status().await;
let _ = sink.send(&PubSubResult::SyncingStatus(sync_status));
let syncing_status = pubsub.syncing_status().await;
let msg = to_sub_message(&sink, &PubSubResult::SyncingStatus(syncing_status));
let _ = sink.send(msg).await;

// When the node is not under a major syncing (i.e. from genesis), react
// normally to import notifications.
Expand All @@ -288,8 +288,10 @@ where
while (stream.next().await).is_some() {
let syncing_status = pubsub.sync.is_major_syncing();
if syncing_status != last_syncing_status {
let sync_status = pubsub.syncing_status().await;
let _ = sink.send(&PubSubResult::SyncingStatus(sync_status));
let syncing_status = pubsub.syncing_status().await;
let msg =
to_sub_message(&sink, &PubSubResult::SyncingStatus(syncing_status));
let _ = sink.send(msg).await;
}
last_syncing_status = syncing_status;
}
Expand All @@ -298,11 +300,7 @@ where
}
.boxed();

self.executor.spawn(
"frontier-rpc-subscription",
Some("rpc"),
fut.map(drop).boxed(),
);
Ok(())
self.executor
.spawn("frontier-rpc-subscription", Some("rpc"), fut);
}
}
31 changes: 18 additions & 13 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,29 @@ pub mod frontier_backend_client {
}
}

pub fn err<T: ToString>(code: i32, message: T, data: Option<&[u8]>) -> jsonrpsee::core::Error {
jsonrpsee::core::Error::Call(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorObject::owned(
code,
message.to_string(),
data.map(|bytes| {
jsonrpsee::core::to_json_raw_value(&format!("0x{}", hex::encode(bytes)))
.expect("fail to serialize data")
}),
),
))
pub fn err<T: ToString>(
code: i32,
message: T,
data: Option<&[u8]>,
) -> jsonrpsee::types::error::ErrorObjectOwned {
jsonrpsee::types::error::ErrorObject::owned(
code,
message.to_string(),
data.map(|bytes| {
jsonrpsee::core::to_json_raw_value(&format!("0x{}", hex::encode(bytes)))
.expect("fail to serialize data")
}),
)
}

pub fn internal_err<T: ToString>(message: T) -> jsonrpsee::core::Error {
pub fn internal_err<T: ToString>(message: T) -> jsonrpsee::types::error::ErrorObjectOwned {
err(jsonrpsee::types::error::INTERNAL_ERROR_CODE, message, None)
}

pub fn internal_err_with_data<T: ToString>(message: T, data: &[u8]) -> jsonrpsee::core::Error {
pub fn internal_err_with_data<T: ToString>(
message: T,
data: &[u8],
) -> jsonrpsee::types::error::ErrorObjectOwned {
err(
jsonrpsee::types::error::INTERNAL_ERROR_CODE,
message,
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use ethereum::TransactionV2 as EthereumTransaction;
use ethereum_types::{H160, H256};
use jsonrpsee::core::Error;
use jsonrpsee::types::ErrorObjectOwned;
// Substrate
use sp_core::hashing::keccak_256;
// Frontier
Expand All @@ -35,7 +35,7 @@ pub trait EthSigner: Send + Sync {
&self,
message: TransactionMessage,
address: &H160,
) -> Result<EthereumTransaction, Error>;
) -> Result<EthereumTransaction, ErrorObjectOwned>;
}

pub struct EthDevSigner {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl EthSigner for EthDevSigner {
&self,
message: TransactionMessage,
address: &H160,
) -> Result<EthereumTransaction, Error> {
) -> Result<EthereumTransaction, ErrorObjectOwned> {
let mut transaction = None;

for secret in &self.keys {
Expand Down
1 change: 0 additions & 1 deletion frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type MaxHolds = ConstU32<5>;
type MaxFreezes = ConstU32<1>;
}

Expand Down
1 change: 0 additions & 1 deletion frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
}

Expand Down
1 change: 0 additions & 1 deletion frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
}

Expand Down
6 changes: 3 additions & 3 deletions precompiles/src/solidity/codec/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_support::{ensure, traits::ConstU32};
use sp_core::H256;
use sp_std::vec::Vec;
use sp_weights::Weight;
use xcm::latest::{Junction, Junctions, MultiLocation, NetworkId};
use xcm::latest::{Junction, Junctions, Location, NetworkId};

use crate::solidity::{
codec::{bytes::*, Codec, Reader, Writer},
Expand Down Expand Up @@ -358,12 +358,12 @@ impl Codec for Junctions {
}

// Cannot used derive macro since it is a foreign struct.
impl Codec for MultiLocation {
impl Codec for Location {
fn read(reader: &mut Reader) -> MayRevert<Self> {
let (parents, interior) = reader
.read()
.map_in_tuple_to_field(&["parents", "interior"])?;
Ok(MultiLocation { parents, interior })
Ok(Location { parents, interior })
}

fn write(writer: &mut Writer, value: Self) {
Expand Down
1 change: 0 additions & 1 deletion precompiles/tests-external/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl pallet_balances::Config for Runtime {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
}

Expand Down
2 changes: 1 addition & 1 deletion template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use prometheus_endpoint::Registry;
use sc_client_api::{Backend, BlockBackend};
use sc_consensus::BasicQueue;
use sc_executor::NativeExecutionDispatch;
use sc_network_sync::warp::{WarpSyncParams, WarpSyncProvider};
use sc_network_sync::strategy::warp::{WarpSyncParams, WarpSyncProvider};
use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
Expand Down
1 change: 0 additions & 1 deletion template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ impl pallet_balances::Config for Runtime {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type MaxHolds = ConstU32<5>;
type MaxFreezes = ConstU32<1>;
}

Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,6 @@ describeWithFrontier("Frontier RPC (RPC execution)", (context) => {
input: "0x12345678",
},
]);
expect((result as any).error.message).to.match(/^Ambiguous value for `data` and `input`/);
expect(result.error.data).to.match(/^Ambiguous value for `data` and `input`/);
});
});

0 comments on commit c5d6daa

Please sign in to comment.