-
Notifications
You must be signed in to change notification settings - Fork 2.7k
babe: treat epoch_authorship RPC method as unsafe #6069
Changes from 6 commits
285234d
d3730f1
d6b56d7
27bcb4b
78c1b9c
229d32f
a083f24
09ded54
824545b
0ffb971
8298d0a
d515e33
6d8ba08
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 |
|---|---|---|
|
|
@@ -99,30 +99,46 @@ macro_rules! new_full_start { | |
| import_setup = Some((block_import, grandpa_link, babe_link)); | ||
| Ok(import_queue) | ||
| })? | ||
| .with_rpc_extensions(|builder| -> std::result::Result<RpcExtension, _> { | ||
| let babe_link = import_setup.as_ref().map(|s| &s.2) | ||
| .expect("BabeLink is present for full services or set up failed; qed."); | ||
| .with_rpc_extensions(|builder| { | ||
| let grandpa_link = import_setup.as_ref().map(|s| &s.1) | ||
| .expect("GRANDPA LinkHalf is present for full services or set up failed; qed."); | ||
| let shared_authority_set = grandpa_link.shared_authority_set(); | ||
|
|
||
| let shared_authority_set = grandpa_link.shared_authority_set().clone(); | ||
| let shared_voter_state = grandpa::SharedVoterState::empty(); | ||
| let deps = node_rpc::FullDeps { | ||
| client: builder.client().clone(), | ||
| pool: builder.pool(), | ||
| select_chain: builder.select_chain().cloned() | ||
| .expect("SelectChain is present for full services or set up failed; qed."), | ||
| babe: node_rpc::BabeDeps { | ||
| keystore: builder.keystore(), | ||
| babe_config: sc_consensus_babe::BabeLink::config(babe_link).clone(), | ||
| shared_epoch_changes: sc_consensus_babe::BabeLink::epoch_changes(babe_link).clone() | ||
| }, | ||
| grandpa: node_rpc::GrandpaDeps { | ||
| shared_voter_state: shared_voter_state.clone(), | ||
| shared_authority_set: shared_authority_set.clone(), | ||
| }, | ||
| }; | ||
| rpc_setup = Some((shared_voter_state)); | ||
| Ok(node_rpc::create_full(deps)) | ||
|
|
||
| rpc_setup = Some((shared_voter_state.clone())); | ||
|
|
||
| let babe_link = import_setup.as_ref().map(|s| &s.2) | ||
| .expect("BabeLink is present for full services or set up failed; qed."); | ||
|
|
||
| let babe_config = babe_link.config().clone(); | ||
| let shared_epoch_changes = babe_link.epoch_changes().clone(); | ||
|
|
||
| let client = builder.client().clone(); | ||
| let pool = builder.pool().clone(); | ||
| let select_chain = builder.select_chain().cloned() | ||
| .expect("SelectChain is present for full services or set up failed; qed."); | ||
| let keystore = builder.keystore().clone(); | ||
|
|
||
| Ok(move |deny_unsafe| -> RpcExtension { | ||
|
||
| let deps = node_rpc::FullDeps { | ||
| client: client.clone(), | ||
| pool: pool.clone(), | ||
| select_chain: select_chain.clone(), | ||
| deny_unsafe, | ||
| babe: node_rpc::BabeDeps { | ||
| babe_config: babe_config.clone(), | ||
| shared_epoch_changes: shared_epoch_changes.clone(), | ||
| keystore: keystore.clone(), | ||
| }, | ||
| grandpa: node_rpc::GrandpaDeps { | ||
| shared_voter_state: shared_voter_state.clone(), | ||
| shared_authority_set: shared_authority_set.clone(), | ||
| }, | ||
| }; | ||
|
|
||
| node_rpc::create_full(deps) | ||
| }) | ||
| })?; | ||
|
|
||
| (builder, import_setup, inherent_data_providers, rpc_setup) | ||
|
|
@@ -366,21 +382,28 @@ pub fn new_light(config: Configuration) | |
| let provider = client as Arc<dyn StorageAndProofProvider<_, _>>; | ||
| Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _) | ||
| })? | ||
| .with_rpc_extensions(|builder,| -> | ||
| Result<RpcExtension, _> | ||
| { | ||
| .with_rpc_extensions(|builder| { | ||
| let fetcher = builder.fetcher() | ||
| .ok_or_else(|| "Trying to start node RPC without active fetcher")?; | ||
| .ok_or_else(|| "Trying to start node RPC without active fetcher")? | ||
| .clone(); | ||
|
|
||
| let remote_blockchain = builder.remote_backend() | ||
| .ok_or_else(|| "Trying to start node RPC without active remote blockchain")?; | ||
| .ok_or_else(|| "Trying to start node RPC without active remote blockchain")? | ||
| .clone(); | ||
|
|
||
| let client = builder.client().clone(); | ||
| let pool = builder.pool().clone(); | ||
|
|
||
| Ok(move |_| -> RpcExtension { | ||
| let light_deps = node_rpc::LightDeps { | ||
| remote_blockchain: remote_blockchain.clone(), | ||
| fetcher: fetcher.clone(), | ||
| client: client.clone(), | ||
| pool: pool.clone(), | ||
| }; | ||
|
|
||
| let light_deps = node_rpc::LightDeps { | ||
| remote_blockchain, | ||
| fetcher, | ||
| client: builder.client().clone(), | ||
| pool: builder.pool(), | ||
| }; | ||
| Ok(node_rpc::create_light(light_deps)) | ||
| node_rpc::create_light(light_deps) | ||
| }) | ||
| })? | ||
| .build()?; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,37 +25,37 @@ use jsonrpc_core as rpc; | |||||
| /// Signifies whether a potentially unsafe RPC should be denied. | ||||||
| #[derive(Clone, Copy, Debug)] | ||||||
| pub enum DenyUnsafe { | ||||||
| /// Denies only potentially unsafe RPCs. | ||||||
| Yes, | ||||||
| /// Allows calling every RPCs. | ||||||
| No | ||||||
| /// Denies only potentially unsafe RPCs. | ||||||
| Yes, | ||||||
| /// Allows calling every RPCs. | ||||||
|
Contributor
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
|
||||||
| No, | ||||||
| } | ||||||
|
|
||||||
| impl DenyUnsafe { | ||||||
| /// Returns `Ok(())` if the RPCs considered unsafe are safe to call, | ||||||
| /// otherwise returns `Err(UnsafeRpcError)`. | ||||||
| pub fn check_if_safe(self) -> Result<(), UnsafeRpcError> { | ||||||
| match self { | ||||||
| DenyUnsafe::Yes => Err(UnsafeRpcError), | ||||||
| DenyUnsafe::No => Ok(()) | ||||||
| } | ||||||
| } | ||||||
| /// Returns `Ok(())` if the RPCs considered unsafe are safe to call, | ||||||
Demi-Marie marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| /// otherwise returns `Err(UnsafeRpcError)`. | ||||||
| pub fn check_if_safe(self) -> Result<(), UnsafeRpcError> { | ||||||
| match self { | ||||||
| DenyUnsafe::Yes => Err(UnsafeRpcError), | ||||||
| DenyUnsafe::No => Ok(()), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Signifies whether an RPC considered unsafe is denied to be called externally. | ||||||
| #[derive(Debug)] | ||||||
| pub struct UnsafeRpcError; | ||||||
|
|
||||||
| impl std::fmt::Display for UnsafeRpcError { | ||||||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
| write!(f, "RPC call is unsafe to be called externally") | ||||||
| } | ||||||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
| write!(f, "RPC call is unsafe to be called externally") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl std::error::Error for UnsafeRpcError {} | ||||||
|
|
||||||
| impl From<UnsafeRpcError> for rpc::Error { | ||||||
| fn from(_: UnsafeRpcError) -> rpc::Error { | ||||||
| rpc::Error::method_not_found() | ||||||
| } | ||||||
| fn from(_: UnsafeRpcError) -> rpc::Error { | ||||||
| rpc::Error::method_not_found() | ||||||
| } | ||||||
| } | ||||||
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.
We could expect a closure that get's a
RpcDependenciesobject here instead ofBuilder, which would contain all required stuff anddeny_unsafe. That would simplify the code a bit (no extra closure), but would make this method special in a way that it's not invoked right away like otherwith_*methods.