29

Bitcoin's block chain system is really two quite separate systems, and they are easily confused. The first one is the block tree and the second is the active chain. The block tree consists of all valid blocks whose entire ancestry is known, up to the genesis block. The rules for validness include no double spending, valid signatures, no introduction of more ...


23

Gary's answer is not entirely correct. When comparing two chains, their total "scores" are compared. Each block counts as (2^256 / block_target); this is the expected/average number of attempts that were necessary to create it. Obviously, within one series of 2016 blocks, the difficulties are all equal, so for most small reorganizations, the score will tell ...


12

There are two problems with this: The "longest" block chain is selected not by total number of blocks, but by total difficulty. A chain with a large number of low-difficulty blocks would not win. The Bitcoin reference client hard-codes the hashes of a relatively recent block as a "checkpoint" and will reject any chain not containing that block at the ...


12

Imagine that the blockchain is 210000 blocks long and TWO miners both find valid blocks within a few seconds of each other and broadcast them to the network. This is perfectly normal as the Bitcoin network is peer to peer and global. You now have two chains, each of length 210001. Neither of these are longer than each other. Some bitcoind nodes will see ...


11

Your assumptions are perfectly right. Since there is no information exchange between the two partitions while the network is partitioned, and Bitcoin guarantees liveness, the global consistency suffers (see CAP Theorem). This means that each partition will have its own blockchain fork, unaware of each other. The forks are incompatible not just because the ...


11

Pieter's answer is good, the chainwork value is the expected work amount in the chain, expressed as a 32 bytes integer, for the double SHA-256 hashes calculation work. The chainwork is used to identify the correct chain, the biggest chainwork value means the strongest or the correct chain. By the way, Satoshi didn't initially realize that choosing the ...


10

Bitcoin Core maintains two databases: The block index The chain state (or UTXO set) The first one just contains a list of all blocks we know about, valid and invalid. It contains all forks we have ever heard about, and all branches that result from it. It also contains information about where on disk these are stored. It does however not contain any ...


10

The "longest" chain is the one with the most work. A chain's work is equal to the expected number of hashes it would take for someone to replicate a chain of the same number of blocks and the exact same difficulty steps. So currently each block adds about 266 work to the chain because it takes on average ~266 hashes to solve a block with the current ...


8

The chainwork value is really just the total amount of work in the chain. It is the total number of hashes that are expected to have been necessary to produce the current chain, in hexadecimal. Converting 0000000000000000000000000000000000000000000086859f7a841475b236fd to decimal, you get 635262017308958427068157, or 635262 exahashes. At june 2014 hash ...


7

Background info: Strongest vs Longest chain and orphaned blocks How does a client decide which is the longest block chain if there is a fork? Where exactly is the "off-by-one" difficulty bug? (timewarp info) A shorter chain could possibly be considered the correct one, but it would be very hard to make this happen in bitcoin. I can think of two ...


7

Background info: The block hash must be less than a certain value (as defined by the difficulty function) in order for the block to be valid. Generally, as time has progressed, network difficulty has increased. So as the blockheight has increased, the cutoff value for a valid blockhash has decreased. ————— Why not just e.g. add together all block ...


6

You're looking for CBlockIndexWorkComparator, which operates by three rules. The rules are applied one at a time, and if a rule leads to a tie, then the next rule is applied. Which blockchain has the most work? Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.) Which one has a ...


6

According to the Satoshi paper, the following applies: The steps to run the network are as follows: 1) New transactions are broadcast to all nodes. 2) Each node collects new transactions into a block. 3) Each node works on finding a difficult proof-of-work for its block. 4) When a node finds a proof-of-work, it broadcasts the ...


5

Bitcoin clients always accept the longest valid chain. On one hand, clients check the received blocks for validity, on the other hand length is defined by another metric than many assume. The length of the blockchain is the sum of the difficulty of all its blocks, not the number of blocks. So, in order to create a fake chain, the attacker would have to ...


4

This process, generally know as forking, creates two parallel chains that are incompatible, that is, there will be some transactions that will be valid against one chain but are not valid against the other. If there are parallel branches, a miner might keep track of both of them. Once a chain is rejected, transactions in that chain are checked against the ...


