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

blockchain: Correct total subsidy snapshot. #3112

Merged
merged 3 commits into from
May 25, 2023

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented May 17, 2023

Testing Notes

As of this PR, the expected behavior is that there is a single migration that takes around 2 to 3 minutes to complete after which it will no longer be possible to downgrade.

As the warning above notes, if you try to run an older software version after this migration has completed, you will get an error message similar to Unable to start server: the current blockchain database is no longer compatible with this version of the software (14 > 13)


This modifies calculateAddedSubsidy to also include the subsidy generated by treasurybases to ensure the total reported coin supply is the expected value.

It should be noted that this commit only corrects the function and the issue does not affect consensus in any way since the calculated value is only used when providing the information via RPC.

However, it does mean the database has an incorrect value stored and therefore requires a database migration to correct.

The migration involves loading and iterating through all of the main chain blocks and to recalculate the total subsidy and then updating the best chain state that houses the stored value. The process can be interrupted at any point and future invocations will resume from the point it was interrupted.

Also, this takes advantage of the database version bump to only check and remove the legacy spend consumer dependencies bucket once during the upgrade instead of at every startup.

Fixes #3111.

@davecgh davecgh added the database upgrade Issues and/or pull requests that involve a new database version. label May 17, 2023
@davecgh davecgh added this to the 1.8.0 milestone May 17, 2023
@davecgh davecgh force-pushed the blockchain_correct_subsidy_snapshot branch from 92cc25f to 46a675b Compare May 22, 2023 05:06
Copy link
Member

@jrick jrick left a comment

Choose a reason for hiding this comment

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

upgrade ran fine, and don't spot any issues in this code except the trivial bits regarding the error messages

internal/blockchain/upgrade.go Outdated Show resolved Hide resolved
internal/blockchain/upgrade.go Outdated Show resolved Hide resolved
internal/blockchain/upgrade.go Outdated Show resolved Hide resolved
davecgh added 3 commits May 22, 2023 20:44
This removes the error return from the TipGeneration method since it is
no longer used due to previous updates.

It also updates all callers accordingly.
This modifies calculateAddedSubsidy to also include the subsidy
generated by treasurybases to ensure the total reported coin supply is
the expected value.

It should be noted that this commit only corrects the function and the
issue does not affect consensus in any way since the calculated value is
only used when providing the information via RPC.

However, it does mean the database has an incorrect value stored.  That
will be corrected via a database migration in a separate commit.
This adds code to correct the total subsidy entry in the database due to
the issue in calculateAddedSubsidy described by the previous commit.

It involves loading and iterating through all of the main chain blocks
and to recalculate the total subsidy and then updating the best chain
state that houses the stored value.  The process can be interrupted at
any point and future invocations will resume from the point it was
interrupted.

Also, this takes advantage of the database version bump to only check
and remove  the legacy spend consumer dependencies bucket once during
the upgrade instead of at every startup.
@davecgh davecgh force-pushed the blockchain_correct_subsidy_snapshot branch from 46a675b to 14a80d5 Compare May 23, 2023 01:56
@davecgh davecgh merged commit 14a80d5 into decred:master May 25, 2023
@davecgh davecgh deleted the blockchain_correct_subsidy_snapshot branch May 25, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database upgrade Issues and/or pull requests that involve a new database version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[rpcserver] getcoinsupply RPC is not reporting treasurybases
4 participants