What's the most efficient way to detect a fork in the blockchain?

My app polls for changes to user deposit addresses on each new block.

Deposits are credited to user accounts with a record in a database then the funds are transfered to cold storage.

When users get refunds those refunds come from the cold storage and a record is added to the database.

My concern is the following happening:

  • User deposits Btc and the database record is created.
  • Chain is forked from 51% attack or software incompatability.
  • User gets refund from cold storage but I no longer have access to the funds they sent so its out of my pocket.

It seems that everything but rechecking every deposit is marginally risky.

If I rely on height plus hash that can be manufactured by the attacker so the new chain looks like the old chain.

  • I'm not completely sure what you have in mind when you say "height plus hash". But note that a different fork of the chain will necessarily have different blocks with different hashes. (Unless the attacker has managed to break sha256, in which case we all have bigger problems anyway.) Commented Apr 15, 2014 at 15:04

2 Answers 2


Maybe you can arrange it such that a refund always uses the TxOut of the transaction with which it came into the cold storage? Basically giving the user the same bitcoins back.

If a fork causes the funds not to go into cold storage they will not be going out either.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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