<p>Since you say you are changing your OS clock, I am assuming you are using Bitcoin Core's built in miner for regtest. This miner will try to not produce invalid blocks.</p>

<p>To avoid the <code>time-too-old</code> failure, it will take the maximum between the median time + 1, and the network adjusted time (which is basically OS time). So when you set the clock too far back, it will end up creating a block that is 1 second ahead of the median time which is valid.</p>

<p>You aren't getting the <code>time-too-new</code> error because Bitcoin Core is using the system time in that check, not median time. A block that is too new will become valid after time has passed. So it uses the OS time for that check, not median time. As such, when you set your OS clock 3 hours in the future, it produces a block with a timestamp 3 hours in the future and compares that to the OS clock which is also 3 hours in the future. This comparison finds that the block is not too new, so it does not fail.</p>

<p>In order to test these specific errors, you need to implement your own miner to produce blocks with the parameters that you want to use. Bitcoin Core's test suite has an independent miner in python which is how these specific failures are tested.</p>

CC BY-SA 4.0
2020-05-14T03:05:59.933Z
2020-05-14T03:05:59.933Z
Ava Chow
<p>we are playing with the regtest and we don't able to replicate the two blocks validation error managed here
<a href="https://github.com/bitcoin/bitcoin/blob/5b24f6084ede92d0f493ff416b4726245140b2c1/src/validation.cpp#L3493-L3499" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/5b24f6084ede92d0f493ff416b4726245140b2c1/src/validation.cpp#L3493-L3499</a></p>

<p>We understand that <code>GetBlockTime</code> and <code>nAdjustedTime</code> have values near os <code>now()</code> time so move manually the os clock can trigger the validation errors.</p>

<p>But we were unable to :(</p>

<p>Step to reproduce "time-too-old"</p>

<ul>
<li>start bitcoin regtest daemon</li>
<li>mine 101 block</li>
<li>change the os clock 1h behind</li>
<li>mine a new block</li>
</ul>

<p>we expect to get "time-too-old" validation error but we got no error</p>

<p>Step to reproduce "time-too-new"</p>

<ul>
<li>start bitcoin regtest daemon</li>
<li>mine 101 blocks</li>
<li>change the os clock 3h forward</li>
<li>mine a new block</li>
</ul>

<p>we expect to get "time-too-new" validation error but we got no error</p>

<block><miner-configuration><regtest>
Unable to replicate block header validation errors: time-too-old and time-too-new
monkeyUser
# Unable to replicate block header validation errors: time-too-old and time-too-new

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

we are playing with the regtest and we don't able to replicate the two blocks validation error managed here
<https://github.com/bitcoin/bitcoin/blob/5b24f6084ede92d0f493ff416b4726245140b2c1/src/validation.cpp#L3493-L3499>

We understand that `GetBlockTime` and `nAdjustedTime` have values near os `now()` time so move manually the os clock can trigger the validation errors.

But we were unable to :(

Step to reproduce "time-too-old"

* start bitcoin regtest daemon
* mine 101 block
* change the os clock 1h behind
* mine a new block

we expect to get "time-too-old" validation error but we got no error

Step to reproduce "time-too-new"

* start bitcoin regtest daemon
* mine 101 blocks
* change the os clock 3h forward
* mine a new block

we expect to get "time-too-new" validation error but we got no error

**Tags:** block, miner-configuration, regtest


---

## 1 answers

### Answer by username_1 on 2020-05-14. Score: 1 | Accepted answer

Since you say you are changing your OS clock, I am assuming you are using Bitcoin Core's built in miner for regtest. This miner will try to not produce invalid blocks.

To avoid the `time-too-old` failure, it will take the maximum between the median time + 1, and the network adjusted time (which is basically OS time). So when you set the clock too far back, it will end up creating a block that is 1 second ahead of the median time which is valid.

You aren't getting the `time-too-new` error because Bitcoin Core is using the system time in that check, not median time. A block that is too new will become valid after time has passed. So it uses the OS time for that check, not median time. As such, when you set your OS clock 3 hours in the future, it produces a block with a timestamp 3 hours in the future and compares that to the OS clock which is also 3 hours in the future. This comparison finds that the block is not too new, so it does not fail.

In order to test these specific errors, you need to implement your own miner to produce blocks with the parameters that you want to use. Bitcoin Core's test suite has an independent miner in python which is how these specific failures are tested.


---

