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

[CHIA-1927] add tool to roll-back a blockchain database file to a previous height #806

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Nov 29, 2024

if --rollback is not specified, prints the peak height and hash.

If --rollback is specified with a height lower than the current peak, the database is updated like this:

  • the peak is updated to point to the block at the specified height
  • all blocks with a height greater than the new peak are marked as in_main_chain=0
  • all coins created after the new peak are deleted from the coin_records table
  • all coins spent after the new peak are marked as unspent

Example use:

cargo run --release --bin rollback-blockchain-db -- --rollback 6255740 ~/.chia/mainnet/db/blockchain_v2_mainnet.sqlite

Example output:

opening blockchain database file: /home/arvid/.chia/mainnet/db/blockchain_v2_mainnet.sqlite
peak height: 6267502
peak hash: 9fb57e29c398ffa69895d31a81af033e7a10cbf37625dcecd52307dfbefaa467
Rolling back to height 6255740
updating new peak to 9fb57e29c398ffa69895d31a81af033e7a10cbf37625dcecd52307dfbefaa467
clearing in_main_chain for all blocks with height above 6255740
deleting all coins created after height 6255740
unspending all coins spent after height 6255740

Copy link

Pull Request Test Coverage Report for Build 12084580048

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.054%

Totals Coverage Status
Change from base Build 12070655746: 0.0%
Covered Lines: 13004
Relevant Lines: 15471

💛 - Coveralls

@arvidn arvidn changed the title add tool to roll-back a blockchain database file to a previous height [CHIA-1927] add tool to roll-back a blockchain database file to a previous height Nov 29, 2024
@arvidn arvidn requested a review from AmineKhaldi December 2, 2024 11:39
Copy link
Contributor

@AmineKhaldi AmineKhaldi left a comment

Choose a reason for hiding this comment

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

Is there anything preventing us from having these queries as part of a chia db command (chia db rollback for example) so that it can conveniently benefit the community right from the chia-blockchain repo?

@arvidn
Copy link
Contributor Author

arvidn commented Dec 2, 2024

Is there anything preventing us from having these queries as part of a chia db command (chia db rollback for example) so that it can conveniently benefit the community right from the chia-blockchain repo?

It would be more work and I don't think it's a priority. the community can use this tool too

@arvidn arvidn merged commit d0540f1 into main Dec 4, 2024
52 checks passed
@arvidn arvidn deleted the rollback-db branch December 4, 2024 22:40
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.

3 participants