MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.86k stars 844 forks source link

Litecoin RPC `GetBlock()` throws `System.FormatException: Unknown Transaction optional data` for some blocks #1108

Closed rvnlord closed 1 year ago

rvnlord commented 2 years ago

There is a bug with Litecoin serializer which will throw System.FormatException: Unknown Transaction optional data for some transactions in some blocks. To reproduce run:

var customHash = (await Rpc.GetBlockHeaderAsync(2284382)).GetHash();
var block = await Rpc.GetBlockAsync(customHash);

or

var resp = await Rpc.SendCommandAsync(RPCOperations.getblock, CancellationToken.None, customHash, false);
var block2 = Network.Main.Consensus.ConsensusFactory.CreateBlock();
var s = new BitcoinStream(new MemoryStream(Encoders.Hex.DecodeData(resp.ResultString)), false) { ConsensusFactory = Network.Main.Consensus.ConsensusFactory };
block2.ReadWrite(s);

Example transaction that causes the problem can be found in block 2284382 with 3bed06209f382e20f7b4eb1724366835874769763744d3cc429182422c8e7950 hash.

NicolasDorier commented 2 years ago

@rvnlord can you copy the transaction's hex here?

rvnlord commented 2 years ago

02000000000801d0e493224859b9210af6f88791365b2d40fe45099feeff1474bbc69c5e9200060000000000ffffffff0112bab955d700000022582073a2485a7c127ffca4e0c39484a5145307ea86771f57b6a87be195a3813e3f2e0000000000

twilightrus commented 2 years ago

+1 @NicolasDorier

NicolasDorier commented 1 year ago

Should be fixed https://github.com/MetacoSA/NBitcoin/issues/1125 was caused by a hardfork of ltc