Skip to content

Commit

Permalink
used constants in rpc_client
Browse files Browse the repository at this point in the history
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
  • Loading branch information
iulianbarbu committed Sep 9, 2024
1 parent 03f26fc commit a0fb74d
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,23 @@ use sp_version::RuntimeVersion;

use crate::{
constants::{
BABE_API_CURRENT_EPOCH, CHAIN_GET_HEAD, PARACHAIN_HOST_ON_CHAIN_VOTES,
PARACHAIN_HOST_PVFS_REQUIRE_PRECHECK, PARACHAIN_HOST_SUBMIT_PVF_CHECK_STATEMENT,
PARACHAIN_HOST_VALIATOR_GROUPS,
AUTHORITY_DISCOVERY_API_AUTHORITIES, BABE_API_CURRENT_EPOCH, CHAIN_GET_BLOCKHASH,
CHAIN_GET_FINALIZED_HEAD, CHAIN_GET_HEAD, CHAIN_GET_HEADER,
PARACHAIN_HOST_ASYNC_BACKING_PARAMS, PARACHAIN_HOST_AVAILABILITY_CORES,
PARACHAIN_HOST_CANDIDATES_PENDING_AVAILABILITY, PARACHAIN_HOST_CANDIDATE_EVENTS,
PARACHAIN_HOST_CHECK_VALIDATION_OUTPUTS, PARACHAIN_HOST_CLAIM_QUEUE,
PARACHAIN_HOST_DISABLED_VALIDATORS, PARACHAIN_HOST_DISPUTES, PARACHAIN_HOST_DMQ_CONTENTS,
PARACHAIN_HOST_INBOUND_HRMP_CHANNELS_CONTENTS, PARACHAIN_HOST_KEY_OWNERSHIP_PROOF,
PARACHAIN_HOST_MINIMUM_BACKING_VOTES, PARACHAIN_HOST_NODE_FEATURES,
PARACHAIN_HOST_ON_CHAIN_VOTES, PARACHAIN_HOST_PARA_BACKING_STATE,
PARACHAIN_HOST_PERSISTED_ASSUMED_VALIDATION_DATA, PARACHAIN_HOST_PERSISTED_VALIDATION_DATA,
PARACHAIN_HOST_PVFS_REQUIRE_PRECHECK, PARACHAIN_HOST_SESSION_EXECUTOR_PARAMS,
PARACHAIN_HOST_SESSION_INDEX_FOR_CHILD, PARACHAIN_HOST_SESSION_INFO,
PARACHAIN_HOST_STAGING_APPROVAL_VOTING_PARAMS, PARACHAIN_HOST_SUBMIT_PVF_CHECK_STATEMENT,
PARACHAIN_HOST_SUBMIT_REPORT_DISPUTE_LOST, PARACHAIN_HOST_UNAPPLIED_SLASHES,
PARACHAIN_HOST_VALIATOR_GROUPS, PARACHAIN_HOST_VALIDATION_CODE,
PARACHAIN_HOST_VALIDATION_CODE_BY_HASH, PARACHAIN_HOST_VALIDATION_CODE_HASH,
PARACHAIN_HOST_VALIDATORS, STATE_GET_RUNTIME_VERSION,
},
light_client_worker::{build_smoldot_client, LightClientRpcWorker},
metrics::{BlockchainRpcMetrics, DURATION_LABEL_NAME},
Expand Down Expand Up @@ -325,7 +339,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<Vec<CandidateEvent>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_candidate_events", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_CANDIDATE_EVENTS, at, None::<()>)
.await
}

