Bitcoin Forum

Bitcoin => Electrum => Topic started by: LoyceV on August 10, 2023, 07:46:20 AM



Title: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: LoyceV on August 10, 2023, 07:46:20 AM
See this image:
https://loyce.club/other/blockchain_headers.png
Electrum's file blockchain_headers is larger than the disk space it occupies (on a Linux system).
How can this be? Normally, files take slightly more space on disk (because of the disk block size), not less.


Title: Re: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: Learn Bitcoin on August 10, 2023, 07:48:38 AM
See this image:
https://loyce.club/other/blockchain_headers.png
Electrum's file blockchain_headers is larger than the disk space it occupies (on a Linux system).
How can this be? Normally, files take slightly more space on disk (because of the disk block size), not less.

Probably Compressed in some way?
This is the only thing that might make sense.
I do not see any other possible way it can take less space.


Title: Re: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: LoyceV on August 10, 2023, 08:05:06 AM
Probably Compressed in some way?
Nope, my file system doesn't support compression.


Title: Re: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: Zaguru12 on August 10, 2023, 08:24:49 AM
Probably Compressed in some way?
Nope, my file system doesn't support compression.

The major answer to this is when there is automatic or inbuilt compression gotten from one’s operating system or again if the file in question is a sparse file (https://learn.microsoft.com/en-us/windows/win32/fileio/sparse-files)


Title: Re: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: LoyceV on August 10, 2023, 08:30:25 AM
The major answer to this is when there is automatic or inbuilt compression gotten from one’s operating system
Nope.

Quote
or again if the file in question is a sparse file (https://learn.microsoft.com/en-us/windows/win32/fileio/sparse-files)
That's a Microsoft link, but you may be on to something: "sparse files" exist on ETX4 (https://serverfault.com/questions/981766/how-to-write-a-sparse-linux-ext4-disk-image-without-writing-gigabytes-of-zeros) too. It looks like that's what Electrum is doing, there must be a lot of empty space in the file. That brings the next question: why not just delete the empty space?


Title: Re: [Linux Electrum] Why is "blockchain_headers" larger than it's Size on Disk?
Post by: ranochigo on August 10, 2023, 03:27:54 PM
That's a Microsoft link, but you may be on to something: "sparse files" exist on ETX4 (https://serverfault.com/questions/981766/how-to-write-a-sparse-linux-ext4-disk-image-without-writing-gigabytes-of-zeros) too. It looks like that's what Electrum is doing, there must be a lot of empty space in the file. That brings the next question: why not just delete the empty space?
It is indeed a sparse file. Electrum actually has a function that marks it as such in their util.py: https://github.com/spesmilo/electrum/blob/dfa0dd47b728d22a3b8143af4bdd1819a0997abd/electrum/util.py#L490.

A good bulk of the headers file consists of zeros, and they only need to store the headers beyond the latest checkpoint, CMIIW on this but that is how I remember it when checking out their codes. Might have to do with the way that they retrieve the headers, and thats why the zero data is necessary.