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 coin count and value statistics #960

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

braydonf
Copy link
Contributor

Closes #959

@pinheadmz
Copy link
Member

Importing the discussion from the issue:

Okay so #960 should resolve the issue for new synchronizations.

To fix existing synchronizations there could be:

A manual script that adjusts the values to decrease the txouts by 2 and total amount by 100. The script would need to be run only once and if necessary.
A database version upgrade and a migration script that will decrease the txouts by 2 and total amount by 100. This provides more automation.
A database version upgrade with paired with other database updates. Minimizes database upgrades.
Fixing existing versions are eventually handled by re-syncing. Considering it's a small fix, this is not very efficient.

We could copy the approach in this PR to Handshake for a similar issue:
https://github.com/handshake-org/hsd/pull/396/files
(add a migration ID to the DB and run it once automatically on boot)

@codecov-io
Copy link

codecov-io commented Mar 17, 2020

Codecov Report

Merging #960 into master will increase coverage by 0.01%.
The diff coverage is 91.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #960      +/-   ##
==========================================
+ Coverage   62.10%   62.12%   +0.01%     
==========================================
  Files         156      158       +2     
  Lines       26077    26095      +18     
==========================================
+ Hits        16195    16211      +16     
- Misses       9882     9884       +2     
Impacted Files Coverage Δ
lib/node/rpc.js 30.20% <ø> (ø)
lib/blockchain/internal/cache.js 86.84% <86.84%> (ø)
lib/blockchain/chaindb.js 74.29% <87.50%> (-2.64%) ⬇️
lib/blockchain/internal/records.js 94.25% <94.25%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6beb54d...7afc3c7. Read the comment docs.

@braydonf
Copy link
Contributor Author

braydonf commented Mar 17, 2020

Regarding migration, the existing db version and migration scripts could benefit from increased automation. There is an argument to not want the database to automatically upgrade, especially if it will take some time. So it may be useful to have a flag that can be sent at startup to perform automatic database upgrades, and would default to false. So instead of running the migration script manually, it could be to include a --migrate flag at startup or similar cli tool.

@pinheadmz
Copy link
Member

Update looks good, utACK for now @ 0a82ad9

@braydonf
Copy link
Contributor Author

braydonf commented Mar 18, 2020

Okay, I've started the migration script (untested) by adding it to the existing migration scripts. It should update the database version and fixes bip30 duplicate issues for existing databases. It was necessary to expose ChainState and ChainFlags for usage in the migration.

@braydonf
Copy link
Contributor Author

Also realized that, technically disconnectBlock will need to also have corresponding changes.

@braydonf
Copy link
Contributor Author

I've run a sync with the changes and it confirms it, and have the correct txouts count.

@braydonf
Copy link
Contributor Author

I've added corresponding code for disconnectBlock, it also applies to removing the coins, because the coins should still exist (for the duplicate).

@braydonf braydonf modified the milestones: next, v3.0.0 Mar 19, 2020
@braydonf braydonf changed the title blockchain: fix duplicate txout count Fix coin count and value statistics Mar 19, 2020
@braydonf braydonf added chain bug Unexpected or incorrect behavior labels Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior chain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coin count and value statistics are incorrect
3 participants