Bitcoin Forum
February 29, 2020, 08:05:59 AM *
News: Latest Bitcoin Core release: 0.19.0.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How does a node knows the current tip of best block chain  (Read 65 times)
maplelake
Newbie
*
Offline Offline

Activity: 28
Merit: 2


View Profile
February 10, 2020, 01:11:54 PM
 #1

Question 1:
Assume some node is offline for a long time. After it reconnects to block chain, how does it know what is latest block? As his peer nodes maybe "wake up just now". From their view of chain, maybe the current tip is not the really Latest block.

Question 2:
I am confused how "IsInitialBlockDownload" function works. What is role of this function? It require a node to download a fixed number of block("nChainWork" must more than "nMinimumChainWork").

Question 3:
I run the a new node and read its debug.log file. I find Node got many inv tx info. But it does not sync all the block data(blk***.dat). And it does not "Requesting tx data of tx hash". why ?

"2020-02-10T12:21:14Z got inv: tx 04ef3414b55e45555ebfad775b6164827a020a25836e6a4db87eeb9ebee462d9  new peer=4
"

Question 5:
Why it named 'tip', I think 'top' is more obviously understand. "Top block" Smiley


Thank you
1582963559
Hero Member
*
Offline Offline

Posts: 1582963559

View Profile Personal Message (Offline)

Ignore
1582963559
Reply with quote  #2

1582963559
Report to moderator
1582963559
Hero Member
*
Offline Offline

Posts: 1582963559

View Profile Personal Message (Offline)

Ignore
1582963559
Reply with quote  #2

1582963559
Report to moderator
AWARD-WINNING
CRYPTO CASINO
ASKGAMBLERS
PLAYERS CHOICE 2019
PROUD
PARTNER OF
1500+
GAMES
2 MIN
CASH-OUTS
24/7
SUPPORT
100s OF
FREE SPINS
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 1666
Merit: 1571


https://bit.ly/387FXHi ← lightning theory


View Profile
February 10, 2020, 01:30:03 PM
 #2

5. It's probably better to assume it's more of a hint.

1. The peers.dat is designed to store up to a thousand peers and the other peers will be able to help the new client find the most up to date one. There's probably the initial major/trusted peers that take up the first 10 in thst spot (I assume) in order to limit such an event from occurring.

3. That data is stored into memory, the debug log doesn't include io writes because it'd probably be very similar every time and io writes to disk take a long time... (a few milliseconds afaik).

ranochigo
Legendary
*
Offline Offline

Activity: 1932
Merit: 1271

Back online:)


View Profile WWW
February 10, 2020, 02:11:59 PM
 #3

Question 2:
I am confused how "IsInitialBlockDownload" function works. What is role of this function? It require a node to download a fixed number of block("nChainWork" must more than "nMinimumChainWork").
Initialblockdownload is adopted by the client to download a large number of blocks at a faster rate. Currently, Bitcoin Core downloads the block headers first to allow it to request blocks simultaneously from all the peers that it is connected to.

To answer your question, the client will not download blocks from its peers unless the work in the chain that the peers have is higher than the one defined in the chain which is currently located here [1] as of now. It helps to prevent sybil attacks (to a certain extent) which tricks your client into downloading blockchains that has too little work (ie. Chains that are shorter difficulty wise).

[1] https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L87

achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 2058
Merit: 3122


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


View Profile WWW
February 10, 2020, 04:53:00 PM
Merited by Foxpup (4), ETFbitcoin (1), styca (1), nc50lc (1)
 #4

Question 1:
Assume some node is offline for a long time. After it reconnects to block chain, how does it know what is latest block? As his peer nodes maybe "wake up just now". From their view of chain, maybe the current tip is not the really Latest block.
A node will connect to many peers in a way that is unlikely to have many peers that are also behind. The reason for this is twofold. Firstly, a node will store a database of peers and some information about those peers. When it starts up, it chooses peers from that database and chooses them based on some "goodness" information it stores. Secondly, if that database is too small or has a lot of offline nodes, then it will use the DNS seeders. The DNS seeders will filter for nodes which are up for a long time so new nodes will be connected to seed nodes that know many peers. Those nodes will return additional nodes for new nodes to connect to based on node uptime and other characteristics. So peer discovery itself will select for nodes that have been up for a while and thus are likely to have the latest block.

But even if all of the peers are just coming online, they too will be connected to other nodes and syncing their own blockchain. As they receive new blocks and block headers, they will be able to serve them to their peers. So if you are only connected to nodes that are still syncing, you will still sync from them as they sync their blockchain from their other peers.

Question 2:
I am confused how "IsInitialBlockDownload" function works. What is role of this function? It require a node to download a fixed number of block("nChainWork" must more than "nMinimumChainWork").
It is a bunch of heuristic tests that just check for whether the node is likely to be not synced. It is used to disable certain functionality that is dependent on a recent blockchain (IsIBD will return true before being fully synced).

Question 3:
I run the a new node and read its debug.log file. I find Node got many inv tx info. But it does not sync all the block data(blk***.dat). And it does not "Requesting tx data of tx hash". why ?

"2020-02-10T12:21:14Z got inv: tx 04ef3414b55e45555ebfad775b6164827a020a25836e6a4db87eeb9ebee462d9  new peer=4
"
Other nodes will just send invs to all of their peers regardless of sync state and other status. It is up to the receiver of those invs to do something with them. Because your node is still syncing, it won't request those transactions as it might not be able to validate them yet.

Khaos77
Member
**
Offline Offline

Activity: 434
Merit: 68

Flag Day ☺


View Profile
February 11, 2020, 04:07:15 AM
 #5

Question 1:
Assume some node is offline for a long time. After it reconnects to block chain, how does it know what is latest block? As his peer nodes maybe "wake up just now". From their view of chain, maybe the current tip is not the really Latest block.

You are connecting to other peers, your client compares the block height of each peer and considers the highest block # the latest block.
If for some reason you and your peers are isolated from the main chain, then your block height would be lower ,
until a peer synced with your node or one of your peers node that truly had the latest block.

Smart move whenever your node has been offline ,
is to compare your block height with the latest block height on a block explorer,
just to make certain you are on the latest block agreed upon by the network.  Smiley

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!