MMR: move RPC code from frame/ to client/ (#12805)

* mmr: move MMR RPC from frame/ to client/

Signed-off-by: Adrian Catangiu <adrian@parity.io>

* client/mmr: adjust logging levels to avoid spam

* cargo fmt

* remove unused imports

Signed-off-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2022-11-30 10:37:29 +02:00
committed by GitHub
parent 04e883d310
commit 6a5bac18d2
10 changed files with 39 additions and 41 deletions
+17 -17
View File
@@ -4253,6 +4253,22 @@ dependencies = [
"tokio",
]
[[package]]
name = "mmr-rpc"
version = "4.0.0-dev"
dependencies = [
"anyhow",
"jsonrpsee",
"parity-scale-codec",
"serde",
"serde_json",
"sp-api",
"sp-blockchain",
"sp-core",
"sp-mmr-primitives",
"sp-runtime",
]
[[package]]
name = "mockall"
version = "0.11.2"
@@ -4685,8 +4701,8 @@ name = "node-rpc"
version = "3.0.0-dev"
dependencies = [
"jsonrpsee",
"mmr-rpc",
"node-primitives",
"pallet-mmr-rpc",
"pallet-transaction-payment-rpc",
"sc-chain-spec",
"sc-client-api",
@@ -5682,22 +5698,6 @@ dependencies = [
"sp-std",
]
[[package]]
name = "pallet-mmr-rpc"
version = "3.0.0"
dependencies = [
"anyhow",
"jsonrpsee",
"parity-scale-codec",
"serde",
"serde_json",
"sp-api",
"sp-blockchain",
"sp-core",
"sp-mmr-primitives",
"sp-runtime",
]
[[package]]
name = "pallet-multisig"
version = "4.0.0-dev"
+1 -1
View File
@@ -42,6 +42,7 @@ members = [
"client/informant",
"client/keystore",
"client/merkle-mountain-range",
"client/merkle-mountain-range/rpc",
"client/network",
"client/network-gossip",
"client/network/bitswap",
@@ -108,7 +109,6 @@ members = [
"frame/lottery",
"frame/membership",
"frame/merkle-mountain-range",
"frame/merkle-mountain-range/rpc",
"frame/multisig",
"frame/nicks",
"frame/node-authorization",
+1 -1
View File
@@ -14,8 +14,8 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
jsonrpsee = { version = "0.15.1", features = ["server"] }
node-primitives = { version = "2.0.0", path = "../primitives" }
pallet-mmr-rpc = { version = "3.0.0", path = "../../../frame/merkle-mountain-range/rpc/" }
pallet-transaction-payment-rpc = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/rpc/" }
mmr-rpc = { version = "4.0.0-dev", path = "../../../client/merkle-mountain-range/rpc/" }
sc-chain-spec = { version = "4.0.0-dev", path = "../../../client/chain-spec" }
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
+2 -6
View File
@@ -108,11 +108,7 @@ where
+ Send
+ 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_mmr_rpc::MmrRuntimeApi<
Block,
<Block as sp_runtime::traits::Block>::Hash,
BlockNumber,
>,
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
@@ -121,7 +117,7 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use pallet_mmr_rpc::{Mmr, MmrApiServer};
use mmr_rpc::{Mmr, MmrApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};
@@ -1,6 +1,6 @@
[package]
name = "pallet-mmr-rpc"
version = "3.0.0"
name = "mmr-rpc"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
@@ -44,7 +44,7 @@ pub mod test_utils;
use std::{marker::PhantomData, sync::Arc};
use futures::StreamExt;
use log::{debug, error, trace, warn};
use log::{error, trace, warn};
use sc_client_api::{Backend, BlockchainEvents, FinalityNotifications};
use sc_offchain::OffchainDb;
@@ -110,13 +110,16 @@ where
}
},
_ => {
trace!(target: LOG_TARGET, "Finality notification: {:?}", notification);
debug!(target: LOG_TARGET, "Waiting for MMR pallet to become available ...");
trace!(
target: LOG_TARGET,
"Waiting for MMR pallet to become available... (best finalized {:?})",
notification.header.number()
);
},
}
}
warn!(
error!(
target: LOG_TARGET,
"Finality notifications stream closed unexpectedly. \
Couldn't build the canonicalization engine",
@@ -66,7 +66,7 @@ where
match self.client.header_metadata(hash) {
Ok(header) => Some(header),
_ => {
error!(
debug!(
target: LOG_TARGET,
"Block {} not found. Couldn't {} associated branch.", hash, action
);
@@ -168,7 +168,7 @@ where
canon_key
);
} else {
error!(
debug!(
target: LOG_TARGET,
"Couldn't canonicalize elem at pos {} using temp key {:?}", pos, temp_key
);
@@ -57,10 +57,17 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{log, weights::Weight};
use sp_mmr_primitives::utils;
use sp_runtime::{
traits::{self, One, Saturating},
SaturatedConversion,
};
use sp_std::prelude::*;
pub use pallet::*;
pub use sp_mmr_primitives::{
self as primitives, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex,
};
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
@@ -71,13 +78,6 @@ mod mock;
#[cfg(test)]
mod tests;
pub use pallet::*;
use sp_mmr_primitives::utils;
pub use sp_mmr_primitives::{
self as primitives, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex,
};
use sp_std::prelude::*;
/// The most common use case for MMRs is to store historical block hashes,
/// so that any point in time in the future we can receive a proof about some past
/// blocks without using excessive on-chain storage.
@@ -29,7 +29,6 @@ use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup, Keccak256},
};
use sp_std::prelude::*;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;