-
Notifications
You must be signed in to change notification settings - Fork 709
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
Refactor proxy pallet to use Consideration instead #5336
base: master
Are you sure you want to change the base?
Refactor proxy pallet to use Consideration instead #5336
Conversation
bebc66f
to
130be66
Compare
ac65fc0
to
912f663
Compare
8ff747d
to
6ae7b4a
Compare
f901e22
to
ad31477
Compare
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.
Here we need a new runtime API, or a pallet view function, that would allow a UI to query how much the deposit would be.
We can go with the runtime API approach, but then it is really hard to get this API integrated across all runtimes..
The PR itself is pretty good, but I think this is tapping into another unsolved problem that we have now, so we should pause and first consolidate on how the broader issue is solved.
I have recently re-summarized the issue at hand here:
This PR per-se is one where we would benefit most from view-functions, as they would be shipped automatically, and the logic that needs to be encapsulated is pallet-specific. |
It does sound like proxy pallet could benefit from the view functions so all users could see their proxy deposit sizes. However, from the storage and implementation perspective, would we need to change anything to create view functions? For me it seems these are independent problems and we could resolve these in the future once view functions for pallets are established. PRs to create view functions would be much smaller this way. |
The CI pipeline was cancelled due to failure one of the required jobs. |
We have a PR to ship the view functions, and the discussion in the forum thread is converging towards using them. So, in principle, once we have them, we can provide a view fn that returns the deposit amount of a new proxy to be created. I am a bit hesitant to green-light this PR before the above is done though. Imagine: if DApps rely on I suggest:
FWIW, I think pausing the PR is not bad, or anything short of success here, especially in this day and age where we value stability. We can then use the learnings here to shift focus towards merging view functions, then resuming the work here. Side note: this conversation might be of interest for your learning @davidk-pt :) #3238 (comment) |
@@ -81,11 +89,13 @@ fn add_announcements<T: Config>( | |||
} | |||
|
|||
benchmarks! { | |||
where_clause { where T: Config + pallet_balances::Config } |
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.
There are different cases to handle this, but specifically requiring that pallet balances is deployed does not seem very clean to me.
You can either create a BenchmarkHelper
trait with a Currency
or Fungible
config item and then have that feature-gated in the main config, or require it here.
Alternatively the BenchmarkHelper
trait can also just have a fund_account
function, since that is the only thing that it needs to do. Not sure.
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.
PS what Muharem wrote about Consideration::ensure_successful
is better and exactly what it is intended for.
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]. | ||
pub mod config_preludes { |
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.
🙏 thanks for adding this.
substrate/frame/proxy/src/lib.rs
Outdated
T::Currency::unreserve(&spawner, deposit); | ||
if let Some((_, ticket)) = Proxies::<T>::take(&who) { | ||
if let Err(e) = ticket.drop(&spawner) { | ||
log::error!( |
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, defensive panics only in tests and logs a magic string in production, that we can filter for in our monitoring.
Otherwise this error log would probably get lost.
You can use it like
let _ = ticket.drop(&spawner).defensive_proof("something..");
substrate/frame/proxy/src/lib.rs
Outdated
pending.try_push(announcement).map_err(|_| Error::<T>::TooMany)?; | ||
let new_ticket = ticket.update( | ||
&who, | ||
Footprint::from_parts(pending.len(), Self::announcement_size_bytes()), |
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.
Footprint::from_parts(pending.len(), Self::announcement_size_bytes()), | |
Footprint::from_parts(pending.len(), Announcement::<...>::max_encoded_len()), |
Looks like there should be no difference between max and actual encoded len for this struct.
substrate/frame/proxy/src/lib.rs
Outdated
T::AnnouncementConsideration::new( | ||
&who, | ||
Footprint::from_parts(0, Self::announcement_size_bytes()), | ||
)?, |
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.
Not sure if i get this? Mabe a case distinction could work, that either updates or creates a new ticket.
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.
Rewritten this section
substrate/frame/proxy/src/lib.rs
Outdated
T::ProxyConsideration::new( | ||
delegator, | ||
Footprint::from_parts(0, Self::proxy_def_size_bytes()), | ||
)?, |
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 think these intermediary tickets are not so nice, as they are updated anyway. Could either not be created at all, or dropped.
let (_, old_deposit) = Proxies::<T>::take(&delegator); | ||
T::Currency::unreserve(&delegator, old_deposit); | ||
if let Some((_, ticket)) = Proxies::<T>::take(&delegator) { | ||
if let Err(e) = ticket.drop(&delegator) { |
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.
if let Err(e) = ticket.drop(&delegator) { | |
let _ = ticket.drop(&delegator).defensive_proof(".."); |
@@ -200,6 +200,23 @@ where | |||
} | |||
} | |||
|
|||
/// A storage price modifier that returns zero if number of elements is zero, |
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.
Where is this useful? Couldn't there still be a base deposit?
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 is the behaviour of Proxy pallet before Consideration, there's no base deposit, if items in footprint is zero then storage price is 0. This is to keep Proxy pallet backwards compatible with this behaviour not to break existing runtimes.
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.
Removed ZeroFootprintOr, not it calculates based on size only
Okay in this context it makes sense to pause for now, this PR is mostly done just needs few tweaks like view functions, some refactor to benchmarks and so on |
5f8b6c3
to
6576a7a
Compare
6576a7a
to
0332ab4
Compare
322a251
to
c680f8d
Compare
I'm afraid view functions will take a while to be completed, please see: #4722 |
Refactor proxy pallet to use Consideration #226
Based on initial PR here https://github.com/paritytech/polkadot-sdk/pull/1837/files
Adds
TestDefaultConfig
for proxy pallet.Guide on how to migrate from previous proxy pallet usage
Remove
Currency
from configuration of the proxy pallet (now currency comes fromProxyConsideration
andAnnouncementConsideration
)Remove the
ProxyDepositBase
,ProxyDepositFactor
,AnnouncementDepositBase
,AnnouncementDepositFactor
types inside proxy pallet config and addProxyConsideration
andAnnouncementConsideration
configuration types instead.Also you need to add two hold reasons for proxy and announcement respectively
IMPORTANT
ProxyDepositFactor
andAnnouncementDepositFactor
parameters inAtLeastOneLinearStoragePrice
don't need to account for byte size of proxies and announcements as it is already computed so it should be renamed toProxyDepositPerByte
andAnnouncementDepositPerByte
and deposit value should be divided by previous byte value that was used, for exampledeposit(0, 66)
should be lowered todeposit(0, 1)
if deposit factor reflected 66 bytes per item.Example
Previous example proxy usage
New usage
@seadanda @muharem