RecordBytesSent() does not require cs_vSend to be locked, so reduce the scope of cs_vSend.
Also correctly annotate the CNode data members that are guarded by cs_vSend.
This is a simpler alternative to #19673.
Concept ACK. Will review next year.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
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.
Concept ACK
Thanks for improving locking!
1522 | - if (nBytes) { 1523 | - RecordBytesSent(nBytes); 1524 | - } 1525 | + if (sendSet) { 1526 | + // Send data 1527 | + size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, {return SocketSendData(pnode);});
stylistic yocto-nit: could drop the curly braces for the lambda argument here -- according to git grep WITH_LOCK.*return on all other places the code is directly passed, w/o putting in a block.
size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
OTOH maybe the way in this PR is preferred and the others should be adapted (though not in this PR, obviously), IDK.
Fixed. Much nicer, thanks!
ACK a06c1ed04dd6b318eb0e7aa0e152ded834b647d6 🔒
re-ACK 378aedc45248cea82d9a3e6dc1038d6828008a76
1521 | - size_t nBytes = SocketSendData(pnode); 1522 | - if (nBytes) { 1523 | - RecordBytesSent(nBytes); 1524 | - } 1525 | + if (sendSet) { 1526 | + // Send data
in the first commit: I think the code is already self-documenting. No need for this
I only kept this because there was a comment before but you're right - it's useless. Removing.
1522 | - if (nBytes) { 1523 | - RecordBytesSent(nBytes); 1524 | - } 1525 | + if (sendSet) { 1526 | + // Send data 1527 | + size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
same commit: The lock annotation for this member function SocketSendData is in the wrong place. Should be in the h file not the cpp file because otherwise moving code can disable the annotation.
Would be nice to fix in this pull and maybe also update the SocketSendData pointer arg to a reference?
Done.
review ACK 378aedc45248cea82d9a3e6dc1038d6828008a76 🔌
<details><summary>Show signature and timestamp</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK 378aedc45248cea82d9a3e6dc1038d6828008a76 🔌
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUh/bAwAlAViNkPZb/+MFuod/2ZmdPPu+12UtIpBh3oTcEKw+G/wdVHJ7fCPI7Tv
yvd8cPzeOKp3dXSqsuTu6UOHJ9+mcRodOkiu9F6smvgo0NLIC+DKYFUoRD8ywaEN
2GhjFdiIKJoaDPRLM+YA3FEVbJG1oxqUX6ifnlk/Zyh+/zCLd5l4S3GqcLQmhyJ/
4guvd1eq9a4H1apiGEop3j75Xm+jFvou07WF31RJgJgmP9L3WELsYItcpLe7+Gar
nVhL6amBwh4Ctt2DYcggNhP3mk/a6bOSvYVBDOAlfya4SOlg1weBXwjU1o1jpv2C
X5HgiToUfl4UzlYoFz7kxPoFJHCMhgaTadL23IiJpf5Tm/nNX/NVcJbTf5+WRUfd
ns/enM8FESK7cp4z4qwnOk1EY5tfHhrGTnXx36GaVyABggL/TaObMxrGZbxjBiPx
T8wByTCoTUdpXHjtqloT3AzLoJq8uTRJQlyd5WyqPjQbn75hcBij1JmprCD6KoUo
CAf3cVsZ
=tcoi
-----END PGP SIGNATURE-----
Timestamp of file with hash df2bf40ec7e87ed6608ff1eeaa002645df088c8901feef602a141b1ef0909d5f -
</details>
let me know if you want this merged or address the style nits
let me know if you want this merged or address the style nits
I'll address your review comments. Might as well fix those things up while I'm touching this code.
Thanks for the review @MarcoFalke. I've addressed your comments.
CI is failing now:
In file included from net.cpp:10:
./net.h:451:77: error: member access into incomplete type 'CNode'
size_t SocketSendData(CNode& pnode) const EXCLUSIVE_LOCKS_REQUIRED(pnode.cs_vSend);
^
./net.h:39:7: note: forward declaration of 'CNode'
class CNode;
^
1 error generated.
ok, reverting to commit 378aedc which has two ACKs already. Any style issues can be fixed up in future PRs.
ACK 378aedc45248cea82d9a3e6dc1038d6828008a76
This is definitely the right way to fix this.