mirror of
https://github.com/bitcoin/bips.git
synced 2025-05-12 12:03:29 +00:00
Update BIP68 implementation to match spec
This commit is contained in:
parent
fe1b3b5b7b
commit
0e48a2466c
@ -64,21 +64,21 @@ enum {
|
|||||||
/* Setting nSequence to this value for every input in a transaction
|
/* Setting nSequence to this value for every input in a transaction
|
||||||
* disables nLockTime. */
|
* disables nLockTime. */
|
||||||
static const uint32_t SEQUENCE_FINAL = 0xffffffff;
|
static const uint32_t SEQUENCE_FINAL = 0xffffffff;
|
||||||
|
|
||||||
|
/* Below flags apply in the context of BIP 68*/
|
||||||
/* If this flag set, CTxIn::nSequence is NOT interpreted as a
|
/* If this flag set, CTxIn::nSequence is NOT interpreted as a
|
||||||
* relative lock-time. Setting the most significant bit of a
|
* relative lock-time. */
|
||||||
* sequence number disabled relative lock-time. */
|
|
||||||
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
|
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
|
||||||
|
|
||||||
/* If CTxIn::nSequence encodes a relative lock-time and this flag
|
/* If CTxIn::nSequence encodes a relative lock-time and this flag
|
||||||
* is set, the relative lock-time has units of 512 seconds,
|
* is set, the relative lock-time has units of 512 seconds,
|
||||||
* otherwise it specifies blocks with a granularity of 1. */
|
* otherwise it specifies blocks with a granularity of 1. */
|
||||||
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
|
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
|
||||||
|
|
||||||
/* If CTxIn::nSequence encodes a relative lock-time, this mask is
|
/* If CTxIn::nSequence encodes a relative lock-time, this mask is
|
||||||
* applied to extract that lock-time from the sequence field. */
|
* applied to extract that lock-time from the sequence field. */
|
||||||
static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
||||||
|
|
||||||
/* In order to use the same number of bits to encode roughly the
|
/* In order to use the same number of bits to encode roughly the
|
||||||
* same wall-clock duration, and because blocks are naturally
|
* same wall-clock duration, and because blocks are naturally
|
||||||
* limited to occur every 600s on average, the minimum granularity
|
* limited to occur every 600s on average, the minimum granularity
|
||||||
@ -87,7 +87,7 @@ static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
|||||||
* multiplying by 512 = 2^9, or equivalently shifting up by
|
* multiplying by 512 = 2^9, or equivalently shifting up by
|
||||||
* 9 bits. */
|
* 9 bits. */
|
||||||
static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
|
static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the block height and previous block's median time past at
|
* Calculates the block height and previous block's median time past at
|
||||||
* which the transaction will be considered final in the context of BIP 68.
|
* which the transaction will be considered final in the context of BIP 68.
|
||||||
@ -174,16 +174,17 @@ bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeig
|
|||||||
bool CheckSequenceLocks(const CTransaction &tx, int flags)
|
bool CheckSequenceLocks(const CTransaction &tx, int flags)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
|
AssertLockHeld(mempool.cs);
|
||||||
|
|
||||||
CBlockIndex* tip = chainActive.Tip();
|
CBlockIndex* tip = chainActive.Tip();
|
||||||
CBlockIndex index;
|
CBlockIndex index;
|
||||||
index.pprev = tip;
|
index.pprev = tip;
|
||||||
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
|
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
|
||||||
// height based locks because when SequenceLocks() is called within
|
// height based locks because when SequenceLocks() is called within
|
||||||
// CBlock::AcceptBlock(), the height of the block *being*
|
// ConnectBlock(), the height of the block *being*
|
||||||
// evaluated is what is used. Thus if we want to know if a
|
// evaluated is what is used.
|
||||||
// transaction can be part of the *next* block, we need to call
|
// Thus if we want to know if a transaction can be part of the
|
||||||
// SequenceLocks() with one more than chainActive.Height().
|
// *next* block, we need to use one more than chainActive.Height()
|
||||||
index.nHeight = tip->nHeight + 1;
|
index.nHeight = tip->nHeight + 1;
|
||||||
|
|
||||||
// pcoinsTip contains the UTXO set for chainActive.Tip()
|
// pcoinsTip contains the UTXO set for chainActive.Tip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user