Bitcoin Forum
May 03, 2024, 09:57:45 PM *
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
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
Report to moderator
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
Report to moderator
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
Report to moderator
Make sure you back up your wallet regularly! Unlike a bank account, nobody can help you if you lose access to your BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
Report to moderator
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
Report to moderator
1714773465
Hero Member
*
Offline Offline

Posts: 1714773465

View Profile Personal Message (Offline)

Ignore
1714773465
Reply with quote  #2

1714773465
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!