-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
1ccf396
to
93b70bf
Compare
93b70bf
to
c0dfff5
Compare
997bb08
to
0a03d71
Compare
0a03d71
to
01a38e3
Compare
} | ||
|
||
/// Check if the header is an equivocation and returns the proof in that case. | ||
/// Assumes all the headers in the same slot are signed by the same Signer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can make this assumption for BABE (remember that uncles are allowed). I'm also not sure it holds for Aura in the presence of forks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm checking the public key now, it's executed after verification.
slot_header_map = slot_header_map.split_off(&(slot - MAX_SLOT_CAPACITY)); | ||
} | ||
|
||
backend.insert_aux( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can come up with a simple way to avoid dumping everything to disk. If we store the different elements under different keys (e.g. SLOT_HEADER_MAP_KEY
+ index
), then we'd only need to delete one key and add a new one as we import new blocks. Not sure this is strictly needed for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by adding SLOT_HEADER_MAP_KEY
+ index
as keys.
core/consensus/aura/src/lib.rs
Outdated
Ok(CheckedHeader::Checked(header, digest_item)) | ||
match check_equivocation(client, slot_num, header.clone()) { | ||
Ok(Some(equivocation_proof)) => { | ||
// TODO: dispatch report here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add a reporting module as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A runtime module? I think we'll hold that off for another PR. srml-aura
should get a function for checking equivocation, given two headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code needs to be either removed or finished, and a potential denial of service attack from many equivocations needs to be addressed.
core/consensus/aura/src/lib.rs
Outdated
match check_equivocation::<_, _, <P as Pair>::Public>(client, slot_num, header.clone(), public.clone()) { | ||
Ok(Some(equivocation_proof)) => { | ||
// TODO: dispatch report here. | ||
Err(format!("Slot author is equivocating with headers {:?} and {:?}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should log this with severity at least warn
, as it should not happen normally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it as info
.
let mut v = load_decode::<_, Vec<(H, P)>>(backend.clone(), &key[..])? | ||
.unwrap_or_else(Vec::new); | ||
|
||
for (prev_header, prev_signer) in v.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is O(n)
, and is called O(n)
times, so it is O(n^2)
(where n
is the number of messages from any particular validator).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is O(validators)
now, worst case scenario, since we store only one message by validated signer.
} | ||
} | ||
|
||
// match slot_header_map.entry(slot) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented-out code should either be removed or uncommented.
// }; | ||
|
||
if slot % PRUNING_BOUND == 0 { | ||
// slot_header_map = slot_header_map.split_off(&(slot - MAX_SLOT_CAPACITY)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
097392b
to
502d47e
Compare
502d47e
to
5ee6d79
Compare
I addressed the previous issues and it's ready for another round of review. |
21c00a9
to
eb6d098
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The algorithm for finding equivocations is rather subtle. Would adding some comments be a good idea?
core/consensus/aura/src/lib.rs
Outdated
public.clone() | ||
) { | ||
Ok(Some(equivocation_proof)) => { | ||
info!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the code duplication between this and the following statement be removed?
core/consensus/aura/src/lib.rs
Outdated
Ok(CheckedHeader::Checked(header, digest_item)) | ||
}, | ||
Err(e) => { | ||
println!("{}", e.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be logged as error!
, not written to stdout
.
snd_header: header.clone(), | ||
})); | ||
} else { | ||
return Ok(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be correct, since at least the first equivocation will be reported. That said, I suspect a comment explaining why would be justified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments, hope it helps.
@demimarie-parity happy with this now? |
@@ -1103,4 +1163,40 @@ mod tests { | |||
Keyring::Charlie.into() | |||
]); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray newline
core/consensus/aura/src/lib.rs
Outdated
|
||
pub use aura_primitives::*; | ||
pub use consensus_common::{SyncOracle, ExtraVerification}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray newline
} | ||
} | ||
|
||
#[derive(Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docs on public item
} | ||
|
||
impl<H> EquivocationProof<H> { | ||
pub fn slot(&self) -> u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs
where | ||
H: Header, | ||
C: AuxStore, | ||
P: Encode + Decode + PartialEq + std::fmt::Debug, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug
bound seems unnecessary.
core/primitives/src/crypto.rs
Outdated
@@ -290,7 +290,7 @@ impl<T: AsMut<[u8]> + AsRef<[u8]> + Default + Derive> Ss58Codec for T { | |||
#[cfg(feature = "std")] | |||
pub trait Pair: Sized + 'static { | |||
/// TThe type which is used to encode a public key. | |||
type Public; | |||
type Public: Clone + std::fmt::Debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these are necessary.
8da401f
to
a821f9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underflow
Co-Authored-By: André Silva <andre.beat@gmail.com>
Co-Authored-By: André Silva <andre.beat@gmail.com>
* init store for slots * fix: add check_equivocation to Aura/Babe * fix tests * fix: add pruning bound Co-Authored-By: André Silva <andre.beat@gmail.com> * use saturating_sub
Starting PR for issue paritytech/polkadot-sdk#70.
slot -> vec![(header, signer)]
.MAX_SLOT_CAPACITY
slots.PRUNING_BOUND % slot_now == 0
, withPRUNING_BOUND
>MAX_SLOT_CAPACITY
. Note: I don't know if the pruning may be too slow.O(validators)
in the worst scenario, since we save only one header by signer, i.e. duplicates are ignored and different headers generate equivocations.