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

Add support for feature pallet_balances/insecure_zero_ed in benchmarks and testing #7379

Conversation

manuelmauro
Copy link
Contributor

@manuelmauro manuelmauro commented Jan 29, 2025

Description

Currently benchmarks and tests on pallet_balances would fail when the feature insecure_zero_ed is enabled. This PR allows to run such benchmark and tests keeping into account the fact that accounts would not be deleted when their balance goes below a threshold.

Integration

In depth notes about how this PR should be integrated by downstream projects. This part is mandatory, and should be
reviewed by reviewers, if the PR does NOT have the R0-Silent label. In case of a R0-Silent, it can be ignored.

Review Notes

In depth notes about the implementation details of your PR. This should be the main guide for reviewers to
understand your approach and effectively review it. If too long, use
<details>
.

Imagine that someone who is depending on the old code wants to integrate your new code and the only information that
they get is this section. It helps to include example usage and default value here, with a diff code-block to show
possibly integration.

Include your leftover TODOs, if any, here.

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
    • External contributors: ask maintainers to put the right label on your PR.
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

You can remove the "Checklist" section once all have been checked. Thank you for your contribution!

✄ -----------------------------------------------------------------------------

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Jan 29, 2025

User @manuelmauro, please sign the CLA here.

@manuelmauro manuelmauro marked this pull request as ready for review January 29, 2025 09:53
@manuelmauro manuelmauro requested a review from a team as a code owner January 29, 2025 09:53
@re-gius re-gius added T2-pallets This PR/Issue is related to a particular pallet. T10-tests This PR/Issue is related to tests. labels Jan 29, 2025
@re-gius
Copy link
Contributor

re-gius commented Jan 29, 2025

bot bench substrate-pallet --features=insecure_zero_ed --pallet=pallet_balances

@command-bot
Copy link

command-bot bot commented Jan 29, 2025

@re-gius https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8112528 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=insecure_zero_ed --pallet=pallet_balances. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 1-750b5ecf-caad-4fbe-af7f-1bef56eafa29 to cancel this command or bot cancel to cancel all commands in this pull request.

Copy link
Contributor

We have migrated the command bot to GHA

Please, see the new usage instructions here or here. Soon the old commands will be disabled.

@re-gius
Copy link
Contributor

re-gius commented Jan 29, 2025

/cmd bench substrate-pallet --features=insecure_zero_ed --pallet=pallet_balances

Copy link
Contributor

Command "bench substrate-pallet --features=insecure_zero_ed --pallet=pallet_balances" has started 🚀 See logs here

@command-bot
Copy link

command-bot bot commented Jan 29, 2025

@re-gius Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=insecure_zero_ed --pallet=pallet_balances has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8112528 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8112528/artifacts/download.

@re-gius
Copy link
Contributor

re-gius commented Jan 29, 2025

/cmd bench substrate-pallet --pallet=pallet_balances

Copy link
Contributor

Command "bench substrate-pallet --pallet=pallet_balances" has started 🚀 See logs here

Copy link
Contributor

@re-gius re-gius left a comment

Choose a reason for hiding this comment

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

LGTM

substrate/frame/balances/src/benchmarking.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot requested review from re-gius and RomarQ January 29, 2025 15:32
Copy link
Contributor

Review required! Latest push from author must always be reviewed

@re-gius
Copy link
Contributor

re-gius commented Jan 29, 2025

/cmd bench substrate-pallet --pallet=pallet_balances

Copy link
Contributor

Command "bench substrate-pallet --pallet=pallet_balances" has started 🚀 See logs here

Comment on lines +68 to +72
if cfg!(feature = "insecure_zero_ed") {
assert_eq!(Balances::<T, I>::free_balance(&caller), balance - transfer_amount);
} else {
assert_eq!(Balances::<T, I>::free_balance(&caller), Zero::zero());
}
Copy link
Member

Choose a reason for hiding this comment

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

These changes are not required, since this change: 1c4141a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the linked change was not enough as some benchmarks/tests rely on the side-effect of an account being removed as its balance goes below the ExistentialBalance threshold.

E.g., https://github.com/paritytech/polkadot-sdk/pull/7379/files/e5e561501393e4384bac52b2c8febae49591b1c9#diff-bbca4fed8efbc441432d5d1772f445f49b1f4a25e0920dbcd41ccba2dfbc6520L209-L213

