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

refactor: optimization of total power calculation #518

Merged
merged 1 commit into from
Jun 18, 2023

Conversation

b00f
Copy link
Collaborator

@b00f b00f commented Jun 18, 2023

Description

Prior to this PR, the total power (the total staked coins) was calculated at each height by iterating over all validators and summing up the power (stakes). This was not an efficient method for calculating total power.

With this PR, a more efficient approach has been implemented. Now, whenever a validator bonds or unbonds a stake, we record this as a power delta (change) and apply it to the total power. This removes the need for iterating over all validators at every height, thereby optimizing the total power calculation process.

@codecov
Copy link

codecov bot commented Jun 18, 2023

Codecov Report

Merging #518 (c8aefb8) into main (5e2f135) will increase coverage by 0.15%.
The diff coverage is 97.29%.

@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
+ Coverage   83.15%   83.31%   +0.15%     
==========================================
  Files         154      154              
  Lines        7306     7322      +16     
==========================================
+ Hits         6075     6100      +25     
+ Misses        951      942       -9     
  Partials      280      280              

@Ja7ad Ja7ad self-requested a review June 18, 2023 10:04
@Ja7ad
Copy link
Contributor

Ja7ad commented Jun 18, 2023

@b00f All thing is okay for merge

@b00f b00f merged commit 0918e5d into pactus-project:main Jun 18, 2023
@b00f b00f deleted the power-delta branch June 18, 2023 10:35
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.

2 participants