Add UTXO Snapshot Loading Interface and Progress Notifications
This PR implements a complete interface for loading UTXO snapshots through the GUI, including progress notifications to provide user feedback during the loading process.
Changes
Commit 1: interfaces: expose UTXO snapshot functionality (loading/activate) in node interface
- Added a new virtual method
snapshotto the node interface for loading UTXO snapshots from a path. - Added
snapshot.htosrc/interfacesdefining the Snapshot interface;activate()returnsutil::Result<const CBlockIndex*>to carry either the base block index on success or a descriptive error message on failure, matching the shape ofChainstateManager::ActivateSnapshot(). - Added a
getMetadataaccessor so callers can read snapshot metadata populated during activation without re-parsing the file. - Added
SnapshotImplin src/node/interfaces.cpp: opens the snapshot file, parses metadata, and forwards toChainstateManager::ActivateSnapshot(), propagating any error as util::Error{...}.
This change enhances the user's ability to load UTXO snapshots through the GUI and/or RPC.
Commit 2: notifications: Implement snapshot load progress notifications
- Added a new signal
SnapshotLoadProgressfor snapshot load progress in the UI interface. - Updated the notifications interface to include a method for reporting snapshot loading progress.
- Enhanced the
ChainstateManagerto report progress during snapshot loading. - Implemented the necessary handler in the kernel notifications to relay progress updates.
This change improves user feedback during the snapshot loading process.
Commit 3: rpc: refactor loadtxoutset to use snapshot interface
- Updated the
loadtxoutsetRPC to call the new snapshot interface instead of directly working with chainstate internals. File opening, metadata parsing, and activation now all happen insideinterfaces::Snapshot::activate()rather than being split between the RPC handler and the interface. - Removed the redundant pre-parse block in the RPC handler; its file-open and metadata-parse work duplicated what activate() already performs.
- Collapsed the RPC error handling to a single
RPC_INTERNAL_ERRORbuilt fromutil::ErrorString(activation_result).original, using the"Unable to load UTXO snapshot: %s. (%s)"format established in #30267 / #30395. - Read
coins_loadedfromsnapshot->getMetadata()afteractivate()populates it. - Updated
feature_assumeutxo.pyto assert on the unified error code for file-open and metadata-parse failures (message substrings unchanged). Improves modularity by consolidating snapshot handling through the interface layer.
Technical Details
The implementation includes:
UI Interface Enhancement Added
SnapshotLoadProgresssignal toCClientUIInterfacewith corresponding signal declaration and implementation.Node Interface Added
loadSnapshotvirtual method to the node interface with implementation ininterfaces.cpp.Progress Notifications Implemented
snapshotLoadProgressmethod inKernelNotificationsclass to relay progress updates to the UI.Base Interface Added
snapshotLoadProgressvirtual method to the kernel notifications interface.
Benefits
User Experience Provides real-time feedback during UTXO snapshot loading operations.
GUI Integration Enables loading UTXO snapshots directly through the Bitcoin Core GUI.
Progress Tracking Users can monitor the progress of snapshot loading operations.
Consistent Interface Follows the existing pattern for progress notifications in the codebase.
Testing
- Daemon build and launch
bitcoindthen withbitcoin-cliload a snapshot using:
./bitcoin-cli -rpcclienttimeout=0 -signet loadtxoutset /path/to/utxo-snapsshot.dat