Skip to content

Conversation

@amitiuttarwar
Copy link
Contributor

Based on reviewing #21188

the first commit switches the lock annotations on CheckInputScripts to be on the function declaration instead of on the function definition. this ensures that all call sites are checked, not just ones that come after the definition.

the second commit adds a note to the developer-notes section to clarify where the annotations should be applied.

@amitiuttarwar
Copy link
Contributor Author

to test this out, reviewers can apply this diff locally

- bool CheckInputScripts(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck>* pvChecks)
+ RecursiveMutex cs_new;
+ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck>* pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_new)

and see that the compiler warns about the call site from ConnectBlock:

validation.cpp:2136:35: warning: calling function 'CheckInputScripts' requires holding mutex 'cs_new' exclusively [-Wthread-safety-analysis]
            if (fScriptChecks && !CheckInputScripts(tx, tx_state, view, flags, fCacheResults, fCacheResults, txsdata[i], g_parallel_script_checks ? &vChecks : nullptr)) {

but there is no warning from the call site from CheckInputsFromMempoolAndCache or PolicyScriptChecks.

then you can apply the annotation to the declaration instead of the definition, and see that all the call sites generate warnings.

@hebasto
Copy link
Member

hebasto commented Feb 17, 2021

If this pr a case to apply #20986?

…laration

When the annotation is on the definition, it does not check call sites between
the declaration and the definition.
@amitiuttarwar
Copy link
Contributor Author

thanks for the review @hebasto, took all your suggestions.

If this pr a case to apply #20986?

done

@maflcko maflcko added Refactoring and removed Docs labels Feb 18, 2021
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK 25c57d6.

How about adding a validation_p.h with these "private" declarations?

@maflcko
Copy link
Member

maflcko commented Feb 22, 2021

ACK 25c57d6 🥘

Show signature and timestamp

Signature:

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

ACK 25c57d640992255ed67964a44b17afbfd4bed0cf 🥘
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUghXQwAxK2rZIu0qYdOFsfc6ncH58m6umvxB6lxhN7rpYnpz1AyiCe4+RbYe2Nx
ty820uHzkkQSb7eu40NeO7OkqcjlXHeUDSzXzzReSbOi90OLJa5pX4vMiur4chlP
AiGAQLuHhDtDOwOySpVBR7NxHkcaCUjD5CrGkbBieLaTJlmYcwqpI4hycCAR9A4h
Yg2hfcpwosTyUA7NNrk8F50UK7Ez97slqvDd7CLcI70jvEGpMiGO/YW1w2HqgJkP
s6x7l0g3Frd9q7VA/EucZoMZYbDnoWEGyP88UaT2G727WxuYhRrUDVVP7srND7Z1
JSNSzm/4v9eJtfaD0D/9xcgN0YxF6DRJqyJK6fPJAMdoimvpFIqyg2NowRaRcvHz
zTTTcygMRV6l/HMDNdNJ59VwWlvxE3MHu4yzSntRtgNaeW/a3bTnm4XZAcF5woQZ
2QhiNmS8BmHj2URMXcrNJmUmnWPj4bHaZuOhqIhvr8UMPeBhzTAzyT6Pyn3xU7Hs
4pT3enGx
=pXvj
-----END PGP SIGNATURE-----

Timestamp of file with hash 29b3e3a94f59f0a1d3ed2364dbf2aa60e4373ca5a3c8c71576d43351cf60215b -

@maflcko maflcko merged commit 34d7030 into bitcoin:master Feb 22, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 22, 2021
@amitiuttarwar amitiuttarwar deleted the 2021-02-locks branch February 22, 2021 18:11
@amitiuttarwar
Copy link
Contributor Author

@promag where are other examples of forward declaring functions from the tests? I see examples for other files eg. denialofservice_tests have declarations for orphan handling stuff from net_processing. But I'm not seeing other declarations for internal validation.cpp functions. I'm definitely open to the pattern of test-only header files, but in this case, seems like it might be a bit of overkill to have an additional header file for just one function? Unless I'm missing something?

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 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.

5 participants