Title: Any way to know about a blockchain reorganization? Post by: SgtSpike on July 08, 2011, 11:08:00 PM If the blockchain gets changed, is there any way to notify about it? Reason being, I have a database being written to based off of every new block that arrives, so if one of the older blocks changes, I'd like to know about it.
Title: Re: Any way to know about a blockchain reorganization? Post by: theymos on July 08, 2011, 11:11:34 PM The way Bitcoin Block Explorer detects it is by getting some previous blocks that are already in the database and seeing if they've changed.
Title: Re: Any way to know about a blockchain reorganization? Post by: SgtSpike on July 08, 2011, 11:51:21 PM Thanks theymos. If blockexplorer does it that way, I'll take it that's the only way to find out. :)
Title: Re: Any way to know about a blockchain reorganization? Post by: etotheipi on July 09, 2011, 02:23:10 PM Can someone please explain why/how the blockchain would be "reorganized" ? Are we talking about invalid blocks that were originally accepted but now have to be discarded?
Title: Re: Any way to know about a blockchain reorganization? Post by: vector76 on July 09, 2011, 02:33:55 PM Previous blocks can change?
I thought reorganization happened when there was a fork in the block chain and the longest/best fork got surpassed by the other fork. Then the transactions in the (now) shorter chain are undone and the transactions in the longer chain are applied. Title: Re: Any way to know about a blockchain reorganization? Post by: etotheipi on July 09, 2011, 03:05:31 PM As far as I'm aware, this only happens in two cases:
1) The rare case of simultaneously transmitted blocks where 1 of those blocks will end up invalid and discarded 2) Someone pulls off a double-spending attack where they build a competing chain faster than the rest of the network, after someone has already accepted a huge payment from them in the original chain. The attacker broadcasts the longer chain and all the miners switch to it because it's longer. Are there other cases? Title: Re: Any way to know about a blockchain reorganization? Post by: kjj on July 10, 2011, 03:13:46 PM If you watch the debug.log, you should see a "REORGANIZE" message come across too.
Title: Re: Any way to know about a blockchain reorganization? Post by: bfever on July 10, 2011, 08:37:23 PM If the block chain gets changed, is there any way to notify about it? Reason being, I have a database being written to based off of every new block that arrives, so if one of the older blocks changes, I'd like to know about it. The "older blocks" won't actually change. When a block chain forks, and you happen to be on the false part of it when one of the forks becomes the "longest", all your blocks from the fork up are simply no longer valid (and all transactions contained in it). You don't get a direct notification of it, but you can "easily" know when there is/was a fork, because the new block you receive will NOT reference the latest block you have in your database. In fact, there are 2 possibilities (current block height in your database is N):
|