<p>I just see that <a href="https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki" rel="nofollow noreferrer">BIP68</a> states</p>

<pre><code>    // Time-based relative lock-times are measured from the
    // smallest allowed timestamp of the block containing the
    // txout being spent, which is the median time past of the
    // block prior.
</code></pre>

<p>so, the relative timelocks for UTXOs in the block 1 (which 114 confirmations) are verified against the mediantime of the prior block, so the block with height 0 in regtest has a hardcoded median time to 2011 ("mediantime": 1296688602, 2011-02-03 00:16:42 CET/CEST)</p>

CC BY-SA 4.0
2020-05-24T09:54:28.307Z
2020-05-24T09:54:28.307Z
monkeyUser
<p>I'm studying sequence, and I set a transaction valid after 512 seconds. 
First of all I use regtest and I start from clean blockchain, after that I mine 114 blocks.
At this point miner creates a transaction and tries to send it</p>

<p>My decode transaction</p>

<pre><code>{
  "txid": "59ff4adafb47a5b22c6434af38f6e138c9008356778ed8b308c48029d7d4032f",
  "hash": "1bef48f96d18f1c78021b7e4b0a7d5285f6f7d2cc8c7adc31671820e367c3d70",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "88fb1408675c774c36692f170c6122af49cab7a5bab336272f0e4d8c0ef8c89a",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "3044022070b753c99e2b6d241fd8a4ebe26f53644ef3eea58fff743e51f7a69e1ee7a99602204cbe9a60fc25be24baa3e4613f27a3e51df4a285174e001b62de18e1da2e42fd01",
        "03494041191fd2b02579fd49877755e55d9d451a37c6d0bbe04aab8ef507a78b19"
      ],
      "sequence": 4194305
    }
  ],
  "vout": [
    {
      "value": 49.99100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 18363770025baac1ebdb99a948eab2776d9568ae",
        "hex": "001418363770025baac1ebdb99a948eab2776d9568ae",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qrqmrwuqztw4vr67mnx55364jwake269w8hl5fe"
        ]
      }
    }
  ]
}
</code></pre>

<p>I Give an error when I try to use sendrawtransaction</p>

<pre><code>error code: -26
error message:
non-BIP68-final (code 64)
</code></pre>

<p>And it's correct because my UTXO (<code>88fb1408675c774c36692f170c6122af49cab7a5bab336272f0e4d8c0ef8c89a</code>) come from the block with height 2 and 113 confirmations, and its median time is <code>1590276467</code> (2020-05-24 01:27:47 CET/CEST) and My transaction is valid after 512 seconds (Date:2020-05-24 01:41:23 CET/CEST) and the best block has that value 2020-05-24 01:28:06 CET/CEST (it's not useful)</p>

<p>Now, If I create another transaction with the TXID comes from block with height 1 and 114 confirmations it works, I can send it.
Below my transaction and details.</p>

<pre><code>{
  "txid": "f98d3ef70ca2c9d797bf7fff2e96e07f5ba10a280186a2132c6a902eebcab31e",
  "hash": "5776ad750fe759411a1ed5aa10e759b33e52b2935555d90b997fa788c9e25405",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "e1ee4602a78ab4f5f58705a75405d2f223307989950e1cbe03a4518cf23b7914",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402200641ef29e3f0c8ef0c55dbb4a86a752e3655dd0c928c4e2e6659d3beeaf3f3870220026821b9ba043894cb20c7d7a378eaae76f56400755bf412f8ab1524a9a238b301",
        "03494041191fd2b02579fd49877755e55d9d451a37c6d0bbe04aab8ef507a78b19"
      ],
      "sequence": 4194305
    }
  ],
  "vout": [
    {
      "value": 49.99100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 18363770025baac1ebdb99a948eab2776d9568ae",
        "hex": "001418363770025baac1ebdb99a948eab2776d9568ae",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qrqmrwuqztw4vr67mnx55364jwake269w8hl5fe"
        ]
      }
    }
  ]
}
</code></pre>

<p>The median time of block 1 and 114 confirmations is <code>1590276486</code> (2020-05-24 01:28:06 CET/CEST) and my transaction should be valid after 512 seconds (2020-05-24 01:45:05 CET/CEST), and my best block median time is 2020-05-24 01:28:06 CET/CEST</p>

<p>Below, the details of block 2 with 114 confirmations</p>

<pre><code>{
  "hash": "5f769f610f29057577611868a660b353bea06e51d94905f3dbf7fb93e60a3d30",
  "confirmations": 1,
  "strippedsize": 214,
  "size": 250,
  "weight": 892,
  "height": 114,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "1699f1cebdde9f4da1211f948f2ec194f7820fcfbab80c93bb5ea486e6837be7",
  "tx": [
    "1699f1cebdde9f4da1211f948f2ec194f7820fcfbab80c93bb5ea486e6837be7"
  ],
  "time": 1590276487,
  "mediantime": 1590276486,
  "nonce": 0,
  "bits": "207fffff",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000e6",
  "nTx": 1,
  "previousblockhash": "36f373a49886a31eff05ff8de39722f589cff103bed47715dd697d14350539ce"
}
</code></pre>

<p>Now, I know the sequence (<code>00000000010000000000000000000001</code>) is checked on median time of UTXO's block, But block 2 (with 114 confirmations) and block 3 (with 113 confirmations) are very similar and very close, and I don't understand why with block height 2 I'm able to send the transaction.</p>

<transactions><sequence><checksequenceverify>
Sequence valid before time
monkeyUser
# Sequence valid before time

