-
Notifications
You must be signed in to change notification settings - Fork 708
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
Add ConsiderationFromLegacy
traits
#2274
base: master
Are you sure you want to change the base?
Conversation
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.
Now it looks clean, thanks!
(test could still be good though)
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Self: Sized, | ||
{ | ||
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 default impl feels like a footgun to me
Self: Sized, | |
{ | |
Ok(None) | |
} | |
Self: Sized; |
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.
Replied why of the default impl in the next comment
Self: Sized, | ||
{ | ||
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.
same, not sure why anyone would want to use this default impl
Self: Sized, | |
{ | |
Ok(None) | |
} | |
Self: Sized; |
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 FRAME pallet that makes use of it on its Config
would look something like this:
type Consideration: Consideration<Self::AccountId> + HoldConsiderationFromLegacy<Self::AccountId, BalanceOf<T>>
The default impl is for 3rd parties that make use of the pallet, so then they do not have to manually implement it.
{ | ||
/// Create a ticket for a `new` balance attributable to `who`. This ticket *must* ultimately | ||
/// be consumed through `update` or `drop` once a footprint changes or is removed. | ||
fn new_from_exact(_who: &A, _new: F::Balance) -> Result<Option<Self>, DispatchError> |
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 do these return Result<Option<Self>, DispatchError>
instead of Result<Self, DispatchError>
?
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 believe I implemented that to return None
as the default impl. As mentioned earlier, ConsiderationFromLegacy
will be required for those pallets that need it during the migration.
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.
Hmm I'm still not convinced
- this feels like a hack to pass a type indirectly to a migration.. As discussed in dm, I'd like to check if it's possible to pass this type directly to the migration if indeed it is only needed in the migration, not the pallet
- there are genuine use cases for when you do want to use this directly in the pallet, e.g. @gupnik is working on a lazy migration right now where we're discussing potentially using 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.
I guess the default impl would never be used and is only meant to make it compile once all currency related crates were removed from the runtime config.
But then it should indeed return an Error and not 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.
Yeah would feel much better returning an error to me instead of the 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.
I still would like to see if possible to avoid the default impl (and polluting the pallet config) by passing this type directly to the migration it is used in tho.
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.
@liamaharon @ggwpez I replaced None
with Err
. It should be now good to go.
For reference, here an example of the new method being used: https://github.com/paritytech/polkadot-sdk/pull/1789/files#diff-489bbb1c7c1b1b8803ab344f63079bdc1b7d67db3d2d8809d6a3a755443619f0R77-R107
This PR addresses a potential issue that may arise when migrating pallets from using
Currency
toConsideration
. It specifically addresses scenarios where a pallet's migrations involve aDeposit
that hasn't been constant over time (e.g. increased by a runtime upgrade).During the migration, the new
HoldConsideration
results in a fixedBalance
based on a constantFootprint
and aConvert
function. For instance, if the newHoldConsideration
is expected to have aBalance
of10
, what happens when, for a particular account, the storedDeposit
is5
? After callingCurrency::unreserve(account, 5)
, attempting to create a new ticket to hold aBalance
of10
might fail due to insufficient balance. Currently,HoldConsideration::new()
returns eitherOk(())
orErr
. What should be done if it's not possible to hold the balance?Following a similar approach to #1813 (comment), I introduced two new traits:
FreezeConsiderationFromLegacy
HoldConsiderationFromLegacy
These traits extend
Consideration
with a new methodnew_from_exact()
which proves useful when a new ticket with a precise balance is needed (as illustrated in the migration example) rather than deriving it from a footprint.