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

feat: improve performance BTC reward distribution #306

Merged
merged 145 commits into from
Dec 20, 2024

Conversation

RafilxTenfen
Copy link
Contributor

@RafilxTenfen RafilxTenfen commented Nov 28, 2024

  • Add new structures to track BTC delegation rewards and lazily distribute
  • Add new event BTCDelegationStatus_EXPIRED for BTC delegations that indicates a BTC delegation is no longer contributing to security
  • Important files diff for review
    • proto/babylon/incentive/rewards.proto
    • x/finality/keeper/power_dist_change.go
    • x/incentive/keeper/btc_staking_gauge.go
    • x/incentive/keeper/grpc_query.go
    • x/incentive/keeper/msg_server.go
    • x/incentive/keeper/reward_tracker.go
    • x/incentive/keeper/reward_tracker_store.go
    • x/btcstaking/keeper/btc_delegations.go
    • x/btcstaking/keeper/msg_server.go
    • x/btcstaking/types/btc_delegation.go

Benchmarks

Command to generate pprof go tool pprof -http=:8080 http://localhost:6060/debug/pprof/profile\?seconds\=300

  • Main branch that iterates over delegations to distribute rewards with 163k BTC delegations, took 15.52s (13.1%) of the time during the 300seconds interval used to generate the pprof

image

  • Current branch rafilx/improve-performance-btc-dist with 100k BTC delegations, took 6.73s (1.8%) of the time during the 300seconds interval

image

Note that the percentage of the time used that is ~7x lower should be considered instead of the time, the benchmark from main was running in the benchmark server 48 processors and 256GB of RAM while the one in the current branch I run locally with 24 processors and 96GB of RAM.... So the percentage of the time usage instead of seconds should be the one in comparison

Thanks @Lazar955 for help with benchmark
The function used to show the difference is the TallyBlocks because the RewardBTCStaking does not appear in the pprof of the current branch demonstrating that the time spent there is negligible to the overall period

@RafilxTenfen RafilxTenfen self-assigned this Nov 29, 2024
…otal amount of satoshi staked as sdkmath.int
… (needed to create a new set of keys to store map of del => fp address)
x/btcstaking/types/btc_delegation.go Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Show resolved Hide resolved
x/incentive/keeper/reward_tracker.go Show resolved Hide resolved
x/finality/types/power_table.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

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

looks good to me 👍 great work pushing it forward :)

Lets wait for at leas one more approval before merging given size of the pr :)

@RafilxTenfen
Copy link
Contributor Author

@SebastianElvis @gitferry Addressed all the comments 🚀

Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Great work on the improvement! Some minor comments, no blocker:

proto/babylon/btcstaking/v1/btcstaking.proto Outdated Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Outdated Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Outdated Show resolved Hide resolved
x/finality/keeper/power_dist_change.go Outdated Show resolved Hide resolved
Copy link
Member

@Lazar955 Lazar955 left a comment

Choose a reason for hiding this comment

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

Amazing work!

@Lazar955 Lazar955 merged commit c3aaaa1 into main Dec 20, 2024
20 checks passed
@Lazar955 Lazar955 deleted the rafilx/improve-performance-btc-dist branch December 20, 2024 10:26
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.

5 participants