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

Equivocation misbehaviour reports#2923

Closed
marcio-diaz wants to merge 28 commits intomasterfrom
marcio/simple-misbehaviour-reports
Closed

Equivocation misbehaviour reports#2923
marcio-diaz wants to merge 28 commits intomasterfrom
marcio/simple-misbehaviour-reports

Conversation

@marcio-diaz
Copy link
Contributor

@marcio-diaz marcio-diaz commented Jun 21, 2019

Replaces #2800, fixing conflicts, adding tests and improving code.

TODO: Test that equivocations really do lead to reports in GRANDPA (no idea how to check it in a meaningful way since equivocations come from grandpa repo), Babe stuff (maybe follow up).

@marcio-diaz marcio-diaz added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jun 21, 2019
@marcio-diaz marcio-diaz force-pushed the marcio/simple-misbehaviour-reports branch from 4a15d16 to a406442 Compare June 24, 2019 09:13
@marcio-diaz marcio-diaz force-pushed the marcio/simple-misbehaviour-reports branch from a406442 to 5c2a007 Compare June 24, 2019 10:33
@marcio-diaz marcio-diaz requested a review from rphmeier June 24, 2019 10:49
@marcio-diaz marcio-diaz added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. A4-gotissues labels Jun 24, 2019
@marcio-diaz marcio-diaz requested a review from andresilva June 24, 2019 12:34
Copy link
Contributor

@Demi-Marie Demi-Marie left a comment

Choose a reason for hiding this comment

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

18446744073709551615 needs to be replaced with u64::MAX everywhere. Also, FIXMEs and issues need to be written for where slashing has not yet been implemented.

@@ -19,21 +19,19 @@
//! This implements the digests for AuRa, to allow the private
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I almost made the same change for BABE in my on-chain randomness work, but reverted it.

fn construct_equivocation_report_call(
_proof: AuraEquivocationProof<<Block as BlockT>::Header,sr25519::Signature>
) -> Vec<u8> {
vec![]
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering why this was empty, then realized that this is the test runtime.

fn construct_equivocation_report_call(
_proof: AuraEquivocationProof<<Block as BlockT>::Header,ed25519::Signature>
) -> Vec<u8> {
vec![]
Copy link
Contributor

Choose a reason for hiding this comment

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

This, however, should not be empty. It seems to me that a proof is definitely required. Even if it is not, there should be documentation explaining why the empty vector is a valid choice.

_origin,
_equivocation_proof: AuraEquivocationProof<T::Header, T::Signature>
) {
// This is the place where we will slash.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs an issue filed for it, along with a FIXME and the issue number in the code.

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: std::u64::MAX,

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: u64::MAX,

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: u64::MAX,

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: u64::MAX,

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: u64::MAX,

priority: 10,
requires: vec![],
provides: vec![],
longevity: 18446744073709551615,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
longevity: 18446744073709551615,
longevity: u64::MAX,

@rphmeier rphmeier added A5-grumble and removed A0-please_review Pull request needs code review. labels Jun 26, 2019
}

#[derive(Debug, Clone, Encode, Decode, PartialEq)]
pub struct GrandpaEquivocationProof<E> {
Copy link
Contributor

Choose a reason for hiding this comment

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

docs on public items (including their public fields)

pub equivocation: E,
}

pub fn localized_payload<E: Encode>(round: u64, set_id: u64, message: &E) -> Vec<u8> {
Copy link
Contributor

@rphmeier rphmeier Jun 26, 2019

Choose a reason for hiding this comment

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

Docs on public items.

Also, if we're going to use this elsewhere, we should consider returning an impl Encode instead of a Vec<u8>. Then you can do e.g.

let payload = localized_payload(...);
let my_packet = (some_other_data, payload).encode();

/// Get slot author for given block along with authorities.
pub fn slot_author<AuthorityId>(slot_num: u64, authorities: &[AuthorityId]) -> Option<&AuthorityId>
{
if authorities.is_empty() { return None }
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why you need these extra checks when the function returns an Option and get does it for you.

why not just

pub fn slot_author<AuthorityId>(slot_num: u64, authorities: &[AuthorityId]) -> Option<&AuthorityId> {
   authorities.get(slot_num as usize)
}

{
if authorities.is_empty() { return None }

let idx = slot_num % (authorities.len() as u64);
Copy link
Contributor

Choose a reason for hiding this comment

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

why wrap-around slot number here to fit in the authorities slice?

@andresilva
Copy link
Contributor

andresilva commented Jul 10, 2019

Is this good to be reviewed? Could you merge/rebase master if that's the case? :)

edit: Actually I think a rebase would be the best.

}

#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone)]
pub struct AuraEquivocationProof<H, S> {
Copy link
Contributor

Choose a reason for hiding this comment

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

docs on public items

let slot = maybe_slot1.expect("OK by previous line; qed");

// FIX: What if there is a different set of authorities?
let authorities = <Module<T>>::authorities();
Copy link
Contributor

Choose a reason for hiding this comment

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

right, this is the hardest part of slashing. we probably will need the historical session trie to also store some key mapped to Vec<T::Keys>. Consensus engines that need access to the entire authorities list will have to accept a proof of that branch as well.

@Demi-Marie
Copy link
Contributor

@marcio-diaz Can you rebase this?

@marcio-diaz
Copy link
Contributor Author

Closing in favor of #3225 (between other follow ups)

@marcio-diaz marcio-diaz deleted the marcio/simple-misbehaviour-reports branch July 29, 2019 13:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants