Skip to content

Conversation

@DocteurPing
Copy link
Contributor

This PR introduces the initial phase of our slashing mechanism. Currently, if a collator fails to produce a block during an entire session, it is removed from the candidate pool. Collators can rejoin the pool after being kicked out by following the usual process of becoming a collator. This is merely a warning for now; no token slashing is being implemented yet.

talhadaar and others added 30 commits August 28, 2024 16:16
…igate prepare_delayed_reward from running twice at genesis
@DocteurPing DocteurPing marked this pull request as ready for review January 6, 2025 10:22
@DocteurPing DocteurPing requested a review from sfffaaa January 6, 2025 10:22
}

fn on_finalize(_n: BlockNumberFor<T>) {
fn on_finalize(n: BlockNumberFor<T>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about the spec but not about the implementation. If the sudo user triggers the force_new_round, should we punish the collators who are not generating the block? Or should we waive it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I kept it like this because it was better for testing purposes. That’s the only way I found to test it in an environment like Chopsticks. Another reason I kept it is that forcing a new round shouldn’t happen frequently. The only scenario I can think of is when we change the token economy. If we really want to force a new round in production we can always deactivate slashing. We can discuss that with the product team.

Copy link
Contributor

@sfffaaa sfffaaa Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, let us discuss with them

If we really want to force a new round in production we can always deactivate slashing

That's a good workaround!

return;
}

if Self::remove_candidate(&collator, &state).is_err() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean this collator will lose all delegator's staking? If that is the case, this punishment is also severe. Let us check with our business team about the spec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let’s check with them. Another workaround would be to remove the candidate from the pool and add a new field to the Candidate object that indicates whether the candidate can be selected. After calling an extrinsic, this candidate could change this value to allow it to be selected again.

log::info!("V11 Migrating Done.");
}

if onchain_storage_version < StorageVersion::new(Versions::V12 as u16) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think whether we should remove the above migration logic? Or is keeping them better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you implying that since the migration has already occurred and the round is now mandatory, it might be reasonable to eliminate it? I think that would make sense but let’s discuss this with @talhadaar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you are right. I'm thinking because only Krest has the old version; however, we shouldn't upgrade it to the lastest version directly. Therefore, it's possible to remove it. Let us discuss it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this entails just yet, i'll have a closer look at this PR.

@peaq-coolify
Copy link

peaq-coolify bot commented Jun 19, 2025

The preview deployment is ready. 🟢

Open Preview | Open Build Logs

Last updated at: 2025-08-20 14:41:18 CET

@DocteurPing DocteurPing requested a review from Copilot June 25, 2025 09:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the initial phase of the slashing mechanism for collators in the parachain staking module. Key changes include enabling/disabling slashing via genesis and callable extrinsics, adding new weight functions and types to support unjailing and collateral management, and updating migration and test logic to reflect these changes.

  • Introduces the slashing_enabled flag in genesis and runtime.
  • Adds new extrinsics: set_slashing_enabled, set_min_unjailed_duration, and unjail_candidate.
  • Updates tests, weights, migrations, and chain specs to integrate the new slashing behavior.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
precompiles/parachain-staking/src/mock.rs Adds slashing_enabled field for genesis configuration.
pallets/parachain-staking/src/weights.rs Provides weight functions for the new slashing-related extrinsics.
pallets/parachain-staking/src/weightinfo.rs Declares new weight functions used for slashing and unjailing.
pallets/parachain-staking/src/types.rs Introduces the JailingStatus enum for capturing candidate status.
pallets/parachain-staking/src/tests.rs Updates tests to account for slashing_enabled events and behavior.
pallets/parachain-staking/src/mock.rs Updates genesis config to include slashing_enabled.
pallets/parachain-staking/src/migrations.rs Adjusts migration logic and storage version to enable slashing.
pallets/parachain-staking/src/lib.rs Implements new storage items, events, and extrinsics for slashing.
node/src/parachain/*_chain_spec.rs Updates chain specs to set slashing_enabled true in genesis config.
Comments suppressed due to low confidence (3)

pallets/parachain-staking/src/lib.rs:564

  • [nitpick] Consider adding a brief comment here to explain why slashing is triggered only on the first block of each round; this will aid future maintainers in understanding the design decision.
			if SlashingEnabled::<T>::get() && current_round.first == n {

pallets/parachain-staking/src/lib.rs:2066

  • Verify that using T::MaxTopCandidates::get() as the parameter for the unjail_candidate weight function accurately reflects the actual computational cost; consider revisiting the weight parameters if future changes affect performance.
		))]

pallets/parachain-staking/src/migrations.rs:118

  • Consider explicitly using the V12 constant instead of Versions::default() when updating the storage version to improve clarity in the migration process.
				);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants