bitcoin-kit-ios icon indicating copy to clipboard operation
bitcoin-kit-ios copied to clipboard

Dash synchronisation stuck in an infinite loop

Open fpcornelis opened this issue 2 years ago • 6 comments

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

fpcornelis avatar Jul 04 '22 09:07 fpcornelis

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)
    }

fpcornelis avatar Jul 05 '22 11:07 fpcornelis

The problem is not completely solved, now only takes into account the last coinbase transaction, other coinbase transactions are ignored.

fpcornelis avatar Jul 11 '22 13:07 fpcornelis

This type of input always have the same txid

0000000000000000000000000000000000000000000000000000000000

and only the last is stored in database

fpcornelis avatar Jul 21 '22 08:07 fpcornelis

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.

fpcornelis avatar Jul 29 '22 14:07 fpcornelis

Fixed in #607, #608

ealymbaev avatar Aug 01 '22 04:08 ealymbaev

With this changes only stores last coinbase transaction

fpcornelis avatar Aug 01 '22 08:08 fpcornelis