Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115186
D13242.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Subscribers
None
D13242.diff
View Options
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
--- a/src/consensus/tx_verify.cpp
+++ b/src/consensus/tx_verify.cpp
@@ -13,6 +13,7 @@
#include <consensus/validation.h>
#include <primitives/transaction.h>
#include <script/script_flags.h>
+#include <util/check.h>
#include <util/moneystr.h> // For FormatMoney
#include <version.h> // For PROTOCOL_VERSION
@@ -115,8 +116,9 @@
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 valid. When
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -2416,12 +2416,12 @@
}
}
- const CBlockIndex *pindexPast =
- pindex->GetAncestor(pindex->nHeight - blockcount);
- int nTimeDiff =
- pindex->GetMedianTimePast() - pindexPast->GetMedianTimePast();
- int nTxDiff =
- pindex->GetChainTxCount() - pindexPast->GetChainTxCount();
+ const CBlockIndex &past_block{*CHECK_NONFATAL(
+ pindex->GetAncestor(pindex->nHeight - blockcount))};
+ const int64_t nTimeDiff{pindex->GetMedianTimePast() -
+ past_block.GetMedianTimePast()};
+ const int nTxDiff =
+ pindex->GetChainTxCount() - past_block.GetChainTxCount();
UniValue ret(UniValue::VOBJ);
ret.pushKV("time", pindex->GetBlockTime());
@@ -2560,9 +2560,8 @@
[&](const RPCHelpMan &self, const Config &config,
const JSONRPCRequest &request) -> UniValue {
ChainstateManager &chainman = EnsureAnyChainman(request.context);
- const CBlockIndex *pindex{
- ParseHashOrHeight(request.params[0], chainman)};
- CHECK_NONFATAL(pindex != nullptr);
+ const CBlockIndex &pindex{*CHECK_NONFATAL(
+ ParseHashOrHeight(request.params[0], chainman))};
std::set<std::string> stats;
if (!request.params[1].isNull()) {
@@ -2573,10 +2572,10 @@
}
}
- const CBlock block =
- GetBlockChecked(config, chainman.m_blockman, pindex);
- const CBlockUndo blockUndo =
- GetUndoChecked(chainman.m_blockman, pindex);
+ const CBlock &block =
+ GetBlockChecked(config, chainman.m_blockman, &pindex);
+ const CBlockUndo &blockUndo =
+ GetUndoChecked(chainman.m_blockman, &pindex);
// Calculate everything if nothing selected (default)
const bool do_all = stats.size() == 0;
@@ -2689,8 +2688,8 @@
(block.vtx.size() > 1)
? total_size / (block.vtx.size() - 1)
: 0);
- ret_all.pushKV("blockhash", pindex->GetBlockHash().GetHex());
- ret_all.pushKV("height", (int64_t)pindex->nHeight);
+ ret_all.pushKV("blockhash", pindex.GetBlockHash().GetHex());
+ ret_all.pushKV("height", (int64_t)pindex.nHeight);
ret_all.pushKV("ins", inputs);
ret_all.pushKV("maxfee", maxfee);
ret_all.pushKV("maxfeerate", maxfeerate);
@@ -2698,7 +2697,7 @@
ret_all.pushKV("medianfee", CalculateTruncatedMedian(fee_array));
ret_all.pushKV("medianfeerate",
CalculateTruncatedMedian(feerate_array));
- ret_all.pushKV("mediantime", pindex->GetMedianTimePast());
+ ret_all.pushKV("mediantime", pindex.GetMedianTimePast());
ret_all.pushKV("mediantxsize",
CalculateTruncatedMedian(txsize_array));
ret_all.pushKV("minfee",
@@ -2709,9 +2708,9 @@
ret_all.pushKV("mintxsize",
mintxsize == blockMaxSize ? 0 : mintxsize);
ret_all.pushKV("outs", outputs);
- ret_all.pushKV("subsidy", GetBlockSubsidy(pindex->nHeight,
+ ret_all.pushKV("subsidy", GetBlockSubsidy(pindex.nHeight,
Params().GetConsensus()));
- ret_all.pushKV("time", pindex->GetBlockTime());
+ ret_all.pushKV("time", pindex.GetBlockTime());
ret_all.pushKV("total_out", total_out);
ret_all.pushKV("total_size", total_size);
ret_all.pushKV("totalfee", totalfee);
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -467,25 +467,26 @@
// Sequence locks fail.
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}));
- for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) {
- // Trick the MedianTimePast.
+ // Sequence locks pass 512 seconds later
+ const int SEQUENCE_LOCK_TIME = 512;
+ for (int i = 0; i < CBlockIndex::nMedianTimeSpan; ++i) {
+ // Trick the MedianTimePast
m_node.chainman->ActiveTip()
->GetAncestor(m_node.chainman->ActiveHeight() - i)
- ->nTime += 512;
+ ->nTime += SEQUENCE_LOCK_TIME;
}
- // Sequence locks pass 512 seconds later.
BOOST_CHECK(
SequenceLocks(CTransaction(tx), flags, prevheights,
CreateBlockIndex(m_node.chainman->ActiveHeight() + 1,
m_node.chainman->ActiveTip())));
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) {
+ CBlockIndex *ancestor{
+ Assert(m_node.chainman->ActiveChain().Tip()->GetAncestor(
+ m_node.chainman->ActiveHeight() - i))};
// Undo tricked MTP.
- m_node.chainman->ActiveChain()
- .Tip()
- ->GetAncestor(m_node.chainman->ActiveHeight() - i)
- ->nTime -= 512;
+ ancestor->nTime -= SEQUENCE_LOCK_TIME;
}
// Absolute height locked.
@@ -579,14 +580,14 @@
// relative locked txs will if inconsistently added to g_mempool. For now
// these will still generate a valid template until BIP68 soft fork.
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3UL);
- // However if we advance height by 1 and time by 512, all of them should be
- // mined.
+ // However if we advance height by 1 and time by SEQUENCE_LOCK_TIME, all of
+ // them should be mined.
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++) {
+ CBlockIndex *ancestor{
+ Assert(m_node.chainman->ActiveChain().Tip()->GetAncestor(
+ m_node.chainman->ActiveHeight() - i))};
// Trick the MedianTimePast.
- m_node.chainman->ActiveChain()
- .Tip()
- ->GetAncestor(m_node.chainman->ActiveHeight() - i)
- ->nTime += 512;
+ ancestor->nTime += SEQUENCE_LOCK_TIME;
}
m_node.chainman->ActiveTip()->nHeight++;
SetMockTime(m_node.chainman->ActiveTip()->GetMedianTimePast() + 1);
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -213,7 +213,12 @@
maxInputHeight = std::max(maxInputHeight, height);
}
}
- lp->maxInputBlock = tip->GetAncestor(maxInputHeight);
+ // tip->GetAncestor(maxInputHeight) should never return a nullptr
+ // because maxInputHeight is always less than the tip height.
+ // It would, however, be a bad bug to continue execution, since a
+ // LockPoints object with the maxInputBlock member set to nullptr
+ // signifies no relative lock time.
+ lp->maxInputBlock = Assert(tip->GetAncestor(maxInputHeight));
}
}
return EvaluateSequenceLocks(index, lockPair);
@@ -4905,14 +4910,14 @@
int nForkHeight = pindexFork ? pindexFork->nHeight : 0;
for (int nHeight = nForkHeight + 1; nHeight <= pindexNew->nHeight;
++nHeight) {
- const CBlockIndex *pindex = pindexNew->GetAncestor(nHeight);
- LogPrintf("Rolling forward %s (%i)\n",
- pindex->GetBlockHash().ToString(), nHeight);
+ const CBlockIndex &pindex{*Assert(pindexNew->GetAncestor(nHeight))};
+ LogPrintf("Rolling forward %s (%i)\n", pindex.GetBlockHash().ToString(),
+ nHeight);
uiInterface.ShowProgress(_("Replaying blocks...").translated,
(int)((nHeight - nForkHeight) * 100.0 /
(pindexNew->nHeight - nForkHeight)),
false);
- if (!RollforwardBlock(pindex, cache)) {
+ if (!RollforwardBlock(&pindex, cache)) {
return false;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 10:12 (7 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187306
Default Alt Text
D13242.diff (9 KB)
Attached To
D13242: Sanity assert GetAncestor() != nullptr where appropriate
Event Timeline
Log In to Comment