-
Notifications
You must be signed in to change notification settings - Fork 856
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
Change pallet referenda TracksInfo::tracks to return an iterator #2072
Change pallet referenda TracksInfo::tracks to return an iterator #2072
Conversation
b059f67
to
4bc9edc
Compare
NOTE: I realized that return_position_impl_trait_in_trait was recently stabilized, I think it's worth using it in this feature as it makes usage of the trait much simpler. Please consider updating the rust toolchain :) EDIT: As the policy is to keep things working with stable Rust, I reverted the usage of the nightly feature( |
5c3ab3b
to
57585ac
Compare
50a8759
to
355615d
Compare
c3abd5b
to
e1a2699
Compare
4994d7e
to
47c9710
Compare
750f1bb
to
e0d4e7c
Compare
e0d4e7c
to
e37fe07
Compare
cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/tracks.rs
Outdated
Show resolved
Hide resolved
cumulus/parachains/runtimes/collectives/collectives-polkadot/src/ambassador/tracks.rs
Outdated
Show resolved
Hide resolved
@@ -117,27 +117,6 @@ pub mod benchmarking; | |||
|
|||
pub use frame_support::traits::Get; | |||
|
|||
#[macro_export] | |||
macro_rules! impl_tracksinfo_get { |
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 having done it, to avoid breaking change we could also keep the macro but make it deprecated. The deprecation message can say: tracks info no longer requires get, the macro invocation can be removed.
But keep it removed is also ok to me.
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.
After a small evaluation, I concluded that removing it is better since we're eliminating some potentially unused code at the almost negligible cost of deleting 5 calls to this macro in the runtimes
repo (plus one or two for every runtime being built outside the scope of Polkadot).
To me keeping it removed is a no brainer.
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.
maybe we can also add a comment about this in the PRdoc in a follow-up PR
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. I can add a follow-up PR that only mentions the changes in the API, and that can be included in the stable2503
to let everyone know about the changes.
On it right now 👀
2c4ab10
to
aee2e08
Compare
c078d2f
…itytech#2072) Returning an iterator in `TracksInfo::tracks()` instead of a static slice allows for more flexible implementations of `TracksInfo` that can use the chain storage without compromising a lot on the performance/memory penalty if we were to return an owned `Vec` instead. --------- Co-authored-by: Pablo Andrés Dorado Suárez <[email protected]>
This PR broke polkadot.js apps: polkadot-js/apps#11310 |
This is a good example of PR where I would ask if it was really necessary to cause a breaking change? and also the PRdoc was not highlighting how this should be treated by the API libraries. |
The internal encoding is changed: #2072 (comment) the field was a |
Yea we could do a custom encoding that prepends the length again. @pandres95 can you please do this and backport into 2503? |
We can also have a type with 2 variant one bounded vec and one static array, with manual encoding. And the decoding always decode the bounded vec variant. Then there is no breaking change for UI not even padding. EDIT: prepending the length is an easier implementation though. |
I think the biggest problem here is getting the pallet constant, not really storing the content. A solution might be transforming the tracks iter into a getter that resolves to the previously known structure. I can do that. |
Yes it will also work, and it will be the least breaking change possible for users |
fn tracks() -> Vec<Track<TrackIdOf<T, I>, BalanceOf<T, I>, BlockNumberFor<T, I>>> { | ||
T::Tracks::tracks().map(|t| t.into_owned()).collect() | ||
} | ||
} |
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.
But having this as a constant is incompatible with the trait usage.
In the trait we want to make use of storage to have dynamic tracks. But this being a constant means the track must not change in between runtime upgrade.
I think this PR is inconsistent.
Maybe we should not extend referenda and let other people use a different pallet if they need dynamic tracks.
Or we should make it a view function and remove the constant, which is a bigger breaking change.
Should we revert it?
The initial design of this PR took into account Gav's requirements of not having any kind of performance regression(i.e. keep allowing the const definition of tracks) and not breaking anything, as tracks were not stored it was fine but didn't consider the front-end. |
I dont see a fixup MR open - going to revert it until it is sorted. Maybe there exists a better approach of the likes as Gui pointed out above. |
Hey @ggwpez . The fixup MR will be ready before 5pm (COT) today. I had to figure out the best way possible to make this to be as performant as possible. After some tests, I'm taking a way that's similar to what Gui actually proposed. |
Returning an iterator in
TracksInfo::tracks()
instead of a static slice allows for more flexible implementations ofTracksInfo
that can use the chain storage without compromising a lot on the performance/memory penalty if we were to return an ownedVec
instead.