Skip to content
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

[Staking] Kill unnecessary storage bloat #970

Merged
merged 7 commits into from Nov 9, 2021

Conversation

4meta5
Copy link
Contributor

@4meta5 4meta5 commented Nov 8, 2021

Changes the pay_stakers code to take() the storage items Staked and Points instead of just getting them.

Also includes a migration to remove the stored values that are older than 2 rounds ago (because any stored values less than 2 rounds old will be killed in pay_stakers during future payout which will take() these values).

I separated this from #810 because this is a distinct change and I do not want to lump too many changes into that PR.

@4meta5 4meta5 added A0-pleasereview Pull request needs code review. D1-runtime-migration PR introduces code that might require downstream chains to run a runtime upgrade. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes B0-silent Changes should not be mentioned in any release notes and removed B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes labels Nov 8, 2021
@4meta5 4meta5 self-assigned this Nov 8, 2021
@4meta5 4meta5 removed their assignment Nov 8, 2021
@notlesh
Copy link
Contributor

notlesh commented Nov 8, 2021

For the migration part, would it be possible/preferable to remove the storage bloat through democracy?

Copy link
Contributor

@JoshOrndorff JoshOrndorff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Made a few little comments. Only one I consider blocking is post_upgrade.

pallets/parachain-staking/src/migrations.rs Outdated Show resolved Hide resolved
pallets/parachain-staking/src/migrations.rs Outdated Show resolved Hide resolved
pallets/parachain-staking/src/migrations.rs Outdated Show resolved Hide resolved
<Points<T>>::remove(i);
}
// 5% of the max block weight as safety margin for computation
db_weight.reads(reads) + db_weight.writes(writes) + 25_000_000_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being a little pedantic here, but if you're intending it to be %5 of max block, you should express it as max_block / 20 or similar in code. Because the max_block actually depends on the runtime in question.

Copy link
Contributor Author

@4meta5 4meta5 Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is in the pallet so how would I pass it this information (max block weight from the runtime where it's executed)?

It is used as a safety margin so it doesn't have to be accurate in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<T as frame_system::Config>::BlockWeights::get().max_block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it doesn't really need to be that accurate.

4meta5 and others added 2 commits November 8, 2021 18:48
Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
@4meta5
Copy link
Contributor Author

4meta5 commented Nov 8, 2021

For the migration part, would it be possible/preferable to remove the storage bloat through democracy?

@notlesh It's not a heavy migration so I don't think this is necessarily preferable. Is there a test we could do to determine when this ought to be done?

With that said, we could easily do this -- we'd just add an extrinsic gated by root hotfix_purge_stale_storage and move that part of the migration into this function.

@notlesh
Copy link
Contributor

notlesh commented Nov 9, 2021

@notlesh It's not a heavy migration so I don't think this is necessarily preferable. Is there a test we could do to determine when this ought to be done?

I was thinking more about simplicity and resiliency; submitting an extrinsic is probably simpler than managing a migration and might be more resilient (less chance of something catastrophic happening). But neither of these are necessarily true.

I don't have a strong opinion either way, just wanted to bring it up.

As for it perhaps being too heavy, we could test this with try-runtime and/or fork-off-substrate. I don't recall whether these things clearly indicate the weight of migrations, but that's something we could add (and, potentially, PoV size). I wouldn't worry much about it if we're talking hundreds or fewer DB reads/writes...

With that said, we could easily do this -- we'd just add an extrinsic gated by root hotfix_purge_stale_storage and move that part of the migration into this function.

Would system->killStorage() or system->killPrefix() work?

@4meta5
Copy link
Contributor Author

4meta5 commented Nov 9, 2021

Would system->killStorage() or system->killPrefix() work?

The proposal would need to be a batch of calls to killPrefix for all values > 2 rounds old for the two relevant storage maps.

I'm sure it could be done, but it's easier for me to do it in a migration.

Copy link
Contributor

@JoshOrndorff JoshOrndorff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-runtime and the unit test both look good to me!

@JoshOrndorff JoshOrndorff merged commit 0dac2df into master Nov 9, 2021
@JoshOrndorff JoshOrndorff deleted the amar-staking-kill-storage-bloat branch November 9, 2021 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview Pull request needs code review. B0-silent Changes should not be mentioned in any release notes D1-runtime-migration PR introduces code that might require downstream chains to run a runtime upgrade.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants