bitcoin core – Failed to parse blk.dat file. Is this block legal?
A. Is this transaction and/or block legal?
Example – assuming you accept the segwit soft fork and the resulting options for serializing BIP144 format transactions.
B. If not, why is it in my blk.dat archive?
Not applicable: See above.
C. What is the transaction version? ffffffff
suggestion?
This is the noise that occurs when trying to read a Segwit TX using the dictionary Segwit parsing scheme.
D. Is scriptPubKey size a VarInt? fe80ffffff
correct?
No, this is also the noise that occurs when trying to read a Segwit tx using the dictionary Segwit parsing scheme.
E. What is the story of this block?
Per Pieter Wuille’s comment:
…the block you linked is the first segwit block (separated witness), a soft fork and associated protocol changes that introduced new block and transaction serialization formats. More details are specified in BIP144: github.com/bitcoin/bips/blob/master/bip-0144.mediawiki. I strongly suspect that’s what’s causing your parser to be abandoned.
The block I linked to was the second segwit block, but it was the first segwit block stored in my local .dat repository, so my parser hit it first.
BIP144 Link
To adjust the parser to allow segwit transactions, we had to add a conditional statement after reading the input count bytes. If this value is 1 0x00
It then processes the segwit transaction and reads the “flags” byte. 0x01
), actual input number of bytes. Lastly, you should also read the script witness.
before reading Locktime
Please read the following for each transaction entry.
NoStackItems <VarInt>
For each stack item:
SizeofStackItem <VarInt>
StackItem <SizeofStackItem bytes>
See also:
https://bitcoin.stackexchange.com/a/110810/34190 https://bitcoin.stackexchange.com/a/55234/34190