MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CheckSequenceLocks

Function CheckSequenceLocks

src/validation.cpp:372–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

370}
371
372bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool useExistingLockPoints)
373{
374 AssertLockHeld(cs_main);
375 AssertLockHeld(mempool.cs);
376
377 CBlockIndex* tip = chainActive.Tip();
378 assert(tip != nullptr);
379
380 CBlockIndex index;
381 index.pprev = tip;
382 // CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
383 // height based locks because when SequenceLocks() is called within
384 // ConnectBlock(), the height of the block *being*
385 // evaluated is what is used.
386 // Thus if we want to know if a transaction can be part of the
387 // *next* block, we need to use one more than chainActive.Height()
388 index.nHeight = tip->nHeight + 1;
389
390 std::pair<int, int64_t> lockPair;
391 if (useExistingLockPoints) {
392 assert(lp);
393 lockPair.first = lp->height;
394 lockPair.second = lp->time;
395 }
396 else {
397 // pcoinsTip contains the UTXO set for chainActive.Tip()
398 CCoinsViewMemPool viewMemPool(pcoinsTip.get(), mempool);
399 std::vector<int> prevheights;
400 prevheights.resize(tx.vin.size());
401 for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) {
402 const CTxIn& txin = tx.vin[txinIndex];
403 Coin coin;
404 if (!viewMemPool.GetCoin(txin.prevout, coin)) {
405 return error("%s: Missing input", __func__);
406 }
407 if (coin.nHeight == MEMPOOL_HEIGHT) {
408 // Assume all mempool transaction confirm in the next block
409 prevheights[txinIndex] = tip->nHeight + 1;
410 } else {
411 prevheights[txinIndex] = coin.nHeight;
412 }
413 }
414 lockPair = CalculateSequenceLocks(tx, flags, &prevheights, index);
415 if (lp) {
416 lp->height = lockPair.first;
417 lp->time = lockPair.second;
418 // Also store the hash of the block with the highest height of
419 // all the blocks which have sequence locked prevouts.
420 // This hash needs to still be on the chain
421 // for these LockPoint calculations to be valid
422 // Note: It is impossible to correctly calculate a maxInputBlock
423 // if any of the sequence locked inputs depend on unconfirmed txs,
424 // except in the special case where the relative lock time/height
425 // is 0, which is equivalent to no sequence lock. Since we assume
426 // input height of tip+1 for mempool txs and test the resulting
427 // lockPair from CalculateSequenceLocks against tip+1. We know
428 // EvaluateSequenceLocks will fail if there was a non-zero sequence
429 // lock on a mempool input, so we can use the return value of

Callers 3

removeForReorgMethod · 0.85
AcceptToMemoryPoolWorkerFunction · 0.85
TestSequenceLocksFunction · 0.85

Calls 10

errorFunction · 0.85
CalculateSequenceLocksFunction · 0.85
maxFunction · 0.85
EvaluateSequenceLocksFunction · 0.85
getMethod · 0.80
GetAncestorMethod · 0.80
TipMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
GetCoinMethod · 0.45

Tested by 1

TestSequenceLocksFunction · 0.68