bitcoin-kit-ios
bitcoin-kit-ios copied to clipboard
Dash synchronisation stuck in an infinite loop
I have a Dash wallet that stops the synchronisation when it arrives to this transaction
https://blockchair.com/es/dash/transaction/3cc6e81dbb258a6fb88fb46e35b0a8e6e6c77fd4699d4a8100b9c700a5a7b3de
This transaction comes from Dash masternode, and it has a coinbase input, I believe that DashKit doesn't support this type of inputs and it gets stuck in an infinite loop.
https://dashcore.readme.io/docs/core-ref-transactions-raw-transaction-format#coinbase-input-the-input-of-the-first-transaction-in-a-block
I think the problem is because the datahash is not being calculated correctly for coinbase transactions and after the transactionis not found in the block.
The datahash is calculated in struct FullTransaction
public init(header: Transaction, inputs: [Input], outputs: [Output]) {
...
self.header.dataHash = Kit.sha256sha256(TransactionSerializer.serialize(transaction: self, withoutWitness: true))
...
}
but for coinbase transaction there are more fields.
I fix the problem moving the calculation of datahash to method deserialize in the class TransactionSerializer
static public func deserialize(byteStream: ByteStream) -> FullTransaction {
transaction.lockTime = Int(byteStream.read(UInt32.self))
transaction.dataHash = Kit.sha256sha256(byteStream.data)
return FullTransaction(header: transaction, inputs: inputs, outputs: outputs)
}
The problem is not completely solved, now only takes into account the last coinbase transaction, other coinbase transactions are ignored.
This type of input always have the same txid
0000000000000000000000000000000000000000000000000000000000
and only the last is stored in database
This type of input always have the same txid
0000000000000000000000000000000000000000000000000000000000
and only the last is stored in database
I'm wrong is not txid, is previousOutputTxHash .
For coinbase input previousOutputTxHash always have the value 0x0000000000000000000000000000000000000000000000000000000000, if you have multiple coinbase transactions only the last transaction input is stored, and other transactions are invalidated.
Fixed in #607, #608
With this changes only stores last coinbase transaction