-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frame: Consideration
trait generic over Footprint
and indicates zero cost
#4596
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75c51b2
generic consideration
muharem 6aa9cc5
prdoc
muharem 6aac2ce
fix benches
muharem b1f2efd
tests
muharem d290864
update prdoc
muharem e88f6ce
revert mock setup change
muharem 3907306
Merge branch 'master' into muharem-generic-consideration
muharem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ where | |
} | ||
|
||
/// Some sort of cost taken from account temporarily in order to offset the cost to the chain of | ||
/// holding some data [`Footprint`] in state. | ||
/// holding some data `Footprint` (e.g. [`Footprint`]) in state. | ||
/// | ||
/// The cost may be increased, reduced or dropped entirely as the footprint changes. | ||
/// | ||
|
@@ -206,16 +206,20 @@ where | |
/// treated as one*. Don't type to duplicate it, and remember to drop it when you're done with | ||
/// it. | ||
#[must_use] | ||
pub trait Consideration<AccountId>: Member + FullCodec + TypeInfo + MaxEncodedLen { | ||
pub trait Consideration<AccountId, Footprint>: | ||
Member + FullCodec + TypeInfo + MaxEncodedLen | ||
{ | ||
/// Create a ticket for the `new` footprint attributable to `who`. This ticket *must* ultimately | ||
/// be consumed through `update` or `drop` once the footprint changes or is removed. | ||
fn new(who: &AccountId, new: Footprint) -> Result<Self, DispatchError>; | ||
/// be consumed through `update` or `drop` once the footprint changes or is removed. `None` | ||
/// implies no cost for a given footprint. | ||
fn new(who: &AccountId, new: Footprint) -> Result<Option<Self>, DispatchError>; | ||
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.
gupnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Optionally consume an old ticket and alter the footprint, enforcing the new cost to `who` | ||
/// and returning the new ticket (or an error if there was an issue). | ||
/// and returning the new ticket (or an error if there was an issue). `None` implies no cost for | ||
/// a given footprint. | ||
/// | ||
/// For creating tickets and dropping them, you can use the simpler `new` and `drop` instead. | ||
fn update(self, who: &AccountId, new: Footprint) -> Result<Self, DispatchError>; | ||
fn update(self, who: &AccountId, new: Footprint) -> Result<Option<Self>, DispatchError>; | ||
|
||
/// Consume a ticket for some `old` footprint attributable to `who` which should now been freed. | ||
fn drop(self, who: &AccountId) -> Result<(), DispatchError>; | ||
|
@@ -230,12 +234,12 @@ pub trait Consideration<AccountId>: Member + FullCodec + TypeInfo + MaxEncodedLe | |
} | ||
} | ||
|
||
impl<A> Consideration<A> for () { | ||
fn new(_: &A, _: Footprint) -> Result<Self, DispatchError> { | ||
Ok(()) | ||
impl<A, F> Consideration<A, F> for () { | ||
fn new(_: &A, _: F) -> Result<Option<Self>, DispatchError> { | ||
Ok(Some(())) | ||
} | ||
fn update(self, _: &A, _: Footprint) -> Result<(), DispatchError> { | ||
Ok(()) | ||
fn update(self, _: &A, _: F) -> Result<Option<Self>, DispatchError> { | ||
Ok(Some(())) | ||
} | ||
fn drop(self, _: &A) -> Result<(), DispatchError> { | ||
Ok(()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why should it not do that? The implementor of the
Consideration
should be able to return as they see fit.Otherwise it would probably need a
Consideration
andMaybeConsideration
trait to disambiguate.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, I agree. But I did now want to change the behaviour of this pallet, and make only a patch. Otherwise we need a migration for the preimage pallet.
Maybe I should rephrase it, that we do expect some cost for any non zero footprint, so it should not return 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.
Okay i see. The maybe add a check to the
integrity_test
of the pallet that a zero sized preimage still needs a deposit.