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

polkompanion 6667: past session slashing #2160

Merged
merged 17 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion client/relay-chain-minimal-node/src/blockchain_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use cumulus_relay_chain_rpc_interface::RelayChainRpcClient;
use futures::{Stream, StreamExt};
use polkadot_core_primitives::{Block, BlockNumber, Hash, Header};
use polkadot_overseer::RuntimeApiSubsystemClient;
use polkadot_primitives::vstaging;
use sc_authority_discovery::{AuthorityDiscovery, Error as AuthorityDiscoveryError};
use sp_api::{ApiError, RuntimeApiInfo};

Expand Down Expand Up @@ -297,7 +298,41 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
)>,
ApiError,
> {
Ok(self.rpc_client.parachain_host_staging_get_disputes(at).await?)
Ok(self.rpc_client.parachain_host_disputes(at).await?)
}

async fn unapplied_slashes(
&self,
at: Hash,
) -> Result<
Vec<(
polkadot_primitives::SessionIndex,
polkadot_primitives::CandidateHash,
vstaging::slashing::PendingSlashes,
)>,
ApiError,
> {
Ok(self.rpc_client.parachain_host_unapplied_slashes(at).await?)
}

async fn key_ownership_proof(
&self,
at: Hash,
validator_id: polkadot_primitives::ValidatorId,
) -> Result<Option<vstaging::slashing::OpaqueKeyOwnershipProof>, ApiError> {
Ok(self.rpc_client.parachain_host_key_ownership_proof(at, validator_id).await?)
}

async fn submit_report_dispute_lost(
&self,
at: Hash,
dispute_proof: vstaging::slashing::DisputeProof,
key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof,
) -> Result<Option<()>, ApiError> {
Ok(self
.rpc_client
.parachain_host_submit_report_dispute_lost(at, dispute_proof, key_ownership_proof)
.await?)
}
}

Expand Down
55 changes: 51 additions & 4 deletions client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_storage::StorageKey;

use cumulus_primitives_core::{
relay_chain::{
BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
vstaging, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo,
Hash as RelayHash, Header as RelayHeader, InboundHrmpMessage, OccupiedCoreAssumption,
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
Expand Down Expand Up @@ -320,15 +320,62 @@ impl RelayChainRpcClient {
}

/// Returns all onchain disputes.
/// This is a staging method! Do not use on production runtimes!
pub async fn parachain_host_staging_get_disputes(
pub async fn parachain_host_disputes(
&self,
at: RelayHash,
) -> Result<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>, RelayChainError> {
self.call_remote_runtime_function("ParachainHost_staging_get_disputes", at, None::<()>)
self.call_remote_runtime_function("ParachainHost_disputes", at, None::<()>)
.await
}

/// Returns a list of validators that lost a past session dispute and need to be slashed.
///
/// This is a staging method! Do not use on production runtimes!
pub async fn parachain_host_unapplied_slashes(
&self,
at: RelayHash,
) -> Result<
Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>,
RelayChainError,
> {
self.call_remote_runtime_function("ParachainHost_unapplied_slashes", at, None::<()>)
.await
}

/// Returns a merkle proof of a validator session key in a past session.
///
/// This is a staging method! Do not use on production runtimes!
pub async fn parachain_host_key_ownership_proof(
&self,
at: RelayHash,
validator_id: ValidatorId,
) -> Result<Option<vstaging::slashing::OpaqueKeyOwnershipProof>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_key_ownership_proof",
at,
Some(validator_id),
)
.await
}

/// Submits an unsigned extrinsic to slash validators who lost a dispute about
/// a candidate of a past session.
///
/// This is a staging method! Do not use on production runtimes!
pub async fn parachain_host_submit_report_dispute_lost(
&self,
at: RelayHash,
dispute_proof: vstaging::slashing::DisputeProof,
key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof,
) -> Result<Option<()>, RelayChainError> {
self.call_remote_runtime_function(
"ParachainHost_submit_report_dispute_lost",
at,
Some((dispute_proof, key_ownership_proof)),
)
.await
}

pub async fn authority_discovery_authorities(
&self,
at: RelayHash,
Expand Down