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

Unsigned Validation best practices#5563

Merged
gavofyork merged 7 commits into
masterfrom
td-unsigned-priority
Apr 8, 2020
Merged

Unsigned Validation best practices#5563
gavofyork merged 7 commits into
masterfrom
td-unsigned-priority

Conversation

@tomusdrw

@tomusdrw tomusdrw commented Apr 7, 2020

Copy link
Copy Markdown
Contributor

Introducing:

  • ValidTransaction builder to take care of prefixing provides tags.
  • Configurable UnsignedPriorityies to make sure the runtime has a way to control inter-pallet priorities of unsigned transactions.

Both should be considered best practices when implementing UnsignedValidator, and the builder should make it easier to follow them.

@tomusdrw tomusdrw added A0-please_review Pull request needs code review. B1-apinoteworthy labels Apr 7, 2020
@tomusdrw tomusdrw requested a review from kianenigma as a code owner April 7, 2020 14:00
///
/// To avoid conflicts between different pallets it's recommended to build `requires`
/// and `provides` tags with a unique prefix.
pub fn for_pallet(prefix: &'static str) -> ValidTransactionBuilder {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't call this for pallet but rather with_prefix. It is better to demonstrate exactly what is happening.

also pallet is.. pallet and primitives should not be pallet oriented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't call this for pallet but rather with_prefix. It is better to demonstrate exactly what is happening.

I'd argue that it's less clear. What prefix is that? What does it apply to?

also pallet is.. pallet and primitives should not be pallet oriented.

That's arguable as well. I feel that the frame and sp-runtime distinction is quite lost already many things are quite frame specific. Although it's a pretty lame argument, since it doesn't justify adding even more frame-specific things.

That said maybe with_tags_prefix would be a good common ground, wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sounds good!

///
/// The tag will be encoded and prefixed with pallet prefix (if any).
/// If you'd rather add a raw `require` tag, consider using `#combine_with` method.
pub fn and_requires(mut self, tag: impl Encode) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

won't this get corrupt if I call and_requires(a).and_requires(b) instead if and_provides((a, b).encode())? they name kinda suggests that you can call and_provides multiple times.

Either way I think the implementation should be safeguarded against it.

same for and_provides .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and by corrupt I only mean that you push the prefix multiple times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow. and_requires/and_provides append a single Tag. All tags will be prefixed. Calling it twice is perfectly fine, but it's definitely not the same as calling once with a tuple.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah my understanding was that PREFIX is added only once. But I was wrong.

Comment thread primitives/runtime/src/transaction_validity.rs
@gavofyork gavofyork merged commit ae77b81 into master Apr 8, 2020
@gavofyork gavofyork deleted the td-unsigned-priority branch April 8, 2020 09:17
@tomusdrw

tomusdrw commented Apr 8, 2020

Copy link
Copy Markdown
Contributor Author

Working on companion PR just now, will submit shortly.

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

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants