Introduce a Poisson helper method that wraps the existing method to return std::chrono::duration
type, which is mockable.
Needed for #16698.
Introduce a Poisson helper method that wraps the existing method to return std::chrono::duration
type, which is mockable.
Needed for #16698.
948-
949-
950 /** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
951 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
952
953+/** Wrapper to return mockable type */
0/** Return a timestamp in the future for exponentially distributed events. */
nNextInvSend
to the new type and use the new function there. Also, a unit test to assert that the two methods return the same value would be nice.
nNextInvSend
. Not sure how to unit test since the result of the poisson method would be different for two separate calls. LMK if you want deeper changes with chrono types, happy to update.
g_mock_deterministic_tests = true;
for just your test case, then set it to false
again at the end.
ACK d504d70e602bf30aad18e1e5677daa3961757bb7
Signature:
0-----BEGIN PGP SIGNED MESSAGE-----
1Hash: SHA512
2
3ACK d504d70e602bf30aad18e1e5677daa3961757bb7
4-----BEGIN PGP SIGNATURE-----
5
6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
7pUgYJAv+Nkm4e1Ac/wfPzNKwyAfkC7oRMCGqY1IqPm0vCugazxm+02u7JFotM4rI
8j75ONrqy/LC7TAk7ELIWUfJv0lquBLGpkz5ZuYAcfAH8CjSj9NEt1bfm+XRmmXFe
9jxLvL068KeDbz/6i2vwwQW3557/0A5p1z8zmTh66IXF7lQU/yjpSAOK5BXXxoVs8
10sMqj2o1vZ7TMPZlGTxZxMQB49DUxdRi6TYMKssS7lJqrVbtTxHZcTwzdfOWWVg6e
11epAow+pvO1GRV0yYjMzhAXH8HM3500GI3b66gVvvDpIbQK9+pvYDFuVadSHDYvpK
12cbpbu5uXhaskeI5OOiv03L3v7lHrRQi/y01w03mD3SgGW66nE2YkN8L6+I5mk6Li
13LovIQIvTr6x62xjt5YqYGZW+35RRYdIg1tueNKqmCSAYRGo7kBjUnDyCA3Y8/JGB
14jv+afA/RUT2U+8lHYyZkV6rSr9HRuq16DKutyYGiz4VWeyGC0OtUCInf0fvnJkY8
15380rfFsr
16=RKgu
17-----END PGP SIGNATURE-----
Timestamp of file with hash e887cddc7cfb3c4288a10e649645fa1687a1de16f54a8b1819200b2eaa1c86a8 -
3547@@ -3548,6 +3548,8 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3548
3549 // Address refresh broadcast
3550 int64_t nNow = GetTimeMicros();
3551+ auto current_time = GetTime<std::chrono::microseconds>();
{ }
around the inventory code but found that fFetch
is assigned between the two definitions of current_time
and accessed after. is there a way to scope independently?
fFetch
than I miss ?
ah gotcha. I was hesitant to move the declaration of current_time
bc of potential change in logic based on how long code execution between the two spots would take. maybe its ok but I didn’t dig into it / want to make the PR harder to review.
I’m going to leave it as is but thanks for the suggestion & clarification
761@@ -762,7 +762,7 @@ class CNode
762 bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
763 // Last time a "MEMPOOL" request was serviced.
764 std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
765- int64_t nNextInvSend{0};
766+ std::chrono::microseconds nNextInvSend{std::chrono::microseconds{0}};
std::chrono::microseconds nNextInvsend{0};
seems like it would be fine?
309+
310+ int64_t now = 5000;
311+ int average_interval_seconds = 600;
312+
313+ std::chrono::microseconds now_chrono = std::chrono::microseconds{now};
314+ std::chrono::seconds interval_chrono = std::chrono::seconds{average_interval_seconds};
std::chrono::microseconds now_chrono{now};
likewise, or could just say ::PoissonNextSend(std::chrono::microseconds{now}, std::chrono::seconds{average_interval_seconds})
re-ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686
Signature:
0-----BEGIN PGP SIGNED MESSAGE-----
1Hash: SHA512
2
3re-ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686
4-----BEGIN PGP SIGNATURE-----
5
6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
7pUjapAv+MgqGwdYAgJg/hzj7rhv2Fp+bXSWfAoF4Sgqeo7yZbQLfupqRev/uf3hP
8DgC6rpyqIM2X8JuijUVxyOs2Z+bU8pOZMOpzVOGpZPHcgmBP1lVT+BqoV3iVgwD2
96dihYwbFOZIZz4jRyAn8Ca9Aoo4jRXY82kPKhhLfo4lRIcp19v0KzccyLeE3rwzh
10Do7I5M0PISDid6t2xv57+8R+W5IZy5VChShEx3aHkGLVWR5Qwa01WnoPnPV5uQJO
11amkT+i0i5TIRyyN8vSIJWLHfa7BJmG3cRAwekoq0hEeaFw3513hMFPtq+ekfOKb+
12DdNFVFYPk5tkTfnYDHcjzxob2phFtEDpPxII8miRu1pFFhkSmcEUswEQZMCykcqi
13CBddH8/oGs0G7yPjPtJ6GrmITsJHRwxhlxTyXarx3dm7F78AomLvDYRWUncSgGrh
14X7k7PP2ZYTIZIe6YBiPQ1Y6zf73qdw52bsMtXhD5Fj9v/KTZMcW93IghKppmx6Hl
15vnB9QRAE
16=kQL2
17-----END PGP SIGNATURE-----
Timestamp of file with hash c18dd002e27bda4c5087dbc652b61c6e0ece0bbd73a3416548d7cf0624aca3fb -
@naumenkogs I’d like to work on replacing nNow
in SendMessages
entirely with current_time
, but haven’t prioritized yet bc I’m focused on rebroadcast stuff.
Are your concerns limited to the test case introduced or do you also have concerns about the code path? I don’t see how problems could occur, so I’d love if you could explain further?
ah from IRL convo with AJ, he pointed out how it can be confusing from tests based on what functionality executes based on clock time vs needing to update mocktime. Is that what you’re alluding to?
tests based on what functionality executes based on clock time vs needing to update mocktime. Is that what you’re alluding to?
Yes. Also, potentially future code in net_processing. At the same time, I guess it blocks you from proceeding with rebroadcast (even in terms of better testing) today.
ACK 1a8f0d5, and let’s merge it and come back to it later.