-
Notifications
You must be signed in to change notification settings - Fork 37.7k
UTXO snapshot creation (dumptxoutset) #16899
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
Conversation
fd56894
to
e30e3a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
What was the conclusion on the question whether the dump should include all headers? |
e30e3a4
to
0705b18
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
a71a387
to
6452a87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the conclusion on the question whether the dump should include all headers?
We need to connect to peers to make the node usable anyway, and headers take very little time to sync, so I don't see much benefit to bundling the headers with the snapshot. Though if anyone thinks differently I'd be curious to hear why.
6452a87
to
52bba3c
Compare
test/functional/rpc_dumptxoutset.py
Outdated
|
||
# TODO I'd like to make assertions about the contents of the file | ||
# (ideally its hash), but because we can't get a deterministic block | ||
# header (we'd need to mock time) and we have no way of deserializing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you use mock time here?
Also, the test isn't running (see travis)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get a deterministic blockheader, we'd need to use GetTime<...>()
here: https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp#L93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that nTimeStart
is only used for logging benchmarks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah oops, you're totally right. Will try with mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 52bba3c
{ | ||
RPCHelpMan{ | ||
"dumptxoutset", | ||
"\nWrite the serialized UTXO set to disk.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "rpc: add dumptxoutset" (b6af8f5)
Up to you, but I think documentation could say more about
- Data format
- What you'd use this function for, or it's mostly meant to be useful for developers
- Status of the implementation. If this is experimental, whether the data format might change, if there's going to be a corresponding load rpc method
pcursor->Next(); | ||
} | ||
|
||
afile.fclose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "rpc: add dumptxoutset" (b6af8f5)
Implementation seems fine for now. Unclear if in the future we might want to:
- Put some magic bytes in snapshot header so to make it easier to recognize a snapshot file
- Add version or length fields to make it possible to extend the format and include additional data
- Write to temporary file and then rename in case theres a shutdown or crash in the middle of writing so you can distinguish an incomplete snapshot from a complete one
2894d3e
to
c2830a9
Compare
A progress indicator would be nice. If it wasn't for the system activity monitor showing CPU and disk write activity I would have interrupted the script somewhere during the ~ half an hour Maybe the script should call Checksum on macOS 10.14.6 for block 597000: {
"coins_written": 62228899,
"base_hash": "0000000000000000000eadb01d27f7b6ca1c17e71f0ff33853de9d3b25c57e55",
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK c2830a9. Changes since last review: new utxo_snapshot.h file, removed hash and validation_complete snapshot metadata fields, fixed dumptxoutset base_height documentation, dumped to temporary file and renamed instead of writing directly, extended rpc_dumptxoutset test removing todo
2a4e60b Fix block index inconsistency in InvalidateBlock() (Suhas Daftuar) Pull request description: Previously, we could release `cs_main` while leaving the block index in a state that would fail `CheckBlockIndex()`, because `setBlockIndexCandidates` was not being fully populated before releasing `cs_main`. ACKs for top commit: TheBlueMatt: utACK 2a4e60b. I also discovered another issue in InvalidateBlock while reviewing, see #16856. Sjors: ACK 2a4e60b. Tested on top of #16899. Also tested `invalidateblock` with `-checkblockindex=1`. fjahr: ACK 2a4e60b. Ran tests, reviewed code, inspected behavior while manually testing `invalidateblock`. Tree-SHA512: ced12f9dfff0d413258c709921543fb154789898165590b30d1ee0cdc72863382f189744f7669a7c924d3689a1cc623efdf4e5ae3efc60054572c1e6826de612
0efd43d
to
95c7f5e
Compare
src/rpc/blockchain.cpp
Outdated
Coin coin; | ||
|
||
while (pcursor->Valid()) { | ||
boost::this_thread::interruption_point(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no point in adding a boost interruption point here. RPC threads aren't managed by a boost thread group.
Check IsRPCRunning()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah if that's the case then we should fix FindScriptPubKey
at some point too. https://github.com/bitcoin/bitcoin/blob/master/src/rpc/blockchain.cpp#L1970-L1978
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't mind fixing it in this pull in a new commit. It seem like you copy-pasted the code from there, so it wouldn't hurt review if people saw where the code came from
95c7f5e test: add dumptxoutset RPC test (James O'Beirne) ddc90a8 devtools: add utxo_snapshot.sh (James O'Beirne) 49f281b rpc: add dumptxoutset (James O'Beirne) 644c7e7 coinstats: add coins_count (James O'Beirne) 707fde7 add unused SnapshotMetadata class (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: bitcoin#15606 Issue: bitcoin#15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them, `dumptxoutset`. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain via `invalidateblock`. All of this is unused at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 95c7f5e. Changes since last review: rebase, more stable setmocktime call
95c7f5e
to
53bae65
Compare
Removed used of |
Also changes existing CCoinsStats attributes to be C++11 initialized.
53bae65
to
4ebc0c1
Compare
Allows the creation of a UTXO snapshot to disk.
to allow easy (if not time-consuming) generation and verification of snapshots.
4ebc0c1
to
92b2f53
Compare
We should remove all uses of ACK 92b2f53 |
92b2f53 test: add dumptxoutset RPC test (James O'Beirne) c1ccbc3 devtools: add utxo_snapshot.sh (James O'Beirne) 57cf74c rpc: add dumptxoutset (James O'Beirne) 92fafb3 coinstats: add coins_count (James O'Beirne) 707fde7 add unused SnapshotMetadata class (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them, `dumptxoutset`. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain via `invalidateblock`. All of this is unused at the moment. ACKs for top commit: laanwj: ACK 92b2f53 Tree-SHA512: 200dff87767f157d627e99506ec543465d9329860a6cd49363081619c437163a640a46d008faa92b1f44fd403bfc7a7c9e851c658b5a4849efa9a34ca976bf31
echo | ||
echo 'Examples:' | ||
echo | ||
echo " ./contrib/devtools/utxo_snapshot.sh 570000 utxo.dat ./src/bitcoin-cli -datadir=\$(pwd)/testdata" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm making a snapshot at height 600000, will share a torrent link later.
Post merge ACK. Good stuff @jamesob |
PIVOT_BLOCKHASH=$($BITCOIN_CLI_CALL getblockhash $(( GENERATE_AT_HEIGHT + 1 )) ) | ||
|
||
(>&2 echo "Rewinding chain back to height ${GENERATE_AT_HEIGHT} (by invalidating ${PIVOT_BLOCKHASH}); this may take a while") | ||
${BITCOIN_CLI_CALL} invalidateblock "${PIVOT_BLOCKHASH}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For others trying this: it's best to call setnetworkactive false
first
92b2f53 test: add dumptxoutset RPC test (James O'Beirne) c1ccbc3 devtools: add utxo_snapshot.sh (James O'Beirne) 57cf74c rpc: add dumptxoutset (James O'Beirne) 92fafb3 coinstats: add coins_count (James O'Beirne) 707fde7 add unused SnapshotMetadata class (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: bitcoin#15606 Issue: bitcoin#15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them, `dumptxoutset`. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain via `invalidateblock`. All of this is unused at the moment. ACKs for top commit: laanwj: ACK 92b2f53 Tree-SHA512: 200dff87767f157d627e99506ec543465d9329860a6cd49363081619c437163a640a46d008faa92b1f44fd403bfc7a7c9e851c658b5a4849efa9a34ca976bf31
Summary: * add unused SnapshotMetadata class * coinstats: add coins_count Also changes existing CCoinsStats attributes to be C++11 initialized. * rpc: add dumptxoutset Allows the creation of a UTXO snapshot to disk. * devtools: add utxo_snapshot.sh to allow easy (if not time-consuming) generation and verification of snapshots. * test: add dumptxoutset RPC test This is a backport of Core [[bitcoin/bitcoin#16899 | PR16899]] Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D7945
92b2f53 test: add dumptxoutset RPC test (James O'Beirne) c1ccbc3 devtools: add utxo_snapshot.sh (James O'Beirne) 57cf74c rpc: add dumptxoutset (James O'Beirne) 92fafb3 coinstats: add coins_count (James O'Beirne) 707fde7 add unused SnapshotMetadata class (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: bitcoin#15606 Issue: bitcoin#15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them, `dumptxoutset`. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain via `invalidateblock`. All of this is unused at the moment. ACKs for top commit: laanwj: ACK 92b2f53 Tree-SHA512: 200dff87767f157d627e99506ec543465d9329860a6cd49363081619c437163a640a46d008faa92b1f44fd403bfc7a7c9e851c658b5a4849efa9a34ca976bf31
2a4e60b Fix block index inconsistency in InvalidateBlock() (Suhas Daftuar) Pull request description: Previously, we could release `cs_main` while leaving the block index in a state that would fail `CheckBlockIndex()`, because `setBlockIndexCandidates` was not being fully populated before releasing `cs_main`. ACKs for top commit: TheBlueMatt: utACK 2a4e60b. I also discovered another issue in InvalidateBlock while reviewing, see bitcoin#16856. Sjors: ACK 2a4e60b. Tested on top of bitcoin#16899. Also tested `invalidateblock` with `-checkblockindex=1`. fjahr: ACK 2a4e60b. Ran tests, reviewed code, inspected behavior while manually testing `invalidateblock`. Tree-SHA512: ced12f9dfff0d413258c709921543fb154789898165590b30d1ee0cdc72863382f189744f7669a7c924d3689a1cc623efdf4e5ae3efc60054572c1e6826de612
2a4e60b Fix block index inconsistency in InvalidateBlock() (Suhas Daftuar) Pull request description: Previously, we could release `cs_main` while leaving the block index in a state that would fail `CheckBlockIndex()`, because `setBlockIndexCandidates` was not being fully populated before releasing `cs_main`. ACKs for top commit: TheBlueMatt: utACK 2a4e60b. I also discovered another issue in InvalidateBlock while reviewing, see bitcoin#16856. Sjors: ACK 2a4e60b. Tested on top of bitcoin#16899. Also tested `invalidateblock` with `-checkblockindex=1`. fjahr: ACK 2a4e60b. Ran tests, reviewed code, inspected behavior while manually testing `invalidateblock`. Tree-SHA512: ced12f9dfff0d413258c709921543fb154789898165590b30d1ee0cdc72863382f189744f7669a7c924d3689a1cc623efdf4e5ae3efc60054572c1e6826de612
This is part of the assumeutxo project:
Parent PR: #15606
Issue: #15605
Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal
This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them,
dumptxoutset
. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain viainvalidateblock
.All of this is unused at the moment.