Expand All @@ -337,7 +351,7 @@ impl RelayChainRpcClient {
outputs: CandidateCommitments,
) -> Result<bool, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_check_validation_outputs",
PARACHAIN_HOST_CHECK_VALIDATION_OUTPUTS,
at,
Some((para_id, outputs)),
)
Expand All @@ -354,7 +368,7 @@ impl RelayChainRpcClient {
expected_hash: RelayHash,
) -> Result<Option<(PersistedValidationData, ValidationCodeHash)>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_persisted_assumed_validation_data",
PARACHAIN_HOST_PERSISTED_ASSUMED_VALIDATION_DATA,
at,
Some((para_id, expected_hash)),
)
Expand All @@ -363,7 +377,7 @@ impl RelayChainRpcClient {

/// Get hash of last finalized block.
pub async fn chain_get_finalized_head(&self) -> Result<RelayHash, RelayChainError> {
self.request("chain_getFinalizedHead", rpc_params![]).await
self.request(CHAIN_GET_FINALIZED_HEAD, rpc_params![]).await
}

/// Get hash of n-th block.
Expand All @@ -372,7 +386,7 @@ impl RelayChainRpcClient {
block_number: Option<BlockNumber>,
) -> Result<Option<RelayHash>, RelayChainError> {
let params = rpc_params![block_number];
self.request("chain_getBlockHash", params).await
self.request(CHAIN_GET_BLOCKHASH, params).await
}

/// Yields the persisted validation data for the given `ParaId` along with an assumption that
Expand All @@ -387,7 +401,7 @@ impl RelayChainRpcClient {
occupied_core_assumption: OccupiedCoreAssumption,
) -> Result<Option<PersistedValidationData>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_persisted_validation_data",
PARACHAIN_HOST_PERSISTED_VALIDATION_DATA,
at,
Some((para_id, occupied_core_assumption)),
)
Expand All @@ -401,7 +415,7 @@ impl RelayChainRpcClient {
validation_code_hash: ValidationCodeHash,
) -> Result<Option<ValidationCode>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_validation_code_by_hash",
PARACHAIN_HOST_VALIDATION_CODE_BY_HASH,
at,
Some(validation_code_hash),
)
Expand All @@ -414,23 +428,22 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<Vec<CoreState<RelayHash, BlockNumber>>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_availability_cores", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_AVAILABILITY_CORES, at, None::<()>)
.await
}

/// Get runtime version
pub async fn runtime_version(&self, at: RelayHash) -> Result<RuntimeVersion, RelayChainError> {
let params = rpc_params![at];
self.request("state_getRuntimeVersion", params).await
self.request(STATE_GET_RUNTIME_VERSION, params).await
}

/// Returns all onchain disputes.
pub async fn parachain_host_disputes(
&self,
at: RelayHash,
) -> Result<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_disputes", at, None::<()>)
.await
self.call_remote_runtime_function(PARACHAIN_HOST_DISPUTES, at, None::<()>).await
}

/// Returns a list of validators that lost a past session dispute and need to be slashed.
Expand All @@ -440,7 +453,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_unapplied_slashes", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_UNAPPLIED_SLASHES, at, None::<()>)
.await
}

Expand All @@ -453,7 +466,7 @@ impl RelayChainRpcClient {
validator_id: ValidatorId,
) -> Result<Option<slashing::OpaqueKeyOwnershipProof>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_key_ownership_proof",
PARACHAIN_HOST_KEY_OWNERSHIP_PROOF,
at,
Some(validator_id),
)
Expand All @@ -471,7 +484,7 @@ impl RelayChainRpcClient {
key_ownership_proof: slashing::OpaqueKeyOwnershipProof,
) -> Result<Option<()>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_submit_report_dispute_lost",
PARACHAIN_HOST_SUBMIT_REPORT_DISPUTE_LOST,
at,
Some((dispute_proof, key_ownership_proof)),
)
Expand All @@ -482,7 +495,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<Vec<sp_authority_discovery::AuthorityId>, RelayChainError> {
self.call_remote_runtime_function("AuthorityDiscoveryApi_authorities", at, None::<()>)
self.call_remote_runtime_function(AUTHORITY_DISCOVERY_API_AUTHORITIES, at, None::<()>)
.await
}

Expand All @@ -497,7 +510,7 @@ impl RelayChainRpcClient {
occupied_core_assumption: OccupiedCoreAssumption,
) -> Result<Option<ValidationCode>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_validation_code",
PARACHAIN_HOST_VALIDATION_CODE,
at,
Some((para_id, occupied_core_assumption)),
)
Expand All @@ -513,7 +526,7 @@ impl RelayChainRpcClient {
occupied_core_assumption: OccupiedCoreAssumption,
) -> Result<Option<ValidationCodeHash>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_validation_code_hash",
PARACHAIN_HOST_VALIDATION_CODE_HASH,
at,
Some((para_id, occupied_core_assumption)),
)
Expand All @@ -526,7 +539,7 @@ impl RelayChainRpcClient {
at: RelayHash,
index: SessionIndex,
) -> Result<Option<SessionInfo>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_session_info", at, Some(index))
self.call_remote_runtime_function(PARACHAIN_HOST_SESSION_INFO, at, Some(index))
.await
}

