wallet: Remove Boost from DecodeDumpTime #17245

pull elichai wants to merge 3 commits into bitcoin:master from elichai:2019-10-DecodeDumpTime changing 4 files +50 −16
  1. elichai commented at 10:38 pm on October 24, 2019: contributor

    Utilizing C++11 and platform specific function(timegm) to replace the usage of boost in converting a timestamp in string to a unix epoch.

    Moved the old function to the unit tests to check for consistency (in case there’s some corner case in timezones)

    Sadly C++11 doesn’t have anything to handle timezones currently(C++20 seems to have heh) so I had to use timegm from POSIX and _mkgmtime from windows.

    Tested on linux only.

  2. Remove boost usage from time string to int conversation 24a1ecdac4
  3. Added tests for converting time string to int ed2e8afc87
  4. maflcko renamed this:
    Removing Boost from DecodeDumpTime
    wallet: Remove Boost from DecodeDumpTime
    on Oct 24, 2019
  5. maflcko added the label RPC/REST/ZMQ on Oct 24, 2019
  6. maflcko added the label Wallet on Oct 24, 2019
  7. maflcko added the label Refactoring on Oct 24, 2019
  8. laanwj commented at 10:48 pm on October 24, 2019: member

    The function to format a ISO8601 datetime is called FormatISO8601DateTime, maybe this should be ParseISO8601DateTime?

    Also: there seems to be no error handling; how does this handle invalid input? (I guess returning 0 would be OK, but not crashing or raising an exception, though not sure, it’s something to think about at least) (nm, I missed the iss.fail() bit)

  9. elichai commented at 11:20 pm on October 24, 2019: contributor

    Great :) I actually looked for a header to include this so I won’t need to do manual declaration in the test.

    I’ll rename it and move it to time.h/cpp

  10. laanwj commented at 9:20 am on October 25, 2019: member

    I’ll rename it and move it to time.h/cpp

    Yes, that’d make sense! Could also do some roundtrip tests then.

    I’m a bit concerned about using timegm; from the man page:

    0CONFORMING TO
    1       These functions are nonstandard GNU extensions that are also present on the BSDs.  Avoid their use.
    

    Such an explicit warning makes me feel bad. Seems sure this is going to cause builder complaints on some obscure or less obscure platform (does this exist on Android ?). It might be worse than just relying on boost.

    I wonder if we can find an alternative to this. The old code did:

    0return (ptime - epoch).total_seconds();
    

    Doesn’t the same trick exist for C++11 time manipulation?

    Edit: weird! travis failure looks like std::get_time isn’t available on trusty. Looks like these were only added in GCC 5.

  11. elichai commented at 10:39 am on October 25, 2019: contributor

    I’m a bit concerned about using timegm; from the man page:

    0CONFORMING TO
    1       These functions are nonstandard GNU extensions that are also present on the BSDs.  Avoid their use.
    

    Such an explicit warning makes me feel bad. Seems sure this is going to cause builder complaints on some obscure or less obscure platform (does this exist on Android ?). It might be worse than just relying on boost.

    I’ll need to check if Android has it. I’m pretty sure glibc had it for a while so anything glibc should be fine. But I’ll look into it when I’m on my laptop again. We could copy glibc’s implementation (bad idea). Or technically we could drop the string representation and just store the epoch, Altough that will be a breaking change that I’m not even sure what it’ll affect exactly.

    I wonder if we can find an alternative to this. The old code did:

    0return (ptime - epoch).total_seconds();
    

    Doesn’t the same trick exist for C++11 time manipulation?

    Not that I could find. I’ll try to look more. But maybe we better off leaving it with boost for now (and coming back to it when we’re actually ready to get rid of boost once and for all)

    Edit: weird! travis failure looks like std::get_time isn’t available on trusty. Looks like these were only added in GCC 5.

    That’s just weird. So before gcc5 they didn’t fully support c++11?

  12. laanwj commented at 10:49 am on October 25, 2019: member

    We could copy glibc’s implementation (bad idea)

    That would be a license violation (LGPL is not compatible with MIT). We could use or copy from some other library which is MIT-compatibly-licensed. But yes, probably not worth it as long as it’s still using boost for so many other things. It’s surprising how involved “parse a ISO8601 datetime” is in C++ with just the standard library, even C++11.

    That’s just weird. So before gcc5 they didn’t fully support c++11?

    Apparently!

  13. elichai commented at 10:50 am on October 25, 2019: contributor
    FWIU the boost trick is just because boost’s time isn’t unix time. So if you want to get the time since unix epoch you need to subtract unix time 0 from your time.
  14. elichai commented at 11:33 am on October 25, 2019: contributor

    It’s surprising how involved “parse a ISO8601 datetime” is in C++ with just the standard library, even C++11.

    Yeah it seems like timezones stuff will only get in in C++20.

    There’s also strptime(3) which might work. And it’s posix instead of a gnu extension. (but then windows https://social.msdn.microsoft.com/Forums/vstudio/en-US/199a0e75-cb51-40b8-8e3c-230f65a2f4a4/alternative-for-strptime?forum=vcgeneral)

  15. laanwj commented at 11:43 am on October 25, 2019: member
    FWIW strptime is disallowed by test/lint/lint-locale-dependence.sh because its date parsing can be locale-dependent (month names, for example, though not relevant for this specific case).
  16. elichai commented at 1:05 pm on October 25, 2019: contributor
    Right. forgot about that. (I see that getdate(3) is also there) @laanwj do you know if the format always looks like this? 2019-10-24T23:46:06Z i.e. YYYY-MM-DDTHH:MM:SSZ. if so I can probably write an easy parser from that to std::tm and then use mktime to get the time_t.
  17. laanwj commented at 1:16 pm on October 25, 2019: member

    @laanwj do you know if the format always looks like this? 2019-10-24T23:46:06Z

    Yes, it always looks like that.

    But to be honest I think it’s better to revisit this later. Likely, at the time that we’re really ready to get rid of boost, trusty is no longer a relevant platform, and it can simply use std::gettime.

    and then use mktime to get the time_t.

    mktime uses the local timezone (and does something with daylight saving time), it’s unfortunately not useful for this. This is why GNU added timegm in the first place.

  18. Rename DecodeDumpTime to ParseISO8601DateTime 5b87433195
  19. elichai commented at 1:42 pm on October 25, 2019: contributor

    But to be honest I think it’s better to revisit this later. Likely, at the time that we’re really ready to get rid of boost, trusty is no longer a relevant platform, and it can simply use std::gettime.

    Yeah :/ I guess we’ll leave this for a while and I’ll move on :)

  20. maflcko commented at 1:45 pm on October 25, 2019: member
    I guess the rename can be done today. I wasn’t aware that this util forms a round trip with FormatISO8601DateTime.
  21. DrahtBot commented at 4:53 pm on October 25, 2019: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16037 (rpc: Enable wallet import on pruned nodes by promag)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  22. laanwj commented at 10:45 am on October 26, 2019: member

    Yes, doing the rename/move separately might be worthwhile.

    maybe instead of getting rid of boost dep, new goal should be “isolate boost usage to a few places that we know are pain points” (such as date/time/sleep/filesystem handling)

  23. maflcko added the label Waiting for author on Oct 26, 2019
  24. elichai commented at 6:13 pm on October 26, 2019: contributor
    Opened #17266
  25. elichai closed this on Oct 26, 2019

  26. maflcko referenced this in commit cfec3e01b4 on Oct 28, 2019
  27. fanquake removed the label Waiting for author on May 28, 2020
  28. practicalswift commented at 9:29 pm on February 17, 2021: contributor

    Now that #21110 has been merged I think it might be time to resurrect this PR :)

    Context: #21110 (comment)

  29. laanwj added the label Up for grabs on Feb 18, 2021
  30. maflcko commented at 12:09 pm on May 12, 2022: member
  31. bitcoin locked this on May 12, 2023
  32. maflcko removed the label Up for grabs on Jan 5, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 13:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me