Skip to content

feat(#1722) : add initial wallet height setting to avoid rescanning from genesis#2278

Open
dimension-drifter wants to merge 1 commit intoergoplatform:masterfrom
dimension-drifter:fix/issue-1722
Open

feat(#1722) : add initial wallet height setting to avoid rescanning from genesis#2278
dimension-drifter wants to merge 1 commit intoergoplatform:masterfrom
dimension-drifter:fix/issue-1722

Conversation

@dimension-drifter
Copy link

Problem:
Currently, when a wallet is initialized (/wallet/init) or restored (/wallet/restore), the node wallet re-scans the blockchain from height 0 (genesis). This is unnecessary and inefficient, especially for nodes with long blockchain histories.

Root Cause:
The initWallet and restoreWallet methods call recreateRegistry() which deletes and recreates the wallet registry database. The new registry starts at height 0 (EmptyHistoryHeight). When new blocks arrive after wallet initialization, the wallet attempts to scan from height 1 onwards, effectively rescanning the entire blockchain.

Solution:
Set the wallet registry height to the current blockchain height immediately after recreating the registry during wallet initialization/restoration. This ensures the wallet only scans new blocks going forward, not historical blocks.

Changes
:

  • [WalletRegistry.scala]: Added setInitialHeight(height: Int) method to set the wallet height without balance changes
  • [ErgoWalletService.scala]: Modified recreateRegistry() to call setInitialHeight() with the current blockchain height (state.fullHeight)

Behavior
:

  • Before: Wallet initialized at height 0, rescans all blocks from genesis
  • After: Wallet initialized at current blockchain height, only scans new blocks

This is the correct behavior because:

  • A newly initialized wallet has no prior transaction history to discover
  • A restored wallet should use the /wallet/rescan endpoint if historical transactions need to be recovered
  • Users can explicitly call /wallet/rescan with fromHeight: 0 if they want to scan from genesis

@dimension-drifter dimension-drifter changed the title feat (#1722) : add initial wallet height setting to avoid rescanning from genesis feat : add initial wallet height setting to avoid rescanning from genesis Dec 14, 2025
@dimension-drifter dimension-drifter changed the title feat : add initial wallet height setting to avoid rescanning from genesis feat(#1722) : add initial wallet height setting to avoid rescanning from genesis Dec 14, 2025
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.

1 participant