Expand All @@ -537,7 +550,7 @@ impl RelayChainRpcClient {
session_index: SessionIndex,
) -> Result<Option<ExecutorParams>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_session_executor_params",
PARACHAIN_HOST_SESSION_EXECUTOR_PARAMS,
at,
Some(session_index),
)
Expand All @@ -550,7 +563,7 @@ impl RelayChainRpcClient {
hash: Option<RelayHash>,
) -> Result<Option<RelayHeader>, RelayChainError> {
let params = rpc_params![hash];
self.request("chain_getHeader", params).await
self.request(CHAIN_GET_HEADER, params).await
}

/// Get the receipt of a candidate pending availability. This returns `Some` for any paras
Expand All @@ -561,7 +574,7 @@ impl RelayChainRpcClient {
para_id: ParaId,
) -> Result<Option<CommittedCandidateReceipt>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_candidate_pending_availability",
PARACHAIN_HOST_CANDIDATES_PENDING_AVAILABILITY,
at,
Some(para_id),
)
Expand All @@ -575,7 +588,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<SessionIndex, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_session_index_for_child", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_SESSION_INDEX_FOR_CHILD, at, None::<()>)
.await
}

Expand All @@ -584,7 +597,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<Vec<ValidatorId>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_validators", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_VALIDATORS, at, None::<()>)
.await
}

Expand All @@ -596,7 +609,7 @@ impl RelayChainRpcClient {
at: RelayHash,
) -> Result<BTreeMap<ParaId, Vec<InboundHrmpMessage>>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_inbound_hrmp_channels_contents",
PARACHAIN_HOST_INBOUND_HRMP_CHANNELS_CONTENTS,
at,
Some(para_id),
)
Expand All @@ -609,7 +622,7 @@ impl RelayChainRpcClient {
para_id: ParaId,
at: RelayHash,
) -> Result<Vec<InboundDownwardMessage>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_dmq_contents", at, Some(para_id))
self.call_remote_runtime_function(PARACHAIN_HOST_DMQ_CONTENTS, at, Some(para_id))
.await
}

Expand All @@ -619,23 +632,23 @@ impl RelayChainRpcClient {
at: RelayHash,
_session_index: SessionIndex,
) -> Result<u32, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_minimum_backing_votes", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_MINIMUM_BACKING_VOTES, at, None::<()>)
.await
}

pub async fn parachain_host_node_features(
&self,
at: RelayHash,
) -> Result<NodeFeatures, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_node_features", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_NODE_FEATURES, at, None::<()>)
.await
}

pub async fn parachain_host_disabled_validators(
&self,
at: RelayHash,
) -> Result<Vec<ValidatorIndex>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_disabled_validators", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_DISABLED_VALIDATORS, at, None::<()>)
.await
}

Expand All @@ -644,7 +657,7 @@ impl RelayChainRpcClient {
&self,
at: RelayHash,
) -> Result<AsyncBackingParams, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_async_backing_params", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_ASYNC_BACKING_PARAMS, at, None::<()>)
.await
}

Expand All @@ -655,7 +668,7 @@ impl RelayChainRpcClient {
_session_index: SessionIndex,
) -> Result<ApprovalVotingParams, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_staging_approval_voting_params",
PARACHAIN_HOST_STAGING_APPROVAL_VOTING_PARAMS,
at,
None::<()>,
)
Expand All @@ -667,15 +680,15 @@ impl RelayChainRpcClient {
at: RelayHash,
para_id: ParaId,
) -> Result<Option<BackingState>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_para_backing_state", at, Some(para_id))
self.call_remote_runtime_function(PARACHAIN_HOST_PARA_BACKING_STATE, at, Some(para_id))
.await
}

pub async fn parachain_host_claim_queue(
&self,
at: RelayHash,
) -> Result<BTreeMap<CoreIndex, VecDeque<ParaId>>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_claim_queue", at, None::<()>)
self.call_remote_runtime_function(PARACHAIN_HOST_CLAIM_QUEUE, at, None::<()>)
.await
}

Expand All @@ -686,7 +699,7 @@ impl RelayChainRpcClient {
para_id: ParaId,
) -> Result<Vec<CommittedCandidateReceipt>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_candidates_pending_availability",
PARACHAIN_HOST_CANDIDATES_PENDING_AVAILABILITY,
at,
Some(para_id),
)
Expand All @@ -700,7 +713,7 @@ impl RelayChainRpcClient {
occupied_core_assumption: OccupiedCoreAssumption,
) -> Result<Option<ValidationCodeHash>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_validation_code_hash",
PARACHAIN_HOST_VALIDATION_CODE_HASH,
at,
Some((para_id, occupied_core_assumption)),
)
Expand Down

0 comments on commit a0fb74d

Please sign in to comment.