Bitcoin Forum
May 07, 2024, 08:16:42 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: how long bitcoin core stores different branches for the case of reorg  (Read 637 times)
uchalkql (OP)
Jr. Member
*
Offline Offline

Activity: 49
Merit: 2


View Profile
April 20, 2017, 10:11:33 PM
Merited by ABCbits (1)
 #1

Hi,

Could you please tell me how does bitcoin core stores different branches for a possible reorg?
Could you point me to the code?

Thank you very much!!! Smiley
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715069802
Hero Member
*
Offline Offline

Posts: 1715069802

View Profile Personal Message (Offline)

Ignore
1715069802
Reply with quote  #2

1715069802
Report to moderator
1715069802
Hero Member
*
Offline Offline

Posts: 1715069802

View Profile Personal Message (Offline)

Ignore
1715069802
Reply with quote  #2

1715069802
Report to moderator
1715069802
Hero Member
*
Offline Offline

Posts: 1715069802

View Profile Personal Message (Offline)

Ignore
1715069802
Reply with quote  #2

1715069802
Report to moderator
2112
Legendary
*
Offline Offline

Activity: 2128
Merit: 1065



View Profile
April 20, 2017, 10:37:45 PM
Merited by ABCbits (1)
 #2

Forever.

Check the code servicing 'getchaintips' RPC call.

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
April 20, 2017, 10:47:13 PM
Merited by ABCbits (2)
 #3

Pruning removes them when it removes other blocks of the same age,  otherwise forever. there is no point in having to rewrite data to save a couple megabytes here and there.
uchalkql (OP)
Jr. Member
*
Offline Offline

Activity: 49
Merit: 2


View Profile
April 21, 2017, 01:37:35 AM
 #4

Thank you 2112 and gmaxwell!

The variable BlockMap mapBlockIndex is defined in validation.cpp

I couldn't find where it is initialized.

There is only a comment here:
https://github.com/bitcoin/bitcoin/blob/86ea3c2ff247bb2ba0fb50013c8ecdbaf8a9fe8f/src/txdb.cpp
Code:
    // Load mapBlockIndex
while (pcursor->Valid()) {


uchalkql (OP)
Jr. Member
*
Offline Offline

Activity: 49
Merit: 2


View Profile
April 21, 2017, 01:45:53 AM
 #5

Thank you 2112 and gmaxwell!

The variable BlockMap mapBlockIndex is defined in validation.cpp

I couldn't find where it is initialized.

There is only a comment here:
https://github.com/bitcoin/bitcoin/blob/86ea3c2ff247bb2ba0fb50013c8ecdbaf8a9fe8f/src/txdb.cpp
Code:
    // Load mapBlockIndex
while (pcursor->Valid()) {
I think I found, it is here right?

-- txdb.cpp

CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());

-- validation.cpp

CBlockIndex * InsertBlockIndex(uint256 hash)
{
    if (hash.IsNull())
        return NULL;

    // Return existing
    BlockMap::iterator mi = mapBlockIndex.find(hash);
    if (mi != mapBlockIndex.end())
        return (*mi).second;

    // Create new
    CBlockIndex* pindexNew = new CBlockIndex();
    if (!pindexNew)
        throw std::runtime_error(std::string(__func__) + ": new CBlockIndex failed");
    mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
    pindexNew->phashBlock = &((*mi).first);

    return pindexNew;
}
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!