4

Consensus rules are often a lot more delicate than they might first appear. Having a tie breaker can actually enable attacks. If I find a block with a really low nonce, I can gamble to keep it secret and then only when a competing block is found, I can simply neutralize it by broadcasting my low-nonce block. This makes other miners waste their time on a ...


4

Stale and orphan blocks are confusing terms with many meanings, depending on whom you ask. If by stale blocks you mean "blocks that are on branches off the main chain, but are otherwise valid", yes, those still exist. They are inherent to proof-of-work chains, as you can't avoid the case where occasionally two miners produce a competing block. Necessarily, ...


4

I think this would be considered a time warp attack. What prevents this strategy from working is actually quite simple, as explained in https://bitcoin.stackexchange.com/a/37960/26673: Bitcoin nodes do not compare chains by their height. (Although they used to do this.) They calculate the total work in each chain (nChainWork), and compare by that. This ...


4

The "apparent" work is 2x higher than actual work due to luck, but the reason it's good bitcoin doesn't use the apparent work is because it has bad stability properties due to variance, and bad game theory interactions. Imagine Bitcoin were worked the way you suggested-- Say, for example, you mine a block and by chance it has 10x the 'work' expected. It ...


4

The answer to the question "Are the segwit witnesses part of the blockchain" depends on what you define as the blockchain: According to old pre-segwit nodes, the answer is no, as they don't care or receive the witnesses. According to new segwit nodes, the answer is yes; the witnesses are as much part of the chain as everything else, and subject to just as ...


3

Appending blocks to the longest blockchain fork. _ _ _ _ _ _ _this is the best chain _ _ _ _/ \_ _ this is NOT


3

There isn't really a "race" any more than there is a race normally. Since both chains are valid, miners can choose which block they would like to build off of. There isn't an advantage to mining on one vs the other; whichever chain you build off of, if you find a block, your block is valid. There doesn't need to be any sort of tie breaking.


3

This is explained in the Bitcoin paper: Nodes always consider the longest chain to be the correct one and will keep working on extending it. If two nodes broadcast different versions of the next block simultaneously, some nodes may receive one or the other first. In that case, they work on the first one they received, but save the other branch in ...


3

I think it's conceivable that this could happen. But under realistic cases, I don't think it actually will. If you don't mine on the longest block, the probability that your block will ever be part of the longest block drops drastically. Unless a block you mine becomes part of the longest chain and stays that way, you never get any fees or reward at all.


3

Nate gave a good answer on the modern meaning of "longest chain"-- as a historical curiosity, the originally released Bitcoin software behaved like you were expecting and that attack would actually work! It was later changed to determine "longest" in terms of work. This seems like a pretty big mistake, but for Bitcoin's first year the difficulty was ...


3

The rule is that the longest* valid chain is considered the active one. If you build a forking branch with invalid transactions in it, the network (in particular, all full nodes - including miners) will simply ignore it. If it's invalid, it does not exist. Blocks are not relayed to peers before validating them entirely. You may be able to temporarily fool ...


3

If a block is part of the main chain, that means that the tip of the blockchain is a descendant of that block. If a block is not part of the main chain, that means there is a longer chain of blocks that does not include this one. These are called orphaned blocks or invalid chains. If a block is in the main chain, its parent is automatically in the main ...


3

The problem here lies in a misunderstanding. It's not the longest block that wins out, but the longest blockchain (read "the blockchain with the most cumulative difficulty"). The length of a single block is hereby irrelevant and in fact usually the node that first confirms a set of transactions wins.


2

The answer is simple: if a country blocks off external internet access, its inhabitants effectively cannot use Bitcoin while the country is blocked. Sure, the protocol will continue with a fork ... but this fork has no hopes of ever "reconnecting" with the main blockchain, so any blocks generated / signed in the fork are useless. The country will have ...


2

Full blockchain nodes actually check not only the block headers, but also every transaction in the block body before accepting that block. If any transaction in the block doesn't "add up" (i.e. its inputs do not match the current accepted balance of those addresses, signatures, etc) then the block will not be accepted as valid. This is where "light" bitcoin ...


Only top voted, non community-wiki answers of a minimum length are eligible