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

Fix - Uses fetch_add() to accumulate usage counters in LoadedPrograms #34319

Merged

Conversation

Lichtso
Copy link
Contributor

@Lichtso Lichtso commented Dec 5, 2023

Problem

The pattern load(), saturating_add_assign(), store() on an atomic counter is a race condition because it does not use the transactional properties of atomics. Also DelayVisibility tombstones currently don't have their usage counter incremented on use.

Summary of Changes

While fetch_add() gives up the saturating arithmetic, this is first of all an extremely improbable edge case as even with the wildest TPS numbers currently envisioned a single validator would still have to run for tens of thousands of years without a single reboot and all transactions only using a single program, for this 64 bit counter to ever overflow. And even if it does, the atomics do wrapping and do not panic, so it is self correcting.

@Lichtso Lichtso requested a review from dmakarov December 5, 2023 13:18
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Merging #34319 (a147952) into master (d451675) will increase coverage by 0.0%.
Report is 1 commits behind head on master.
The diff coverage is 100.0%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #34319   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         819      819           
  Lines      220228   220225    -3     
=======================================
+ Hits       180535   180559   +24     
+ Misses      39693    39666   -27     

@Lichtso Lichtso merged commit f70d548 into solana-labs:master Dec 5, 2023
33 checks passed
@Lichtso Lichtso deleted the fix/loaded_programs_counter_accumulation branch December 5, 2023 22:21
@Lichtso Lichtso added the v1.17 PRs that should be backported to v1.17 label Dec 6, 2023
Copy link
Contributor

mergify bot commented Dec 6, 2023

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify bot pushed a commit that referenced this pull request Dec 6, 2023
…ams` (#34319)

Uses fetch_add() to accumulate usage counters.

(cherry picked from commit f70d548)

# Conflicts:
#	program-runtime/src/loaded_programs.rs
Lichtso added a commit that referenced this pull request Dec 12, 2023
…ams` (#34319)

Uses fetch_add() to accumulate usage counters.

(cherry picked from commit f70d548)
Lichtso added a commit that referenced this pull request Dec 12, 2023
…edPrograms` (backport of #34319) (#34348)

Fix - Uses `fetch_add()` to accumulate usage counters in `LoadedPrograms` (#34319)

Uses fetch_add() to accumulate usage counters.

(cherry picked from commit f70d548)

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
alessandrod added a commit that referenced this pull request Dec 14, 2023
…rograms (backport of #34319) (#34431)

* Fix tx_usage_counter use fetch_add.

* loaded_programs: fix tx_usage_counter for tombstone entries

---------

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.17 PRs that should be backported to v1.17
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants