-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): add protocol config rpc endpoint (#3919)
Add `EXPERIMENTAL_protocol_config` rpc endpoint that returns the protocol config given some block, since protocol config can change after genesis due to protocol upgrades. This will allow users to get the up-to-date protocol-level configs. Fixes #3918. Test plan ---------- `test_protocol_config_rpc`
- Loading branch information
1 parent
4ea58d9
commit 0aa0823
Showing
17 changed files
with
347 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use crate::types::blocks::BlockReference; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RpcProtocolConfigRequest { | ||
#[serde(flatten)] | ||
pub block_reference: BlockReference, | ||
} | ||
|
||
impl RpcProtocolConfigRequest { | ||
pub fn parse( | ||
value: Option<Value>, | ||
) -> Result<RpcProtocolConfigRequest, crate::errors::RpcParseError> { | ||
crate::utils::parse_params::<BlockReference>(value) | ||
.map(|block_reference| RpcProtocolConfigRequest { block_reference }) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RpcProtocolConfigResponse { | ||
#[serde(flatten)] | ||
pub config_view: near_chain_configs::ProtocolConfigView, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum RpcProtocolConfigError { | ||
#[error("Block has never been observed: {0}")] | ||
UnknownBlock(String), | ||
#[error("The node reached its limits. Try again later. More details: {0}")] | ||
InternalError(String), | ||
// NOTE: Currently, the underlying errors are too broad, and while we tried to handle | ||
// expected cases, we cannot statically guarantee that no other errors will be returned | ||
// in the future. | ||
// TODO #3851: Remove this variant once we can exhaustively match all the underlying errors | ||
#[error("It is a bug if you receive this error type, please, report this incident: https://github.com/near/nearcore/issues/new/choose. Details: {0}")] | ||
Unreachable(String), | ||
} | ||
|
||
impl From<near_client_primitives::types::GetProtocolConfigError> for RpcProtocolConfigError { | ||
fn from(error: near_client_primitives::types::GetProtocolConfigError) -> Self { | ||
match error { | ||
near_client_primitives::types::GetProtocolConfigError::UnknownBlock(s) => { | ||
Self::UnknownBlock(s) | ||
} | ||
near_client_primitives::types::GetProtocolConfigError::IOError(s) => { | ||
Self::InternalError(s) | ||
} | ||
near_client_primitives::types::GetProtocolConfigError::Unreachable(s) => { | ||
near_metrics::inc_counter_vec( | ||
&crate::metrics::RPC_UNREACHABLE_ERROR_COUNT, | ||
&["RpcProtocolConfigError", &s], | ||
); | ||
Self::Unreachable(s) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<actix::MailboxError> for RpcProtocolConfigError { | ||
fn from(error: actix::MailboxError) -> Self { | ||
Self::InternalError(error.to_string()) | ||
} | ||
} | ||
|
||
impl From<RpcProtocolConfigError> for crate::errors::RpcError { | ||
fn from(error: RpcProtocolConfigError) -> Self { | ||
let error_data = match error { | ||
RpcProtocolConfigError::UnknownBlock(hash) => { | ||
Some(Value::String(format!("Block Not Found: {}", hash))) | ||
} | ||
RpcProtocolConfigError::Unreachable(s) => Some(Value::String(s)), | ||
RpcProtocolConfigError::InternalError(_) => Some(Value::String(error.to_string())), | ||
}; | ||
|
||
Self::new(-32_000, "Server error".to_string(), error_data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod blocks; | ||
pub mod chunks; | ||
pub mod config; | ||
pub mod receipts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.