The HTTP request and response are both handled entirely in-memory, thus making maximum memory usage at least 2.66MB (1 MB max block, plus hex encoding) per request.
Now with SegWit up to 4 MB, is it 10.66 MB?
The HTTP request and response are both handled entirely in-memory, thus making maximum memory usage at least 2.66MB (1 MB max block, plus hex encoding) per request.
Now with SegWit up to 4 MB, is it 10.66 MB?
https://medium.com/@jimmysong/understanding-segwit-block-size-fd901b87c9d4
Loved your article 50👏 , It was very informative!
I think there are a few more things to consider here. First of all, I can’t really make sense of the 2.66MB number. From my understanding, it should be 3 MB if we are talking about Hex. 1 MB is the full block that gets loaded into memory before the processing. Then, it might get processed into hex which is the less efficient encoding format where 1 byte binary takes 2 bytes in hex. I think this is right because HexStr
is also reserving twice the space here: https://github.com/bitcoin/bitcoin/blob/b6a5dc90bfd4640cf9f914e59bf8e21cd265b51e/src/util/strencodings.h#L128
But then there is also the JSON option and that should add way more overhead than a hex encoding. I just did a quick check if I am missing something with a recent block to make sure I am not missing something and this looks right:
0$ ls -hla | grep 5694ce
1-rw-r--r--@ 1 XXX XXX 1.2M Apr 22 01:57 00000000000000000011fbefe97f501a0160a2c86201ef5ef79e1cd2ce5694ce.bin
2-rw-r--r--@ 1 XXX XXX 2.4M Apr 22 01:56 00000000000000000011fbefe97f501a0160a2c86201ef5ef79e1cd2ce5694ce.hex.txt
3-rw-r--r--@ 1 XXX XXX 8.0M Apr 22 01:53 00000000000000000011fbefe97f501a0160a2c86201ef5ef79e1cd2ce5694ce.json
@michaelfolkson mentioned block weight, but I think this would not be the right term to talk about here because the weight is a theoretical term used to calculate fees and when a block is considered full but it only has an indirect influence on the space used in memory. I would say the term weight was actually introduced to create a disconnect between the space that the block uses in memory and measuring when a block is full. (Edit: I should probably call it a direct influence but the point is you can’t tell the block size in memory from the block weight)
But this disconnect also makes it much harder to give a good estimate of what size to expect. 4 MB is the theoretical max size of a Segwit block, but even with increasing Segwit adoption, I would say a 2 MB block would be huge. We are currently at 1.2 -1.3 MB usually: https://bitcoinvisuals.com/chain-block-size.
So what number to take? If I had to make a guess it would be ~10 MB worst case for the foreseeable future (big Segwit block with JSON). But really I would rather suggest removing that number, I am not sure how much relevance it has. If I am right and the number was off all this time, then I guess nobody noticed it because of that ;) But I am also not a regular rest interface user and looked at that code for the first time today, so don’t take my word for it.
Anyway, if anyone wants to open a PR for this I would suggest looking for more inconsistencies in the docs and the rest code and put them together. Looking at rest.cpp
this error string seems to be missing the json
option for example: https://github.com/bitcoin/bitcoin/blob/b6a5dc90bfd4640cf9f914e59bf8e21cd265b51e/src/rest.cpp#L209
But really I would rather suggest removing that number, I am not sure how much relevance it has.
Agree with @fjahr that the number should be removed. No documentation is better than wrong documentation.