-
Notifications
You must be signed in to change notification settings - Fork 2.6k
grandpa-rpc: use FinalityProofProvider to check finality for rpc #6215
Changes from 31 commits
4eab2a4
5953803
0fc9cd5
06b04f5
34522c1
9fe866e
8591352
80f6c53
136c257
eab8404
d3e8d30
801b3e6
56f32a3
c1e50d5
3b5a3c6
a892236
2db4ba0
3c543e6
0e89cee
7b1ed8f
ca1e2a8
9a3b43f
f294b47
6c7adb1
026f542
cf2375d
bdf931a
9d43c11
354c589
c353f81
de666ff
ff6d612
21afc7d
37b9507
1212782
6c79a1e
c284665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,7 @@ sp-block-builder = { version = "2.0.0-rc6", path = "../../../primitives/block-bu | |
sp-blockchain = { version = "2.0.0-rc6", path = "../../../primitives/blockchain" } | ||
sp-consensus = { version = "0.8.0-rc6", path = "../../../primitives/consensus/common" } | ||
sp-consensus-babe = { version = "0.8.0-rc6", path = "../../../primitives/consensus/babe" } | ||
sp-runtime = { version = "2.0.0-rc6", path = "../../../primitives/runtime" } | ||
sp-state-machine = { version = "0.8.0-rc6", path = "../../../primitives/state-machine" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one isn't needed anymore. |
||
sp-transaction-pool = { version = "2.0.0-rc6", path = "../../../primitives/transaction-pool" } | ||
substrate-frame-rpc-system = { version = "2.0.0-rc6", path = "../../../utils/frame/rpc/system" } |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,7 +37,9 @@ use node_primitives::{Block, BlockNumber, AccountId, Index, Balance, Hash}; | |||||||||
use sc_consensus_babe::{Config, Epoch}; | ||||||||||
use sc_consensus_babe_rpc::BabeRpcHandler; | ||||||||||
use sc_consensus_epochs::SharedEpochChanges; | ||||||||||
use sc_finality_grandpa::{SharedVoterState, SharedAuthoritySet, GrandpaJustificationStream}; | ||||||||||
use sc_finality_grandpa::{ | ||||||||||
SharedVoterState, SharedAuthoritySet, FinalityProofProvider, GrandpaJustificationStream | ||||||||||
}; | ||||||||||
use sc_finality_grandpa_rpc::GrandpaRpcHandler; | ||||||||||
use sc_keystore::KeyStorePtr; | ||||||||||
pub use sc_rpc_api::DenyUnsafe; | ||||||||||
|
@@ -47,6 +49,7 @@ use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; | |||||||||
use sp_consensus::SelectChain; | ||||||||||
use sp_consensus_babe::BabeApi; | ||||||||||
use sp_transaction_pool::TransactionPool; | ||||||||||
use sp_runtime::traits::BlakeTwo256; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed if we do the change I suggested below. |
||||||||||
|
||||||||||
/// Light client extra dependencies. | ||||||||||
pub struct LightDeps<C, F, P> { | ||||||||||
|
@@ -71,7 +74,7 @@ pub struct BabeDeps { | |||||||||
} | ||||||||||
|
||||||||||
/// Extra dependencies for GRANDPA | ||||||||||
pub struct GrandpaDeps { | ||||||||||
pub struct GrandpaDeps<B> { | ||||||||||
/// Voting round info. | ||||||||||
pub shared_voter_state: SharedVoterState, | ||||||||||
/// Authority set info. | ||||||||||
|
@@ -80,10 +83,12 @@ pub struct GrandpaDeps { | |||||||||
pub justification_stream: GrandpaJustificationStream<Block>, | ||||||||||
/// Subscription manager to keep track of pubsub subscribers. | ||||||||||
pub subscriptions: SubscriptionManager, | ||||||||||
/// Finality proof provider. | ||||||||||
pub finality_provider: Arc<FinalityProofProvider<B, Block>>, | ||||||||||
} | ||||||||||
|
||||||||||
/// Full client dependencies. | ||||||||||
pub struct FullDeps<C, P, SC> { | ||||||||||
pub struct FullDeps<C, P, SC, B> { | ||||||||||
/// The client instance to use. | ||||||||||
pub client: Arc<C>, | ||||||||||
/// Transaction pool instance. | ||||||||||
|
@@ -95,15 +100,15 @@ pub struct FullDeps<C, P, SC> { | |||||||||
/// BABE specific dependencies. | ||||||||||
pub babe: BabeDeps, | ||||||||||
/// GRANDPA specific dependencies. | ||||||||||
pub grandpa: GrandpaDeps, | ||||||||||
pub grandpa: GrandpaDeps<B>, | ||||||||||
} | ||||||||||
|
||||||||||
/// A IO handler that uses all Full RPC extensions. | ||||||||||
pub type IoHandler = jsonrpc_core::IoHandler<sc_rpc::Metadata>; | ||||||||||
|
||||||||||
/// Instantiate all Full RPC extensions. | ||||||||||
pub fn create_full<C, P, SC>( | ||||||||||
deps: FullDeps<C, P, SC>, | ||||||||||
pub fn create_full<C, P, SC, B>( | ||||||||||
deps: FullDeps<C, P, SC, B>, | ||||||||||
) -> jsonrpc_core::IoHandler<sc_rpc_api::Metadata> where | ||||||||||
C: ProvideRuntimeApi<Block>, | ||||||||||
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError> + 'static, | ||||||||||
|
@@ -115,6 +120,8 @@ pub fn create_full<C, P, SC>( | |||||||||
C::Api: BlockBuilder<Block>, | ||||||||||
P: TransactionPool + 'static, | ||||||||||
SC: SelectChain<Block> +'static, | ||||||||||
B: Send + Sync + 'static + sc_client_api::Backend<Block>, | ||||||||||
<B as sc_client_api::Backend<Block>>::State: sp_state_machine::Backend<BlakeTwo256>, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the reason we need to specify the state backend here is because |
||||||||||
{ | ||||||||||
use substrate_frame_rpc_system::{FullSystem, SystemApi}; | ||||||||||
use pallet_contracts_rpc::{Contracts, ContractsApi}; | ||||||||||
|
@@ -140,6 +147,7 @@ pub fn create_full<C, P, SC>( | |||||||||
shared_authority_set, | ||||||||||
justification_stream, | ||||||||||
subscriptions, | ||||||||||
finality_provider, | ||||||||||
} = grandpa; | ||||||||||
|
||||||||||
io.extend_with( | ||||||||||
|
@@ -173,6 +181,7 @@ pub fn create_full<C, P, SC>( | |||||||||
shared_voter_state, | ||||||||||
justification_stream, | ||||||||||
subscriptions, | ||||||||||
finality_provider, | ||||||||||
) | ||||||||||
) | ||||||||||
); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2020 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use serde::{Serialize, Deserialize}; | ||
|
||
use sc_finality_grandpa::FinalityProofProvider; | ||
use sp_runtime::traits::{Block as BlockT, NumberFor}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct EncodedFinalityProofs(pub sp_core::Bytes); | ||
|
||
/// Local trait mainly to allow mocking in tests. | ||
pub trait RpcFinalityProofProvider<Block: BlockT> { | ||
/// Return finality proofs for the given authorities set id, if it is provided, otherwise the | ||
/// current one will be used. | ||
fn rpc_prove_finality( | ||
&self, | ||
begin: Block::Hash, | ||
end: Block::Hash, | ||
authorities_set_id: u64, | ||
) -> Result<Option<EncodedFinalityProofs>, sp_blockchain::Error>; | ||
} | ||
|
||
impl<B, Block> RpcFinalityProofProvider<Block> for FinalityProofProvider<B, Block> | ||
where | ||
Block: BlockT, | ||
NumberFor<Block>: finality_grandpa::BlockNumberOps, | ||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static, | ||
{ | ||
fn rpc_prove_finality( | ||
&self, | ||
begin: Block::Hash, | ||
end: Block::Hash, | ||
authorities_set_id: u64, | ||
) -> Result<Option<EncodedFinalityProofs>, sp_blockchain::Error> { | ||
self.prove_finality(begin, end, authorities_set_id) | ||
.map(|x| x.map(|y| EncodedFinalityProofs(y.into()))) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.