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 */
/** Return a timestamp in the future for exponentially distributed events. */
I'd rather have the comment draw attention to the fact that its just calling through to the other Poisson method. Esp with the other function signature & comment right there.
Please switch 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.
@MarcoFalke updated 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.
You can set g_mock_deterministic_tests = true; for just your test case, then set it to false again at the end.
@MarcoFalke added tests. Ready for review.
ACK d504d70e602bf30aad18e1e5677daa3961757bb7
<details><summary>Show signature and timestamp</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK d504d70e602bf30aad18e1e5677daa3961757bb7
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgYJAv+Nkm4e1Ac/wfPzNKwyAfkC7oRMCGqY1IqPm0vCugazxm+02u7JFotM4rI
j75ONrqy/LC7TAk7ELIWUfJv0lquBLGpkz5ZuYAcfAH8CjSj9NEt1bfm+XRmmXFe
jxLvL068KeDbz/6i2vwwQW3557/0A5p1z8zmTh66IXF7lQU/yjpSAOK5BXXxoVs8
sMqj2o1vZ7TMPZlGTxZxMQB49DUxdRi6TYMKssS7lJqrVbtTxHZcTwzdfOWWVg6e
epAow+pvO1GRV0yYjMzhAXH8HM3500GI3b66gVvvDpIbQK9+pvYDFuVadSHDYvpK
cbpbu5uXhaskeI5OOiv03L3v7lHrRQi/y01w03mD3SgGW66nE2YkN8L6+I5mk6Li
LovIQIvTr6x62xjt5YqYGZW+35RRYdIg1tueNKqmCSAYRGo7kBjUnDyCA3Y8/JGB
jv+afA/RUT2U+8lHYyZkV6rSr9HRuq16DKutyYGiz4VWeyGC0OtUCInf0fvnJkY8
380rfFsr
=RKgu
-----END PGP SIGNATURE-----
Timestamp of file with hash e887cddc7cfb3c4288a10e649645fa1687a1de16f54a8b1819200b2eaa1c86a8 -
</details>
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>();
I think you can scope definition to inventory code part, would make code easier to read and also don't need to change drop constness of other current_time
tried to introduce scoping with { } 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?
This compile : https://github.com/ariard/bitcoin/commit/1c1765e636db2c9484d10712596754dd774ed7bd, or are you describing a behavior change related with 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})
ACK d504d70e602bf30aad18e1e5677daa3961757bb7 nits only
ACK d504d70, checked directly on parent PR the rational of intended changes
@amitiuttarwar This has three ACKs, so is ready to go. Do you want to address the nits or leave them for later?
ACK d504d70 willing to do quick re-ACK if those tiny nits are resolved :)
ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686
re-ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686
<details><summary>Show signature and timestamp</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
re-ACK 1a8f0d5a74d5cc0000456932babf35301f5c1686
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjapAv+MgqGwdYAgJg/hzj7rhv2Fp+bXSWfAoF4Sgqeo7yZbQLfupqRev/uf3hP
DgC6rpyqIM2X8JuijUVxyOs2Z+bU8pOZMOpzVOGpZPHcgmBP1lVT+BqoV3iVgwD2
6dihYwbFOZIZz4jRyAn8Ca9Aoo4jRXY82kPKhhLfo4lRIcp19v0KzccyLeE3rwzh
Do7I5M0PISDid6t2xv57+8R+W5IZy5VChShEx3aHkGLVWR5Qwa01WnoPnPV5uQJO
amkT+i0i5TIRyyN8vSIJWLHfa7BJmG3cRAwekoq0hEeaFw3513hMFPtq+ekfOKb+
DdNFVFYPk5tkTfnYDHcjzxob2phFtEDpPxII8miRu1pFFhkSmcEUswEQZMCykcqi
CBddH8/oGs0G7yPjPtJ6GrmITsJHRwxhlxTyXarx3dm7F78AomLvDYRWUncSgGrh
X7k7PP2ZYTIZIe6YBiPQ1Y6zf73qdw52bsMtXhD5Fj9v/KTZMcW93IghKppmx6Hl
vnB9QRAE
=kQL2
-----END PGP SIGNATURE-----
Timestamp of file with hash c18dd002e27bda4c5087dbc652b61c6e0ece0bbd73a3416548d7cf0624aca3fb -
</details>
Is it a good idea to have both nNow and current_time? This might lead to counter-intuitive consequences, specifically in the test cases (I don't have the exact example right now).
@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.