aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/tx_verify.cpp
diff options
context:
space:
mode:
authorAdam Jonas <jonas@chaincode.com>2019-10-21 13:17:22 -0400
committerAurèle Oulès <aurele@oules.com>2022-05-05 15:55:44 +0200
commit308dd2e93e92f4cac4e7d75478316af9bb2b77b8 (patch)
tree520c6a3e925de6de2ded46a439c5b09a528f374f /src/consensus/tx_verify.cpp
parentb1c5991eebb916755be188f355ad36fe01a3f529 (diff)
Sanity assert GetAncestor() != nullptr where appropriate
Add sanity asserts for return value of `CBlockIndex::GetAncestor()` where appropriate. In validation.cpp `CheckSequenceLocks`, check the return value of `tip->GetAncestor(maxInputHeight)` stored into `lp->maxInputBlock`. If it ever returns `nullptr` because the ancestor isn't found, it's going to be a bad bug to keep going, since a `LockPoints` object with the `maxInputBlock` member set to `nullptr` signifies no relative lock time. In the other places, the added asserts would prevent accidental dereferencing of a null pointer which is undefined behavior. Co-Authored-By: Aurèle Oulès <aurele@oules.com> Co-Authored-By: danra <danra@users.noreply.github.com>
Diffstat (limited to 'src/consensus/tx_verify.cpp')
-rw-r--r--src/consensus/tx_verify.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
index 5738c333ce..154146f08d 100644
--- a/src/consensus/tx_verify.cpp
+++ b/src/consensus/tx_verify.cpp
@@ -11,6 +11,7 @@
#include <consensus/validation.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
+#include <util/check.h>
#include <util/moneystr.h>
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
@@ -74,7 +75,7 @@ std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, int flags
int nCoinHeight = prevHeights[txinIndex];
if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) {
- int64_t nCoinTime = block.GetAncestor(std::max(nCoinHeight-1, 0))->GetMedianTimePast();
+ const int64_t nCoinTime{Assert(block.GetAncestor(std::max(nCoinHeight - 1, 0)))->GetMedianTimePast()};
// NOTE: Subtract 1 to maintain nLockTime semantics
// BIP 68 relative lock times have the semantics of calculating
// the first block or time at which the transaction would be