HomePhabricator

validation: Check chain tip is non-null in CheckFinalTx

Description

validation: Check chain tip is non-null in CheckFinalTx

Summary:
...also update comments to remove mention of ::ChainActive()

From: https://github.com/bitcoin/bitcoin/pull/20750#discussion_r579400663

Also, what about passing a const reference instead of a pointer? I
know this is only theoretical, but previously if the tip was nullptr,
then Height() evaluated to -1, now it evaluates to UB

Note: in Bitcoin ABC, there was already a check for active_chain_tip == nullptr, but only for nMedianPastTime. A few lines above we accessed the pointer to get the nHeight without checking first (potential UB introduced in D11191).

This is a backport of core#21055 [1/16]
https://github.com/bitcoin/bitcoin/pull/21055/commits/9da106be4db692fa5db7b4de79f9cf7bfef37075

Test Plan:

cmake -GNinja .. \
  -DCMAKE_BUILD_TYPE=Debug \
  -DENABLE_SANITIZERS=undefined

ninja check check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11205

Details

Provenance
Carl Dong <contact@carldong.me>Authored on Feb 22 2021, 16:46
PiRKCommitted on Mar 17 2022, 11:04
PiRKPushed on Mar 17 2022, 11:04
Reviewer
Restricted Project
Differential Revision
D11205: validation: Check chain tip is non-null in CheckFinalTx
Parents
rABC110cc42f6ccb: validation: Use *this in CChainState::LoadMempool
Branches
Unknown
Tags
Unknown