2

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.