-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Deprecate ValidateUnsigned and prevent duplicate heartbeats #3975
Changes from all commits
ba9906a
6246374
11dbcdb
ad09c88
1f2f22f
96a3131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ use sr_staking_primitives::{ | |
offence::{ReportOffence, Offence, Kind}, | ||
}; | ||
use support::{ | ||
decl_module, decl_event, decl_storage, print, ensure, Parameter, debug | ||
decl_module, decl_event, decl_storage, print, Parameter, debug | ||
}; | ||
use system::ensure_none; | ||
use system::offchain::SubmitUnsignedTransaction; | ||
|
@@ -243,24 +243,20 @@ decl_module! { | |
fn heartbeat( | ||
origin, | ||
heartbeat: Heartbeat<T::BlockNumber>, | ||
signature: <T::AuthorityId as RuntimeAppPublic>::Signature | ||
// since signature verification is done in `validate_unsigned` | ||
// we can skip doing it here again. | ||
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature | ||
) { | ||
ensure_none(origin)?; | ||
|
||
let current_session = <session::Module<T>>::current_index(); | ||
ensure!(current_session == heartbeat.session_index, "Outdated heartbeat received."); | ||
let exists = <ReceivedHeartbeats>::exists( | ||
¤t_session, | ||
&heartbeat.authority_index | ||
); | ||
let keys = Keys::<T>::get(); | ||
let maybe_public = keys.get(heartbeat.authority_index as usize); | ||
if let (false, Some(public)) = (exists, maybe_public) { | ||
let signature_valid = heartbeat.using_encoded(|encoded_heartbeat| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this gone? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's done in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's the main difference between The reason why we have pre-dispatch failing transactions in the pool is asynchrony between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! :) |
||
public.verify(&encoded_heartbeat, &signature) | ||
}); | ||
ensure!(signature_valid, "Invalid heartbeat signature."); | ||
|
||
let public = keys.get(heartbeat.authority_index as usize); | ||
if let (false, Some(public)) = (exists, public) { | ||
Self::deposit_event(Event::<T>::HeartbeatReceived(public.clone())); | ||
|
||
let network_state = heartbeat.network_state.encode(); | ||
|
@@ -545,6 +541,7 @@ impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> { | |
} | ||
} | ||
|
||
#[allow(deprecated)] | ||
impl<T: Trait> support::unsigned::ValidateUnsigned for Module<T> { | ||
type Call = Call<T>; | ||
|
||
|
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.
How should we use
SignedExtensions
for this? You mean we should create an extra signed extension for each unsigned transaction and add this to the signed extensions used by theUncheckedExtrinsic
?This would mean that we accept any unsigned transaction, when we forget to add the appropriate signed extension?
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.
Yes. It's a fair point that we should only allow unsigned transactions that are coming from one of the whitelisted modules (currently the
validate_unsigned
function ofSignedExtension
will just allow everything). But it should be easy to do a wrapper type that simply disallows a transaction if it's unsigned and none of the modules returns non-defaultTransactionValidity
.Actually it might be best to just return
InvalidTransaction
by default fromvalidate_unsigned
when we get rid ofUnsignedValidator
.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.
Yeah, good ideas :)
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 one of our meta-modules (system etc.) can register a unified
CheckAndHandleUnsigned
signed extension. What this does is it rejects everything except for a handful ones that are explicitly whitelisted. This can be injected into system viatype UnsignedValidatorModules
which would be a tuple of modules that implement some trait (maybe even the currentValidateUnsigned
)This basically reverses the problem Basti said
everything is rejected unless a module explicitly ping system module about it.
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.
Okay what I said ^^ is in the same line of:
i just understood it :D