Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 5c8aa7e

Browse files
authored
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>
1 parent 59ca8df commit 5c8aa7e

File tree

10 files changed

+39
-41
lines changed

10 files changed

+39
-41
lines changed

Cargo.lock

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ members = [
4242
"client/informant",
4343
"client/keystore",
4444
"client/merkle-mountain-range",
45+
"client/merkle-mountain-range/rpc",
4546
"client/network",
4647
"client/network-gossip",
4748
"client/network/bitswap",
@@ -108,7 +109,6 @@ members = [
108109
"frame/lottery",
109110
"frame/membership",
110111
"frame/merkle-mountain-range",
111-
"frame/merkle-mountain-range/rpc",
112112
"frame/multisig",
113113
"frame/nicks",
114114
"frame/node-authorization",

bin/node/rpc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ targets = ["x86_64-unknown-linux-gnu"]
1414
[dependencies]
1515
jsonrpsee = { version = "0.15.1", features = ["server"] }
1616
node-primitives = { version = "2.0.0", path = "../primitives" }
17-
pallet-mmr-rpc = { version = "3.0.0", path = "../../../frame/merkle-mountain-range/rpc/" }
1817
pallet-transaction-payment-rpc = { version = "4.0.0-dev", path = "../../../frame/transaction-payment/rpc/" }
18+
mmr-rpc = { version = "4.0.0-dev", path = "../../../client/merkle-mountain-range/rpc/" }
1919
sc-chain-spec = { version = "4.0.0-dev", path = "../../../client/chain-spec" }
2020
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
2121
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }

bin/node/rpc/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ where
108108
+ Send
109109
+ 'static,
110110
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
111-
C::Api: pallet_mmr_rpc::MmrRuntimeApi<
112-
Block,
113-
<Block as sp_runtime::traits::Block>::Hash,
114-
BlockNumber,
115-
>,
111+
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
116112
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
117113
C::Api: BabeApi<Block>,
118114
C::Api: BlockBuilder<Block>,
@@ -121,7 +117,7 @@ where
121117
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
122118
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
123119
{
124-
use pallet_mmr_rpc::{Mmr, MmrApiServer};
120+
use mmr_rpc::{Mmr, MmrApiServer};
125121
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
126122
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
127123
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};

frame/merkle-mountain-range/rpc/Cargo.toml client/merkle-mountain-range/rpc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "pallet-mmr-rpc"
3-
version = "3.0.0"
2+
name = "mmr-rpc"
3+
version = "4.0.0-dev"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66
license = "Apache-2.0"

client/merkle-mountain-range/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod test_utils;
4444
use std::{marker::PhantomData, sync::Arc};
4545

4646
use futures::StreamExt;
47-
use log::{debug, error, trace, warn};
47+
use log::{error, trace, warn};
4848

4949
use sc_client_api::{Backend, BlockchainEvents, FinalityNotifications};
5050
use sc_offchain::OffchainDb;
@@ -110,13 +110,16 @@ where
110110
}
111111
},
112112
_ => {
113-
trace!(target: LOG_TARGET, "Finality notification: {:?}", notification);
114-
debug!(target: LOG_TARGET, "Waiting for MMR pallet to become available ...");
113+
trace!(
114+
target: LOG_TARGET,
115+
"Waiting for MMR pallet to become available... (best finalized {:?})",
116+
notification.header.number()
117+
);
115118
},
116119
}
117120
}
118121

119-
warn!(
122+
error!(
120123
target: LOG_TARGET,
121124
"Finality notifications stream closed unexpectedly. \
122125
Couldn't build the canonicalization engine",

client/merkle-mountain-range/src/offchain_mmr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where
6666
match self.client.header_metadata(hash) {
6767
Ok(header) => Some(header),
6868
_ => {
69-
error!(
69+
debug!(
7070
target: LOG_TARGET,
7171
"Block {} not found. Couldn't {} associated branch.", hash, action
7272
);
@@ -168,7 +168,7 @@ where
168168
canon_key
169169
);
170170
} else {
171-
error!(
171+
debug!(
172172
target: LOG_TARGET,
173173
"Couldn't canonicalize elem at pos {} using temp key {:?}", pos, temp_key
174174
);

frame/merkle-mountain-range/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@
5757
#![cfg_attr(not(feature = "std"), no_std)]
5858

5959
use frame_support::{log, weights::Weight};
60+
use sp_mmr_primitives::utils;
6061
use sp_runtime::{
6162
traits::{self, One, Saturating},
6263
SaturatedConversion,
6364
};
65+
use sp_std::prelude::*;
66+
67+
pub use pallet::*;
68+
pub use sp_mmr_primitives::{
69+
self as primitives, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex,
70+
};
6471

6572
#[cfg(feature = "runtime-benchmarks")]
6673
mod benchmarking;
@@ -71,13 +78,6 @@ mod mock;
7178
#[cfg(test)]
7279
mod tests;
7380

74-
pub use pallet::*;
75-
use sp_mmr_primitives::utils;
76-
pub use sp_mmr_primitives::{
77-
self as primitives, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex,
78-
};
79-
use sp_std::prelude::*;
80-
8181
/// The most common use case for MMRs is to store historical block hashes,
8282
/// so that any point in time in the future we can receive a proof about some past
8383
/// blocks without using excessive on-chain storage.

frame/merkle-mountain-range/src/mock.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use sp_runtime::{
2929
testing::Header,
3030
traits::{BlakeTwo256, IdentityLookup, Keccak256},
3131
};
32-
use sp_std::prelude::*;
3332

3433
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
3534
type Block = frame_system::mocking::MockBlock<Test>;

0 commit comments

Comments
 (0)