Update tracking information about which blocks a peer is assumed to have. */
| 440 | |
| 441 | /** Update tracking information about which blocks a peer is assumed to have. */ |
| 442 | void UpdateBlockAvailability(NodeId nodeid, const uint256& hash) |
| 443 | { |
| 444 | CNodeState* state = State(nodeid); |
| 445 | assert(state != NULL); |
| 446 | |
| 447 | ProcessBlockAvailability(nodeid); |
| 448 | |
| 449 | CBlockIndex* pindex = LookupBlockIndex(hash); |
| 450 | if (pindex && pindex->nChainWork > 0) { |
| 451 | // An actually better block was announced. |
| 452 | if (state->pindexBestKnownBlock == NULL || pindex->nChainWork >= state->pindexBestKnownBlock->nChainWork) |
| 453 | state->pindexBestKnownBlock = pindex; |
| 454 | } else { |
| 455 | // An unknown block was announced; just assume that the latest one is the best one. |
| 456 | state->hashLastUnknownBlock = hash; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /** Find the last common ancestor two blocks have. |
| 461 | * Both pa and pb must be non-NULL. */ |
no test coverage detected