(Asked by: username_0 on 2020-05-23)

I'm studying sequence, and I set a transaction valid after 512 seconds.
First of all I use regtest and I start from clean blockchain, after that I mine 114 blocks.
At this point miner creates a transaction and tries to send it

My decode transaction

```
{
  "txid": "59ff4adafb47a5b22c6434af38f6e138c9008356778ed8b308c48029d7d4032f",
  "hash": "1bef48f96d18f1c78021b7e4b0a7d5285f6f7d2cc8c7adc31671820e367c3d70",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "88fb1408675c774c36692f170c6122af49cab7a5bab336272f0e4d8c0ef8c89a",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "3044022070b753c99e2b6d241fd8a4ebe26f53644ef3eea58fff743e51f7a69e1ee7a99602204cbe9a60fc25be24baa3e4613f27a3e51df4a285174e001b62de18e1da2e42fd01",
        "03494041191fd2b02579fd49877755e55d9d451a37c6d0bbe04aab8ef507a78b19"
      ],
      "sequence": 4194305
    }
  ],
  "vout": [
    {
      "value": 49.99100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 18363770025baac1ebdb99a948eab2776d9568ae",
        "hex": "001418363770025baac1ebdb99a948eab2776d9568ae",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qrqmrwuqztw4vr67mnx55364jwake269w8hl5fe"
        ]
      }
    }
  ]
}

```

I Give an error when I try to use sendrawtransaction

```
error code: -26
error message:
non-BIP68-final (code 64)

```

And it's correct because my UTXO (`88fb1408675c774c36692f170c6122af49cab7a5bab336272f0e4d8c0ef8c89a`) come from the block with height 2 and 113 confirmations, and its median time is `1590276467` (2020-05-24 01:27:47 CET/CEST) and My transaction is valid after 512 seconds (Date:2020-05-24 01:41:23 CET/CEST) and the best block has that value 2020-05-24 01:28:06 CET/CEST (it's not useful)

Now, If I create another transaction with the TXID comes from block with height 1 and 114 confirmations it works, I can send it.
Below my transaction and details.

```
{
  "txid": "f98d3ef70ca2c9d797bf7fff2e96e07f5ba10a280186a2132c6a902eebcab31e",
  "hash": "5776ad750fe759411a1ed5aa10e759b33e52b2935555d90b997fa788c9e25405",
  "version": 2,
  "size": 191,
  "vsize": 110,
  "weight": 437,
  "locktime": 0,
  "vin": [
    {
      "txid": "e1ee4602a78ab4f5f58705a75405d2f223307989950e1cbe03a4518cf23b7914",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402200641ef29e3f0c8ef0c55dbb4a86a752e3655dd0c928c4e2e6659d3beeaf3f3870220026821b9ba043894cb20c7d7a378eaae76f56400755bf412f8ab1524a9a238b301",
        "03494041191fd2b02579fd49877755e55d9d451a37c6d0bbe04aab8ef507a78b19"
      ],
      "sequence": 4194305
    }
  ],
  "vout": [
    {
      "value": 49.99100000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 18363770025baac1ebdb99a948eab2776d9568ae",
        "hex": "001418363770025baac1ebdb99a948eab2776d9568ae",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bcrt1qrqmrwuqztw4vr67mnx55364jwake269w8hl5fe"
        ]
      }
    }
  ]
}

```

The median time of block 1 and 114 confirmations is `1590276486` (2020-05-24 01:28:06 CET/CEST) and my transaction should be valid after 512 seconds (2020-05-24 01:45:05 CET/CEST), and my best block median time is 2020-05-24 01:28:06 CET/CEST

Below, the details of block 2 with 114 confirmations

```
{
  "hash": "5f769f610f29057577611868a660b353bea06e51d94905f3dbf7fb93e60a3d30",
  "confirmations": 1,
  "strippedsize": 214,
  "size": 250,
  "weight": 892,
  "height": 114,
  "version": 536870912,
  "versionHex": "20000000",
  "merkleroot": "1699f1cebdde9f4da1211f948f2ec194f7820fcfbab80c93bb5ea486e6837be7",
  "tx": [
    "1699f1cebdde9f4da1211f948f2ec194f7820fcfbab80c93bb5ea486e6837be7"
  ],
  "time": 1590276487,
  "mediantime": 1590276486,
  "nonce": 0,
  "bits": "207fffff",
  "difficulty": 4.656542373906925e-10,
  "chainwork": "00000000000000000000000000000000000000000000000000000000000000e6",
  "nTx": 1,
  "previousblockhash": "36f373a49886a31eff05ff8de39722f589cff103bed47715dd697d14350539ce"
}

```

Now, I know the sequence (`00000000010000000000000000000001`) is checked on median time of UTXO's block, But block 2 (with 114 confirmations) and block 3 (with 113 confirmations) are very similar and very close, and I don't understand why with block height 2 I'm able to send the transaction.

**Tags:** transactions, sequence, checksequenceverify


---

## 1 answers

### Answer by username_0 on 2020-05-24. Score: 1

I just see that [BIP68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki) states

```
    // Time-based relative lock-times are measured from the
    // smallest allowed timestamp of the block containing the
    // txout being spent, which is the median time past of the
    // block prior.

```

so, the relative timelocks for UTXOs in the block 1 (which 114 confirmations) are verified against the mediantime of the prior block, so the block with height 0 in regtest has a hardcoded median time to 2011 ("mediantime": 1296688602, 2011-02-03 00:16:42 CET/CEST)


---

