Since bitcoin validates blockchain by the hash of older blocks recursively; Can I just keep the last blk*.dat file and delete the rest while the bitcoin core is downloading and validating the blockchain?
No, if you manually delete these files, Bitcoin Core will notice the missing files and abort.
However, Bitcoin Core does have functionality to discard blocks after validating them: pruning. You can enable pruning by setting
prune=<n> in your
bitcoin.conf file or by passing
bitcoind on startup.
bitcoind -h for more information, but briefly:
prune=1allows for manually deleting blocks using the
prune=<some number >= 550>enables your node to automatically delete blocks to keep the size, measured in MiB, less than the number specified
A few things to keep in mind when pruning:
- You cannot run
txindexwhile pruning, so you won't be able to use your node to lookup specific transactions
- If you ever want to turn pruning off, you will need to re-download the entire blockchain