To reproduce the issue:

cargo test -p pallet-balances --features runtime-benchmarks,insecure_zero_ed

Copy link
Contributor

Choose a reason for hiding this comment

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

I double-checked it on master and it's right, those tests fail with the insecure_zero_ed feature flag

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I forgot the runtime-benchmarks flag earlier :D

@@ -1136,6 +1136,7 @@ fn operations_on_dead_account_should_not_change_state() {

#[test]
#[should_panic = "The existential deposit must be greater than zero!"]
#[cfg(not(feature = "insecure_zero_ed"))]
Copy link
Member

Choose a reason for hiding this comment

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

Only this is required.

@RomarQ
Copy link
Contributor

RomarQ commented Jan 29, 2025

@manuelmauro I think we should also update burn_allow_death burn_keep_alive benchmarks to use let existential_deposit: T::Balance = minimum_balance::<T, I>(); instead of let existential_deposit = T::ExistentialDeposit::get();

I think it is the only thing missing to allow runtimes to use ExistentialDeposit = 0 when running benchmarks.

Copy link
Contributor

Command "bench substrate-pallet --pallet=pallet_balances" has failed ❌! See logs here

Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_balances']
-- westend: ['pallet_balances']
-- rococo: ['pallet_balances']
-- asset-hub-westend: ['pallet_balances']
-- asset-hub-rococo: ['pallet_balances']
-- bridge-hub-rococo: ['pallet_balances']
-- bridge-hub-westend: ['pallet_balances']
-- collectives-westend: ['pallet_balances']
-- contracts-rococo: ['pallet_balances']
-- coretime-rococo: ['pallet_balances']
-- coretime-westend: ['pallet_balances']
-- people-rococo: ['pallet_balances']
-- people-westend: ['pallet_balances']

Copy link
Contributor

Command "bench substrate-pallet --features=insecure_zero_ed --pallet=pallet_balances" has failed ❌! See logs here

Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_balances']
-- westend: ['pallet_balances']
-- rococo: ['pallet_balances']
-- asset-hub-westend: ['pallet_balances']
-- asset-hub-rococo: ['pallet_balances']
-- bridge-hub-rococo: ['pallet_balances']
-- bridge-hub-westend: ['pallet_balances']
-- collectives-westend: ['pallet_balances']
-- contracts-rococo: ['pallet_balances']
-- coretime-rococo: ['pallet_balances']
-- coretime-westend: ['pallet_balances']
-- people-rococo: ['pallet_balances']
-- people-westend: ['pallet_balances']

Copy link
Contributor

Command "bench substrate-pallet --pallet=pallet_balances" has failed ❌! See logs here

Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_balances']
-- westend: ['pallet_balances']
-- rococo: ['pallet_balances']
-- asset-hub-westend: ['pallet_balances']
-- asset-hub-rococo: ['pallet_balances']
-- bridge-hub-rococo: ['pallet_balances']
-- bridge-hub-westend: ['pallet_balances']
-- collectives-westend: ['pallet_balances']
-- contracts-rococo: ['pallet_balances']
-- coretime-rococo: ['pallet_balances']
-- coretime-westend: ['pallet_balances']
-- people-rococo: ['pallet_balances']
-- people-westend: ['pallet_balances']

@bkchr bkchr enabled auto-merge January 29, 2025 19:51
auto-merge was automatically disabled January 29, 2025 19:53

Head branch was pushed to by a user without write access

@RomarQ
Copy link
Contributor

RomarQ commented Jan 29, 2025

@bkchr just added the missing logic, all calls are now working when insecure_zero_ed feature is enabled and ExistentialDeposit is zero.

@bkchr bkchr enabled auto-merge January 29, 2025 20:01
auto-merge was automatically disabled January 29, 2025 21:19

Head branch was pushed to by a user without write access

@bkchr bkchr enabled auto-merge January 29, 2025 21:32
@bkchr bkchr added this pull request to the merge queue Jan 29, 2025
Merged via the queue into paritytech:master with commit 80e30ec Jan 29, 2025
203 of 206 checks passed
ordian added a commit that referenced this pull request Feb 3, 2025
* master:
  Remove warnings by cleaning up the `Cargo.toml` (#7416)
  [Backport] Version bumps from stable2412-1 + prdocs reorg (#7401)
  fix pre-dispatch PoV underweight for ParasInherent (#7378)
  malus-collator: implement malicious collator submitting same collation to all backing groups (#6924)
  `fatxpool`: use tracing for logging (#6897)
  Improvements for Weekly bench (#7390)
  Replace derivative dependency with derive-where (#7324)
  Add support for feature `pallet_balances/insecure_zero_ed` in benchmarks and testing (#7379)
  Fix Snowbridge benchmark tests (#7296)
  Bridges small nits/improvements (#7383)
  Migrating cumulus-pallet-session-benchmarking to Benchmarking V2  (#6564)
  [pallet-revive] implement the block author API  (#7198)
  Use checked math in frame-balances named_reserve (#7365)
  move installation of frame-omni-bencher into a cmd.py itself (#7372)
  remove old bench & revert the frame-weight-template (#7362)
  ci: fix workflow permissions (#7366)
  [net/libp2p] Use raw `Identify` observed addresses to discover external addresses (#7338)
  Improve `set_validation_data` error message. (#7359)
  Implement pallet view function queries (#4722)
girazoki pushed a commit to moondance-labs/polkadot-sdk that referenced this pull request Feb 4, 2025
…rks and testing (paritytech#7379)

# Description

Currently benchmarks and tests on pallet_balances would fail when the
feature insecure_zero_ed is enabled. This PR allows to run such
benchmark and tests keeping into account the fact that accounts would
not be deleted when their balance goes below a threshold.

## Integration

*In depth notes about how this PR should be integrated by downstream
projects. This part is mandatory, and should be
reviewed by reviewers, if the PR does NOT have the `R0-Silent` label. In
case of a `R0-Silent`, it can be ignored.*

## Review Notes

*In depth notes about the **implementation** details of your PR. This
should be the main guide for reviewers to
understand your approach and effectively review it. If too long, use

[`<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details)*.

*Imagine that someone who is depending on the old code wants to
integrate your new code and the only information that
they get is this section. It helps to include example usage and default
value here, with a `diff` code-block to show
possibly integration.*

*Include your leftover TODOs, if any, here.*

# Checklist

* [x] My PR includes a detailed description as outlined in the
"Description" and its two subsections above.
* [x] My PR follows the [labeling requirements](

https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
) of this project (at minimum one label for `T` required)
* External contributors: ask maintainers to put the right label on your
PR.
* [x] I have made corresponding changes to the documentation (if
applicable)
* [x] I have added tests that prove my fix is effective or that my
feature works (if applicable)

You can remove the "Checklist" section once all have been checked. Thank
you for your contribution!

✄
-----------------------------------------------------------------------------

---------

Co-authored-by: Rodrigo Quelhas <[email protected]>
Ank4n pushed a commit that referenced this pull request Feb 6, 2025
…rks and testing (#7379)

# Description

Currently benchmarks and tests on pallet_balances would fail when the
feature insecure_zero_ed is enabled. This PR allows to run such
benchmark and tests keeping into account the fact that accounts would
not be deleted when their balance goes below a threshold.

## Integration

*In depth notes about how this PR should be integrated by downstream
projects. This part is mandatory, and should be
reviewed by reviewers, if the PR does NOT have the `R0-Silent` label. In
case of a `R0-Silent`, it can be ignored.*

## Review Notes

*In depth notes about the **implementation** details of your PR. This
should be the main guide for reviewers to
understand your approach and effectively review it. If too long, use

[`<details>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details)*.

*Imagine that someone who is depending on the old code wants to
integrate your new code and the only information that
they get is this section. It helps to include example usage and default
value here, with a `diff` code-block to show
possibly integration.*

*Include your leftover TODOs, if any, here.*

# Checklist

* [x] My PR includes a detailed description as outlined in the
"Description" and its two subsections above.
* [x] My PR follows the [labeling requirements](

https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
) of this project (at minimum one label for `T` required)
* External contributors: ask maintainers to put the right label on your
PR.
* [x] I have made corresponding changes to the documentation (if
applicable)
* [x] I have added tests that prove my fix is effective or that my
feature works (if applicable)

You can remove the "Checklist" section once all have been checked. Thank
you for your contribution!

✄
-----------------------------------------------------------------------------

---------

Co-authored-by: Rodrigo Quelhas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet. T10-tests This PR/Issue is related to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants