Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for variable length headers #128

Closed
erasmospunk opened this issue Feb 17, 2017 · 11 comments
Closed

Add support for variable length headers #128

erasmospunk opened this issue Feb 17, 2017 · 11 comments
Labels

Comments

@erasmospunk
Copy link
Contributor

erasmospunk commented Feb 17, 2017

In order to support coins like Dogecoin, Namecoin (AuxPow #127, #83) and Zcash that hash a different header format.

The common pattern in the above coins is that the header is of variable size. The way I quickly solved it for Zcash using the original electrum-server and set the header size to 2048 bytes and filled the unused space with 0x00. This is not very efficient as space is wasted but it does the job.

An alternative is to use db backend to save the headers as height -> header_bytes. However this will complicate the serving the headers for the blockchain.block.get_chunk command.

One simple fix it to store the headers as before but additionally store the header offset and size in db as height -> header_offset: u32, header_size: u32.

We would need to modify the Coin::header_offset and ::header_len by adding an optional Storage instance so that the specific coin type can calculate it's own header size. I am not sure how to handle this from the async point of view as the disk access will lock the thread.

Let me know what you think.

@erasmospunk
Copy link
Contributor Author

It seems that the LogicalFile for saving the header_offset and header_size values is the better option.

@kyuupichan
Copy link
Owner

if you're saving a linear array, which we surely are here, then yes the logical file setup is the way to go. ElectrumX uses that for tx counts by block and for headers themselves.

@kyuupichan
Copy link
Owner

I think only saving header offsets is enough. Getting two in a row to determine the size is not going to be an issue.

@erasmospunk
Copy link
Contributor Author

erasmospunk commented Feb 17, 2017

@kyuupichan you mean to parse the header to determine the size? Yeah, that is a good compromise. Dogecoin that currently has ~1600000 blocks, the extra data we will store is only 6.4MiB.

Alright, will get to work.

@kyuupichan
Copy link
Owner

Maybe we're misunderstanding each other. My point was that there's no point storing an array of offsets and lengths for each header - if you have an array of offsets, you get the length by subtracting the next value from the current.

This is what I do for tx counts in ElectrumX at present.

@kyuupichan
Copy link
Owner

@erasmospunk and I store the full array in RAM; as long as it doesn't exceed 4 bytes per block I think that's quite reasonable to do for header offsets too.

@erasmospunk
Copy link
Contributor Author

@kyuupichan now I understood what you mean, I see that header_len is calculated from header_offset only.

@erasmospunk
Copy link
Contributor Author

erasmospunk commented Feb 23, 2017

@kyuupichan some initial work here that fixes Namecoin and Dogecoin. Next I will try to support Zcash.

Let me know if some things should be done differently.

ps. How to calculate TX_PER_BLOCK?

@kyuupichan
Copy link
Owner

TX_PER_BLOCK is just used to estimate sync times in logs for the user. For bitcoin I made it the average TX count of the most recent 5k blocks or something like that. Doesn't have to be correct, it will just give worse ETAs, which are only very roughly correct anyway. Bitcoin testnet is a mess and giving sane ETAs there is almost impossible.

@erasmospunk
Copy link
Contributor Author

Just force pushed the Zcash support

@erasmospunk
Copy link
Contributor Author

Created the pull request #140, will close this issue once merged.

erasmospunk added a commit to erasmospunk/electrumx that referenced this issue Mar 15, 2017
Block headers can have a dynamic size that is being indexed on a
new meta file "headers_offsets".

The offsets are 64 bits in order to accommodate coins with big
headers that will accumulate GBs of header data after some years.

Closes kyuupichan#128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants