Bitcoin Forum
April 23, 2024, 03:11:12 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: difficulty  (Read 553 times)
ArsenShnurkov (OP)
Legendary
*
Offline Offline

Activity: 1386
Merit: 1000



View Profile
January 19, 2013, 10:43:39 PM
Last edit: January 19, 2013, 11:15:47 PM by ArsenShnurkov
 #1

What prevent the miners from generating the whole new blockchain with low difficulty along the chain?
Thus the chain can be splitted from the starting block or from any checkpoint...
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Gabi
Legendary
*
Offline Offline

Activity: 1148
Merit: 1008


If you want to walk on water, get out of the boat


View Profile
January 19, 2013, 11:09:21 PM
 #2

The fact that no client would accept it?

ArsenShnurkov (OP)
Legendary
*
Offline Offline

Activity: 1386
Merit: 1000



View Profile
January 19, 2013, 11:11:24 PM
Last edit: January 20, 2013, 01:01:17 AM by ArsenShnurkov
 #3

no client would accept it?

Why? New chain can be made longer than the existing one

1) take the place in the "official" chain where difficulty changes
2) generate 2016 blocks to establish low difficulty
3) generate rest of new chain with low difficulty
4) ship all of this to the network
5) ...
6) profit

UPD:
http://sourceforge.net/mailarchive/message.php?msg_id=28441042
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
January 19, 2013, 11:18:41 PM
 #4

the best chain is determined not by length(blocks) but by work(hashs).

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
ArsenShnurkov (OP)
Legendary
*
Offline Offline

Activity: 1386
Merit: 1000



View Profile
January 19, 2013, 11:21:24 PM
 #5

I mean not the length(blocks) but count(blocks in the chain)

the best chain is determined not by length(blocks) but by work(hashs).

I don't understood this. The number of calculated hashes is not included into the block,
so there is no way to reliable determine the amount of work
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
January 19, 2013, 11:30:18 PM
 #6

The "best" chain is the one with the highest combined difficulty.  So a longer but easier chain won't be seen as the "best/longest".

The only way to have the longer chain is to do more work then the current longest chain.
kokjo
Legendary
*
Offline Offline

Activity: 1050
Merit: 1000

You are WRONG!


View Profile
January 19, 2013, 11:33:46 PM
 #7

the best chain is determined not by length(blocks) but by work(hashs).

I don't understood this. The number of calculated hashes is not included into the block,
so there is no way to reliable determine the amount of work

each blockheader contains a field called "bits", the field describes how much of the hash should be 0's, before the block is considered valid. this number is the same as difficulty.

a difficulty adjustment every 2 weeks, adjusts the bits field, depending on the timestamps on the first and last block in that difficulty period. trying to match 2 week on average: if blocks are created too fast, difficulty rises; too slow, difficulty falls.

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
ArsenShnurkov (OP)
Legendary
*
Offline Offline

Activity: 1386
Merit: 1000



View Profile
January 19, 2013, 11:35:53 PM
 #8

The "best" chain is the one with the highest combined difficulty.

Where i can find this check in the code? (in which source code file and function)
21after2
Member
**
Offline Offline

Activity: 112
Merit: 16



View Profile
January 19, 2013, 11:55:34 PM
 #9

This should probably be in mining, I would think, as opposed to newbies.
ArsenShnurkov (OP)
Legendary
*
Offline Offline

Activity: 1386
Merit: 1000



View Profile
January 19, 2013, 11:58:04 PM
Last edit: January 20, 2013, 12:49:53 AM by ArsenShnurkov
 #10

I found global variable
CBigNum bnBestChainWork = 0;
in file
https://github.com/bitcoin/bitcoin/blob/0e31ae9818528d52bbd802a8917b7015f8e38ae7/src/main.cpp#L38

Now I want to understand how the code calculate this "Work"

class CBlockIndex contains member CBigNum bnChainWork;

Here
https://github.com/bitcoin/bitcoin/blob/0e31ae9818528d52bbd802a8917b7015f8e38ae7/src/main.cpp#L1925
https://github.com/bitcoin/bitcoin/blob/0e31ae9818528d52bbd802a8917b7015f8e38ae7/src/main.cpp#L2537
it is calculated
bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork();

https://github.com/bitcoin/bitcoin/blob/0e31ae9818528d52bbd802a8917b7015f8e38ae7/src/main.h#L1788
Code:
struct CBlockIndexWorkComparator
{
    bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
        if (pa->bnChainWork > pb->bnChainWork) return false;
        if (pa->bnChainWork < pb->bnChainWork) return true;

        if (pa->GetBlockHash() < pb->GetBlockHash()) return false;
        if (pa->GetBlockHash() > pb->GetBlockHash()) return true;

        return false; // identical blocks
    }
};

global set of blocks
https://github.com/bitcoin/bitcoin/blob/0e31ae9818528d52bbd802a8917b7015f8e38ae7/src/main.cpp#L42
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed

Actually, I don't understood, how operator() is called in set:
http://www.sgi.com/tech/stl/stl_set.h
(I don't know C++ well)
Ok, it's usual technique - http://www.sgi.com/tech/stl/set.html

Where one can read about block's lifecycle with references to code?
How they are received, in which variables they are stored in memory, when they persists to disk and so on?
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1025



View Profile WWW
January 20, 2013, 12:18:20 PM
Last edit: January 20, 2013, 12:30:32 PM by deepceleron
 #11

http://bitcoin.org/bitcoin.pdf

Section 4; Section 11


The actual "strength" of the blockchain is the chain of difficulty targets stored in blocks since the time of the block one would attempt to replace. The SHA256 hashes of blocks are all below the target; finding such a hash is computationally expensive. By definition, other miners would reject a sequence of blocks where the difficulty target is not as expected for the difficulty period of 2016 blocks or the block hashes did not meet the difficulty.

In the actual block, "bits" is a compact form of of the target.

Code:
{
  "hash":"000000000000026e70652663fd4a5e3a1c38cfdf0c1b2666308c3816d9c21321",
  "ver":2,
  "prev_block":"00000000000000e788455adcba11a49a452acd5298e3a26d2db4cb9fcc050d1a",
  "mrkl_root":"b5484c1dd069b73063ea5cc594826b1541a8d5fd069629e9e950bb304789670b",
  "time":1358682853,
  "bits":436545969,
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!