Why does the wallet keep a pointer to the best chain

1

When I run Bitcoin core to synchronize the blockchain without getting innvolved in any transaction, the wallet.dat gets written to nevertheless.

I believe this is the case because the wallet keeps track of the best chain. (However, I am not sure if this is the only change that is written to the wallet.)

Now, I am wondering why the wallet needs to keep track of the best chain. My possibly faulty understaning is that there is a consensus about the best chain which can be deduced from the blockchain. Hence, no seperate storing of it should be necessary.

René Nyffenegger

Posted 2017-07-05T09:35:57.637

Reputation: 217

Answers

2

I think it is necessary. The wallet doesn't just contain addresses. It also contains transactions that are sent to you.

Suppose you generate a wallet, then back it up. You receive a bunch of money. You delete the wallet on your computer, and restore the old wallet. How does Bitcoin know that it should rescan the blockchain for transactions sent to you? I don't think it can, unless the wallet contains a field that represents the current best chaintip.

If you don't want Bitcoin to ever write to the wallet, you can compile it with --disable-wallet.

Nick ODell

Posted 2017-07-05T09:35:57.637

Reputation: 26 536

Exactly. The best chain field in the wallet is so that the client knows what to rescan after a restore from backup.Pieter Wuille 2017-07-05T19:16:00.083