-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Year 2038 time bug #21356
Comments
I believe bitcoin uses unsigned 32-bit time types so the problem if any is delayed to 2106 |
Well the hole project uses int64_t GetTime(): https://github.com/bitcoin/bitcoin/blob/master/src/util/time.cpp#L26 If you read this function you see he uses the time() function through the OS to get the epoch time. And if i read the specifications from linux about this call: On Linux, a call to time() with tloc specified as NULL cannot Basicly i dont see in the project that it uses ABI's with time_t. Also if there is a unsigned 32-bit declaired then that doesnt mean the time() function will also generate this. In this case its a time_t value. That is treated different. |
That call appears deprecated. See util/time.h
|
I also read that this apperntly will get fixed by itself over time. Like basicly its not a big issue anymore. Just a recompile over time.
|
It would be good to have a test for this. |
Side-note: It is also possible to run the tests under a specific time. E.g. |
I made a small script: #include <iostream>
#include <chrono>
#include <cstdint>
#include <cassert>
using namespace std;
int total_bits(uint64_t epoch)
{
int i = 0;
while(epoch != 0)
{
epoch /= 2;
i++;
}
return i;
}
template <typename T>
static T GetSystemTime()
{
const auto now = std::chrono::duration_cast<T>(std::chrono::system_clock::now().time_since_epoch());
assert(now.count() > 0);
return now;
}
int main()
{
int64_t epoch;
cout << "set date '2038-01-01'" << endl;
system("date +%Y%m%d -s '20380101'");
epoch = int64_t{GetSystemTime<std::chrono::seconds>().count()};
cout << "epoch = " << epoch << " (bits: " << total_bits(epoch) << ")" << endl;
system("date +%Y%m%d -s '20380201'");
cout << "set date '2038-02-01'" << endl;
epoch = int64_t{GetSystemTime<std::chrono::seconds>().count()};
cout << "epoch = " << epoch << " (bits: " << total_bits(epoch) << ")" << endl;
system("date +%Y%m%d -s '21060201'");
cout << "set date '2106-02-01'" << endl;
epoch = int64_t{GetSystemTime<std::chrono::seconds>().count()};
cout << "epoch = " << epoch << " (bits: " << total_bits(epoch) << ")" << endl;
system("date +%Y%m%d -s '21060301'");
cout << "set date '2106-03-01'" << endl;
epoch = int64_t{GetSystemTime<std::chrono::seconds>().count()};
cout << "epoch = " << epoch << " (bits: " << total_bits(epoch) << ")" << endl;
return 0;
} Result:
Basicly this tells me the std:chrono works correctly on my linux vm.
This should be tested between different compilers and os's to figure out if all of them has patched std::chrono correctly and since what version its been patched. That you can avoid old compilers. Second will be that all parts where a time is been used needs to be patched fron unsigned int/uint32_t to int64_t. As example here: bitcoin/src/primitives/block.h Line 27 in 4a54068
|
Patching |
If this Is my thinking right that the the related value of |
fafc96a test: Test year 2106 block timestamps (MacroFake) Pull request description: Alternative to bitcoin#21362 that closes bitcoin#21356 ACKs for top commit: Sjors: utACK fafc96a Tree-SHA512: 196d98f42d6f7f0222312b7bd1c68b3bd30cb6f0cbaccb900cfc5fcc689494adb2a7d7d6023c1ff1e8cf871047ec37eeca41386e31029d99cabf9343b4fd2a03
In 2038 the epoch time run out of bits and that makes it need more bits to represent the correct datetime.
https://en.wikipedia.org/wiki/Year_2038_problem
The text was updated successfully, but these errors were encountered: