| 185 | EXCLUSIVE_LOCKS_REQUIRED(cs_main); |
| 186 | |
| 187 | bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags) |
| 188 | { |
| 189 | AssertLockHeld(cs_main); |
| 190 | assert(active_chain_tip); // TODO: Make active_chain_tip a reference |
| 191 | |
| 192 | // By convention a negative value for flags indicates that the |
| 193 | // current network-enforced consensus rules should be used. In |
| 194 | // a future soft-fork scenario that would mean checking which |
| 195 | // rules would be enforced for the next block and setting the |
| 196 | // appropriate flags. At the present time no soft-forks are |
| 197 | // scheduled, so no flags are set. |
| 198 | flags = std::max(flags, 0); |
| 199 | |
| 200 | // CheckFinalTx() uses active_chain_tip.Height()+1 to evaluate |
| 201 | // nLockTime because when IsFinalTx() is called within |
| 202 | // AcceptBlock(), the height of the block *being* |
| 203 | // evaluated is what is used. Thus if we want to know if a |
| 204 | // transaction can be part of the *next* block, we need to call |
| 205 | // IsFinalTx() with one more than active_chain_tip.Height(). |
| 206 | const int nBlockHeight = active_chain_tip->nHeight + 1; |
| 207 | |
| 208 | // BIP113 requires that time-locked transactions have nLockTime set to |
| 209 | // less than the median time of the previous block they're contained in. |
| 210 | // When the next block is created its previous block will be the current |
| 211 | // chain tip, so we use that to calculate the median time passed to |
| 212 | // IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set. |
| 213 | const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST) |
| 214 | ? active_chain_tip->GetMedianTimePast() |
| 215 | : GetAdjustedTime(); |
| 216 | |
| 217 | return IsFinalTx(tx, nBlockHeight, nBlockTime); |
| 218 | } |
| 219 | |
| 220 | bool CheckSequenceLocks(CBlockIndex* tip, |
| 221 | const CCoinsView& coins_view, |