0

I'm catching all the deposit transactions with walletnotify and insert them into my database. Then on every blocknotify call I fetch all the transactions under 6 confirmations from the db and update them, specifically their confirmations. How do I catch the possible unconfirmed transactions, so the ones that got saved in the db when were first posted, but in the process were rejected/unconfirmed in the next 6 blocks. And also, I'm open to any recommendations on improving my existing system. Thanks

0

How do I catch the possible unconfirmed transactions, so the ones that got saved in the db when were first posted, but in the process were rejected/unconfirmed in the next 6 blocks.

There are two ways a transaction (TXID) is first introduced by walletnotify:

  • 1) Acceptance in mempool
  • 2) Confirmation in a block

A transaction in mempool has no guarantee of being mined, and a confirmed transaction may have never been previously seen in your local mempool. Therefore, you need to be able to differentiate between the two scenarios, and only store the transactions which actually receive confirmation.

Reorgs: Furthermore, there is no guarantee that a previously confirmed transaction receives confirmation from subsequent blocks. It is possible that subsequent blocks form a separate branch, so that your previously confirmed transaction is no longer in the strong chain. This is where incrementing confirmation with each new block as you describe will fail.

Better to verify the longest header chain (they must link together via prev header hash) and ensure that the transaction is included in this longest chain when computing the level of transaction confirmation. If this longest header chain reorganises, you can update the confirmations of all transactions accordingly.

  • So how would a transaction that was rejected or wasn't confirmed in the 'subsequent blocks' differ from the confirmed one in the output of gettransaction <txid> – zabbir Jan 26 at 19:34
  • I am not sure whether gettransaction <txid> returns transactions with confirmation field = 0. If it doesn't, that also tells you it isn't confirmed, but was accepted in your local mem-pool. – James C. Jan 27 at 8:51
  • It does, rgho.st/8rhMpLRsh. What if a transaction gets 2 confirmations and then gets rejected, how would it appear at gettransaction <txid> ? – zabbir Jan 28 at 4:38
  • Good question. Either 0 conf or not at all (TXID not found). The problem is you don't get any notification of a reorganisation, so you need to determine a reorganisation-event based on your header-chain, when new blocks are announced which don't extend the previous chain. – James C. Jan 28 at 6:42
  • Why would I want to catch these blocks? If transactions in them never get confirmed in my db: how would they be harmful? – zabbir Jan 30 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.