Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Jun 6, 2020

Only GetTimeOffset() and AddTimeData() functions lock this mutex. They do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the g_timeoffset_mutex could be a non-recursive mutex.

Related to #19180.

@maflcko
Copy link
Member

maflcko commented Jun 7, 2020

Concept ACK. (nit: Could add a new commit to clang-format the whole file while touching it anyway?)

@hebasto
Copy link
Member Author

hebasto commented Jun 7, 2020

Updated c2410ce -> cc5c0d2 (pr19189.01 -> pr19189.02, diff):

nit: Could add a new commit to clang-format the whole file while touching it anyway?

@maflcko
Copy link
Member

maflcko commented Jun 7, 2020

ACK cc5c0d2 , checked the second commit with --word-diff-regex=. --ignore-all-space -U0 🦉

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK cc5c0d2299b09c58cd9962ca5075ffa53f2633c0 , checked the second commit with  --word-diff-regex=. --ignore-all-space -U0 🦉
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUg9ywv/RuHDTDtPin6ga49t7Vslgym8iyJlbJNII/rcUL4iqxTbocvKoIpaJS4O
URw7HGDe8sr5pBCEuwtM1lKgOxR9JQ2grVLisimxl99rQdLUd8ryCfS5KfAj4Ta+
R5P1IMKO7/oSlovhcnWCoF7IXFcEDbSlYIz+OqYpDYBM6VtadUHTxvy37Tq/nLxO
N+V2CZa2f09toH35OVv019BdSOQ/GiaiAAyMHY4Fwzjgyl7hLTa2DUKuGY/9Myt1
goCN/C+aqtk/O0eNmF87Tq9yARaoba70L9zhNafGNgDB7XFnPY72xrJueCaY/+lm
G2m24ZUVmGbb8NolwXJ6/57J0nysNu/aDZFsDXTpweb3px/uIsOtuivD6zXkMo7f
gvAJ274hCz6DJTXWkyDPJOEk99SFbn6aQaayIBLhdoo5HxihmNNUKhuBnQl0pSPw
5ZsVLD8WQTIPhAeblnm3U6E3ytF2UrZK0yq0yuNWwf8C0Z5YJceUKvYHnM09o0KC
KTFf3Fc3
=r9Js
-----END PGP SIGNATURE-----

Timestamp of file with hash bfef319e8de4b4be6ce092abda9bc310590248e63368de1b85795fcaab7291cf -

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK cc5c0d2 verified that recursion is not happening

if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;
for (const int64_t nOffset : vSorted) {
if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know clang-format did it due to AllowShortIfStatementsOnASingleLine: true and so there is nothing to do in this PR, but I just want to mention that putting the if condition and body on one line like if (A) B;

  • makes life in gdb more difficult (if one wants to set a breakpoint on B)
  • makes backtraces less usefull (if it crashed on line 92, did it crash in A or in B?)
  • skews line based code coverage (if just A is executed and it was false then the code coverage may show the entire line 92 covered, giving the false impression that B was also executed).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lean to agree with you. Just want to preserve ACKs :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only allow trivial statements in single line ifs, so it should always be clear whether it crashed in A or B.

Also, coverage reports reports generally include branch coverage.

static RecursiveMutex cs_nTimeOffset;
static int64_t nTimeOffset GUARDED_BY(cs_nTimeOffset) = 0;
static Mutex g_timeoffset_mutex;
static int64_t nTimeOffset GUARDED_BY(g_timeoffset_mutex) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/nTimeOffset/g_time_offset/, feel free to ignore. I just wonder - you changed the name of one global variable why not the other too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this commit is mutex related only :)

@hebasto
Copy link
Member Author

hebasto commented Jun 8, 2020

@sipa Mind reviewing this PR?

@maflcko maflcko merged commit 374fd6f into bitcoin:master Jun 8, 2020
@hebasto hebasto deleted the 200605-timedata branch June 8, 2020 11:11
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 10, 2021
Summary:
> Only GetTimeOffset() and AddTimeData() functions lock this mutex. They do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the g_timeoffset_mutex could be a non-recursive mutex.

This is a backport of [[bitcoin/bitcoin#19189 | core#19189]]

Test Plan:
```
CC=clang CXX=clang++ cmake .. -DENABLE_SANITIZERS=thread -GNinja
ninja all check check-functional
```

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9310
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants