This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update lowest unbaked storage. #9750
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ac4db0
update lowest unbaked
gui1117 3caa8b2
fix format
gui1117 19c7d2f
add note
gui1117 fd57506
Merge remote-tracking branch 'origin/master' into gui-update-lowest-u…
gui1117 27ad7f3
fmt
gui1117 2936658
Merge remote-tracking branch 'origin/master' into gui-update-lowest-u…
gui1117 4fc6f85
Merge remote-tracking branch 'origin/master' into gui-update-lowest-u…
gui1117 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
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
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.
Would it be clearer
<LowestUnbaked<T>>::mutate(|ref_index| { *ref_index = index + 1})
right here?The only issue I see is if we miss calling this
begin_block
for some previous block and there are some referendum that get skipped over inmaturing_referenda_at_inner
because they end at less thann
, but have not yet finished. I think the below logic would then just get stuck on referenda that end at less thann
but have not yet finished. (And the below loop just seems like an unnecessary constant increase in iterations + storage reads)To handle the skipped block case we could change
maturing_referenda_at_inner
to filter like.filter(|(_, status)| status.end <= n)
(currently it is.filter(|(_, status)| status.end == n)
).(haven't read the whole pallet yet though, so may be missing something)
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 true only if referendum are maturing in order of their index. I expected some referendum to mature later than some other with bigger index. In this case we can't do your proposal.
EDIT: it safer in case of runtime upgrade increase some voting period
I agree we could do the filter
status.end <= n
, or log an error because it should never happen in practice and if it happens it is not a big issue.there shouldn't be any additional (not in cache) storage reads, all storage reads should read from cache.
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.
Just too clarify, you want to keep the second iteration because the cache hit cost is minimal and I assume you think it is more readable?
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.
no I'm not against refactoring maturing_referenda_at_inner to avoid this second iteration. But the suggestion you propose seems a bit more error prone, due to the fact that if any referendum of an index ends after another referendum of an index bigger then the lowest unbaked is invalid. This could maybe happen when the constant VotingPeriod is changed with a runtime upgrade.
So either we refactor, or we keep this second iteration seems to be the best options
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.
Thank you for explaining. Given this info, I like keeping your current approach