Skip to content

chore: centralise weight calculation and reduce writes to storage#1210

Merged
darrenkel merged 27 commits into
release/hayabusafrom
darren/chore/centralise-weight-calculations
Aug 5, 2025
Merged

chore: centralise weight calculation and reduce writes to storage#1210
darrenkel merged 27 commits into
release/hayabusafrom
darren/chore/centralise-weight-calculations

Conversation

@darrenkel

@darrenkel darrenkel commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Description

  • housekeeping: accumulate all validators totals updates, so we only write once per total
  • weights: centralise weight calculation using new stakes package

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@darrenkel
darrenkel requested a review from a team as a code owner July 30, 2025 08:54
@codecov-commenter

codecov-commenter commented Jul 30, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.08054% with 131 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.15%. Comparing base (f03d35e) to head (2db7720).

Files with missing lines Patch % Lines
builtin/staker/validation/validation.go 0.00% 34 Missing ⚠️
builtin/staker/delta/delta.go 0.00% 25 Missing ⚠️
builtin/staker/globalstats/service.go 0.00% 25 Missing ⚠️
builtin/staker/stakes/stakes.go 0.00% 11 Missing ⚠️
builtin/staker/validation/service.go 0.00% 10 Missing ⚠️
builtin/staker/aggregation/service.go 0.00% 9 Missing ⚠️
builtin/staker/housekeep.go 44.44% 2 Missing and 3 partials ⚠️
builtin/staker/staker.go 68.75% 0 Missing and 5 partials ⚠️
builtin/staker/delegation/service.go 0.00% 4 Missing ⚠️
builtin/staker/delegation/delegation.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           release/hayabusa    #1210      +/-   ##
====================================================
- Coverage             58.21%   58.15%   -0.07%     
====================================================
  Files                   275      277       +2     
  Lines                 28987    29014      +27     
====================================================
- Hits                  16876    16872       -4     
- Misses                10675    10706      +31     
  Partials               1436     1436              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread builtin/staker_native_gas_test.go Outdated
@darrenkel
darrenkel force-pushed the darren/chore/centralise-weight-calculations branch from 9fc882d to ce94c3d Compare July 30, 2025 14:02
Base automatically changed from pedro/hayabusa/refact_housekeep to release/hayabusa July 30, 2025 15:54
Comment thread builtin/staker/stakes/stakes.go

@otherview otherview left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is on the right path.
It seems like the goal is to abstract away the concept of Stake (big.Int) and replace it with Weighted Stake (struct).
This avoids any miscalculation or misuse of the stake vs weight.

What about making the Stake a private field and only allowing the access of the WeightedStake ?
My concern is that the Stake can be changed directly wrongfully.
Perhaps, as an example, if the delegation moved from delegation.Stake + delegation.Multiplier to delegation.WeightedStake then it should be impossible to mess that up.

Comment thread builtin/solidity/uint256.go Outdated
Comment thread builtin/solidity/uint256_test.go Outdated
Comment thread builtin/staker/delegation/delegation.go Outdated
Comment thread builtin/staker/validation/validation.go Outdated
Comment thread builtin/staker/validation/validation.go Outdated

@otherview otherview left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps worth making the SetDelegation to a private method. Not a block imo

@darrenkel
darrenkel merged commit dc1aac7 into release/hayabusa Aug 5, 2025
43 of 45 checks passed
@darrenkel
darrenkel deleted the darren/chore/centralise-weight-calculations branch August 5, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants