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

slashing with offchain workers #5773

Closed
wants to merge 10 commits into from
Closed

slashing with offchain workers #5773

wants to merge 10 commits into from

Conversation

drahnr
Copy link
Contributor

@drahnr drahnr commented Apr 24, 2020

Plumbing to allow simplified slashing utilizing data stored by the offchain_index::set API.

Related #3722

@drahnr drahnr added the A3-in_progress Pull request is in progress. No review needed at this stage. label Apr 24, 2020
@drahnr drahnr requested a review from rphmeier April 24, 2020 13:08
@drahnr drahnr self-assigned this Apr 24, 2020
@drahnr drahnr force-pushed the bernhard/slashing-w-ocw branch 3 times, most recently from 31bf932 to 54da597 Compare May 4, 2020 17:24
@@ -274,6 +275,9 @@ impl<T: Trait, D: AsRef<[u8]>> frame_support::traits::KeyOwnerProofSystem<(KeyTy
type IdentificationTuple = IdentificationTuple<T>;

fn prove(key: (KeyTypeId, D)) -> Option<Self::Proof> {
//@note must take a context containing the index as paramter
// rather than depending on the current one since this func might
// be called at a later point of time
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah and the ProvingTrie should only be generated if it's equal to the current session


// @todo requires some internal mutability concept to work properly
// @todo which is yet to be hashed out
unsafe impl<L> core::marker::Sync for AlternativeDB<L> where
Copy link
Contributor

Choose a reason for hiding this comment

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

nothing in the struct definition makes me think this unsafe implementation is needed. Generally we avoid unsafe code very strongly, so I'd rather take a performance hit than introduce unsafe code.

Copy link
Contributor Author

@drahnr drahnr May 8, 2020

Choose a reason for hiding this comment

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

Unfortuantely the trait bound of HashDB requires it to be sync, which can only guaranteed if we introduce internal mutability or only impl HashDB for Arc<Mutex<AlternativeDB>> which I wanted to hold off until there is clarity iff concurrency/reentrancy are a problems.

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 see how a Sync bound, in the absence of some other factors, implies interior mutability. I haven't looked at this in some time, but don't the functions of HashDB that require you to mutate pass &mut self? If that is the case, then are you saying that there is a reason we would need interior mutability on the &self methods of HashDB?

let mapping: BTreeSet<(Vec<u8>, Vec<u8>)> =
offchain::local_storage_get(StorageKind::PERSISTENT, tracking_key.as_ref())
.map(|bytes| {
<BTreeSet<(Vec<u8>, Vec<u8>)> as Decode>::decode(&mut &bytes[..]).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

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

we are also strictly against unwraps in the codebase. the rule is "prove or remove" - use expect with a proof that the panic will not occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mea culpa, what would be the expected behaviour in that case? Should a warning be issued if a entry can not be loaded and the error be discarded and converted to a "Not Found"?

Copy link
Contributor

Choose a reason for hiding this comment

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

At this level of the code, it seems that we should be bubbling up a None value from the return of the function. It seems like the users of get_index should have an error handling case where that returns none. Warn & continue sounds reasonable for the use-cases we have.

}


fn derive_tracking_index_key(session_index: &[u8]) -> Vec<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

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

could this and other functions with a self receiver be free functions rather than inherent impls? Free function is typically more idiomatic in Rust; inherent impls are usually only used as constructors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be, the only reason was the move of the const prefixes into the impl, but if both live outside, it'll work - will do

@drahnr drahnr mentioned this pull request May 13, 2020
@drahnr
Copy link
Contributor Author

drahnr commented Jun 2, 2020

I think this can be discarded in favour of #6220

@drahnr drahnr 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. A0-please_review Pull request needs code review. labels Jun 10, 2020
@drahnr drahnr closed this Jun 10, 2020
@bkchr bkchr deleted the bernhard/slashing-w-ocw branch June 10, 2020 11:24
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.

3 participants