Bitcoin Forum
December 04, 2016, 06:21:09 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Any way to know about a blockchain reorganization?  (Read 1876 times)
SgtSpike
Legendary
*
Offline Offline

Activity: 1344



View Profile
July 08, 2011, 11:08:00 PM
 #1

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.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2492


View Profile
July 08, 2011, 11:11:34 PM
 #2

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.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
SgtSpike
Legendary
*
Offline Offline

Activity: 1344



View Profile
July 08, 2011, 11:51:21 PM
 #3

Thanks theymos.  If blockexplorer does it that way, I'll take it that's the only way to find out.  Smiley
etotheipi
Legendary
*
expert
Offline Offline

Activity: 1428


Core Armory Developer


View Profile WWW
July 09, 2011, 02:23:10 PM
 #4

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?   


Founder and CEO of Armory Technologies, Inc.
Armory Bitcoin Wallet: Bringing cold storage to the average user!
Only use Armory software signed by the Armory Offline Signing Key (0x98832223)

Please donate to the Armory project by clicking here!    (or donate directly via 1QBDLYTDFHHZAABYSKGKPWKLSXZWCCJQBX -- yes, it's a real address!)
vector76
Member
**
Offline Offline

Activity: 70


View Profile
July 09, 2011, 02:33:55 PM
 #5

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.
etotheipi
Legendary
*
expert
Offline Offline

Activity: 1428


Core Armory Developer


View Profile WWW
July 09, 2011, 03:05:31 PM
 #6

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?


Founder and CEO of Armory Technologies, Inc.
Armory Bitcoin Wallet: Bringing cold storage to the average user!
Only use Armory software signed by the Armory Offline Signing Key (0x98832223)

Please donate to the Armory project by clicking here!    (or donate directly via 1QBDLYTDFHHZAABYSKGKPWKLSXZWCCJQBX -- yes, it's a real address!)
kjj
Legendary
*
Offline Offline

Activity: 1302



View Profile
July 10, 2011, 03:13:46 PM
 #7

If you watch the debug.log, you should see a "REORGANIZE" message come across too.

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
bfever
Jr. Member
*
Offline Offline

Activity: 39


View Profile WWW
July 10, 2011, 08:37:23 PM
 #8

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):
  • The new block has a previous hash that you already have in your database (most probably references block N-1, the start of a fork). You can either choose to ignore this new block (as you already have a block chain that is longer or same length), OR you can drop all blocks up to the previous hash of the new block and append this new block as usual.
  • The new block has a previous hash "PH" that doesn't correspond to any of your current block hashes. This means there is/was a fork and your part of the bitcoin network did not get one or more blocks of the other branch. You will have to ask with a "getblock" message the block X with this hash "PH" and check if the previous hash in this block X is a hash you know of. If so, you can reconstruct this branch (and like in the first possibility decide what branch to keep), if not you'll have to do a "getblock" again (and loop until you get a known hash).

Use your freedom, use bitcoins !

Bitcoin Relational Database (in MySQL) aka The BiRD now available.
Universal Bitcoin Smartcard coming soon.

UBiCard - BiRD donations: 1UbicardpLQiAhGfEWKaV5xnKkmgzj1Ce
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!