txmempool: Make entry time type-safe (std::chrono) #16908

pull MarcoFalke wants to merge 3 commits into bitcoin:master from MarcoFalke:1909-mempoolEntryChrono changing 8 files +40 −23
  1. MarcoFalke commented at 5:41 pm on September 18, 2019: member

    This changes the type of the entry time of txs into the mempool from int64_t to std::chrono::seconds.

    The benefits:

    • Documents the type for developers
    • Type violations result in compile errors
    • After compilation, the two are equivalent (at no run time cost)
  2. MarcoFalke added the label Refactoring on Sep 18, 2019
  3. MarcoFalke added the label Mempool on Sep 18, 2019
  4. emilengler commented at 6:41 pm on September 18, 2019: contributor
    Concep ACK, chrono is definitely better for time managment
  5. DrahtBot commented at 8:11 pm on September 18, 2019: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16851 (Continue relaying transactions after they expire from mapRelay by ajtowns)

    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.

  6. ajtowns commented at 10:43 am on September 19, 2019: member

    ConceptACK

    I think LimitMemPoolSize() should have std::chrono::seconds age instead of unsigned long age, which means you can just pass in std::chrono::hours{gArgs.GetArg(...)}; makes it a bit tidier.

    Having int64_t as_seconds(std::chrono::seconds t) { return t.count(); } seems like it would be better than using int64_t{xxx.count()} fwiw; that way if we change xxx’s type either the conversion happens automatically if there’s no loss of precision, or you get a compile time error.

  7. test: mempool entry time is persisted
    Also, remove the now unused "Mine a single block to get out of IBD".
    This was fixed in commit 1111aecbb5.
    1111170f2f
  8. util: Add count_seconds time helper faaa1f01da
  9. MarcoFalke force-pushed on Sep 19, 2019
  10. MarcoFalke commented at 3:53 pm on September 19, 2019: member
    Thx for the review. Took all suggestions by you.
  11. txmempool: Make entry time type-safe (std::chrono) faec689bed
  12. in src/rpc/blockchain.cpp:421 in fa18adca4b outdated
    417@@ -418,7 +418,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
    418     info.pushKV("weight", (int)e.GetTxWeight());
    419     info.pushKV("fee", ValueFromAmount(e.GetFee()));
    420     info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee()));
    421-    info.pushKV("time", e.GetTime());
    422+    info.pushKV("time", int64_t{count_seconds(e.GetTime())});
    


    ajtowns commented at 11:55 am on September 23, 2019:
    No need for the int64_t{} here?

    MarcoFalke commented at 12:18 pm on September 23, 2019:
    Done
  13. MarcoFalke force-pushed on Sep 23, 2019
  14. ajtowns commented at 12:32 pm on September 23, 2019: member
    utACK faec689bed7a5b66e2a7675853d10205b933cec8
  15. in src/net_processing.cpp:1544 in faec689bed
    1540@@ -1541,11 +1541,11 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
    1541             if (mi != mapRelay.end()) {
    1542                 connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
    1543                 push = true;
    1544-            } else if (pfrom->m_tx_relay->timeLastMempoolReq) {
    1545+            } else if (pfrom->m_tx_relay->m_last_mempool_req.load().count()) {
    


    laanwj commented at 11:40 am on September 30, 2019:
    why not use count_seconds here, if it is preferred to inline .count() (according to the comment)?

    MarcoFalke commented at 11:58 am on September 30, 2019:
    The member uses a magic value of 0 to indicate that the mempool was never requested. So this check isn’t about time (in a specific type like seconds), but more about checking that any value exists.

    laanwj commented at 2:54 pm on October 2, 2019:
    Hmm, okay, I guess we’d really want a optional here some day instead of a magic value, but no need to do that here.

    sdaftuar commented at 5:39 pm on October 23, 2019:
    Sorry to chime in late – would it make sense to use the std::chrono::duration::zero value here? I found count() to be unintuitive when I was looking at related code just now (but this std::chrono stuff is new to me so I’m still figuring out how to use it).

    MarcoFalke commented at 5:48 pm on October 23, 2019:

    Comparing it to zero would also work, but still be odd, as the code is written as if the member were an optional.

    I think we can just stop treating it as optional (always assume the last mempool request time for peers was in year 1970). But that can be done in a follow up pull request.

  16. laanwj commented at 2:55 pm on October 2, 2019: member
    ACK faec689bed7a5b66e2a7675853d10205b933cec8
  17. laanwj referenced this in commit ccaef6c28b on Oct 2, 2019
  18. laanwj merged this on Oct 2, 2019
  19. laanwj closed this on Oct 2, 2019

  20. MarcoFalke deleted the branch on Oct 2, 2019
  21. sidhujag referenced this in commit 40dd4ff1e7 on Oct 2, 2019
  22. deadalnix referenced this in commit 9dfe4441b8 on Jun 11, 2020
  23. deadalnix referenced this in commit 583e959f15 on Jun 11, 2020
  24. deadalnix referenced this in commit 02d552019c on Jun 11, 2020
  25. kittywhiskers referenced this in commit 13cc113cb0 on Jul 2, 2021
  26. kittywhiskers referenced this in commit 9d69641a3d on Jul 4, 2021
  27. kittywhiskers referenced this in commit 2c26c4abb8 on Jul 9, 2021
  28. kittywhiskers referenced this in commit 93525512f7 on Jul 9, 2021
  29. kittywhiskers referenced this in commit 59d11fe8ce on Jul 9, 2021
  30. kittywhiskers referenced this in commit bb1cd62bc4 on Jul 13, 2021
  31. kittywhiskers referenced this in commit 60b4db9601 on Jul 15, 2021
  32. kittywhiskers referenced this in commit 35d7129e64 on Jul 15, 2021
  33. kittywhiskers referenced this in commit e474e02c02 on Jul 16, 2021
  34. kittywhiskers referenced this in commit 55ae8a5fe5 on Aug 1, 2021
  35. kittywhiskers referenced this in commit 6112c85671 on Aug 5, 2021
  36. kittywhiskers referenced this in commit 199a0f8d26 on Aug 5, 2021
  37. UdjinM6 referenced this in commit 7aebf156e9 on Aug 10, 2021
  38. 5tefan referenced this in commit b06db34ac7 on Aug 12, 2021
  39. DrahtBot locked this on Dec 16, 2021

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-11-17 21:12 UTC

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