Bitcoin Forum
April 25, 2024, 08:13:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Any way to know about a blockchain reorganization?  (Read 2363 times)
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



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.
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714032839
Hero Member
*
Offline Offline

Posts: 1714032839

View Profile Personal Message (Offline)

Ignore
1714032839
Reply with quote  #2

1714032839
Report to moderator
1714032839
Hero Member
*
Offline Offline

Posts: 1714032839

View Profile Personal Message (Offline)

Ignore
1714032839
Reply with quote  #2

1714032839
Report to moderator
1714032839
Hero Member
*
Offline Offline

Posts: 1714032839

View Profile Personal Message (Offline)

Ignore
1714032839
Reply with quote  #2

1714032839
Report to moderator
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12884


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 (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



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
Merit: 1093


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
Merit: 18


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
Merit: 1093


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
Merit: 1024



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.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
bfever
Jr. Member
*
Offline Offline

Activity: 39
Merit: 1


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).
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!