Skip to content

Conversation

kiminuo
Copy link
Contributor

@kiminuo kiminuo commented May 4, 2021

This PR is a follow up PR to #21244. The PR attempts to move us an inch towards the goal by removing GetDataDir(net_specific) and replacing it by gArgs.GetDataDir(net_specific) calls.

The approach of this PR attempts to be similar to the one chosen in "De-globalize ChainstateManager" (#20158). The goal is to pass ArgsManager to functions (or ideally to have ArgsManager as a member of a class where needed; inspiration from here: #21789) instead of having it as a global variable (i.e. gArgs).

Notes:

If you know about a better approach how to do this, please share it here.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 5, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

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.

@laanwj
Copy link
Member

laanwj commented May 10, 2021

Code review and concept ACK 2ca79de
Getting the data directory seems common enough (as well as shared between all commands) to have on gArgs directly.
Agree that ideally, the arguments would be passed in some way instead of part of a global, but this is at least a step forward toward that.

Copy link
Contributor

@ryanofsky ryanofsky 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 2ca79de.

Just my opinion, but I do think since this is switching code to a new ArgsManager interface, it would be better for the interface to have explicit Base and Net methods instead of using the previous bool net_specific=true default argument. E.g. something like:

public:
    const fs::path& GetDataDirBasePath() const { return GetDataDirPath(false); }
    const fs::path& GetDataDirNetPath() const { return GetDataDirPath(true); }
private:
    const fs::path& GetDataDirPath(bool net_specific) const;

GetDataDirNetPath() would seem more readable than GetDataDirPath(true) at call sites, and harder to confuse when writing code. And since call sites are being updated in this PR anyway, implementing this would just require tweaking the scripted diffs.

@kiminuo
Copy link
Contributor Author

kiminuo commented May 10, 2021

Just my opinion, but I do think since this is switching code to a new ArgsManager interface, it would be better for the interface to have explicit Base and Net methods instead of using the previous bool net_specific=true default argument. E.g. something like:

I find this to be a very good suggestion. If this PR needs to be touched, I would do it in this PR. Otherwise, I would reserve that for a follow-up PR.

@maflcko
Copy link
Member

maflcko commented May 10, 2021

Is there a reason to suffix the return type to the function name? Wouldn't GetDataDirBase and GetDataDirNet be sufficient?

@laanwj
Copy link
Member

laanwj commented May 17, 2021

GetDataDirNetPath() would seem more readable than GetDataDirPath(true) at call sites,

Agree. Boolean arguments tend to be bad for readability.

@kiminuo kiminuo force-pushed the feature/2021-05-get-data-dir-step-2 branch 4 times, most recently from e75c34e to c8616c5 Compare May 21, 2021 08:28
@kiminuo
Copy link
Contributor Author

kiminuo commented May 21, 2021

Code review ACK 2ca79de.

Just my opinion, but I do think since this is switching code to a new ArgsManager interface, it would be better for the interface to have explicit Base and Net methods instead of using the previous bool net_specific=true default argument. E.g. something like:

public:
    const fs::path& GetDataDirBasePath() const { return GetDataDirPath(false); }
    const fs::path& GetDataDirNetPath() const { return GetDataDirPath(true); }
private:
    const fs::path& GetDataDirPath(bool net_specific) const;

GetDataDirNetPath() would seem more readable than GetDataDirPath(true) at call sites, and harder to confuse when writing code. And since call sites are being updated in this PR anyway, implementing this would just require tweaking the scripted diffs.

I have attempted to do the change you propose. Please let me know if you find it better.

(I'm sorry about the needless rebase. I got confused by a test result.)

Copy link
Contributor

@ryanofsky ryanofsky 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 c8616c5

@kiminuo kiminuo force-pushed the feature/2021-05-get-data-dir-step-2 branch from c8616c5 to 17c4128 Compare May 22, 2021 13:20
@kiminuo kiminuo force-pushed the feature/2021-05-get-data-dir-step-2 branch 2 times, most recently from a1831d5 to dfb94ae Compare May 22, 2021 13:58
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

review ACK 849ea30 🍇

Show signature and timestamp

Signature:

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

review ACK 849ea30efe96b29ec3023d10b077ffb4f7fa0f86 🍇
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgybwv/bU7GLhuy9uVt7h3E2faUAPQ2zkOGL9yViqsbXcZyqOUd5XYp8NQFt0Od
ADu7KAStRDEkqMCf0XMI9+Sx1loYVnzXACPvbf8b41+5yAerLOnmig08tDAIoLMc
YMuHK5rHjzrcLiwtrANmsW/jUR7l1pQY7QC5K0wWzSUX3XC69XZ0ZLHnJf2xJv+W
lr+xSFzbDJKcDE0PJQ3veswVGTHIkRw70QdkVj1Us3cX8i7cWADDNCsev9+DolBk
sojoZWDE58Gh/RKB5+dKyi1NpmsMjMJ4KN3l0Cgq6MU1Z8Q1ZiJ1UjwmQNIiGKqC
NNe352Op3nqbhIvXmciUgpTQcYveHmi8OAOv4hYwX2JMCmzM3PdPQ+TDgHuAY8El
PKH6mYTXfdqHow9x9QOpno67/Ei3ubzqmWsFnNTmG825lZEmb5YhviMbUvaEXWSy
6oum6G5mof5Mou4YI72d3cJbrMe0YCgA1P+SzK/jOEx2Hsp6rDw2+LIreBhtzffI
hmJY6Ucg
=7cLP
-----END PGP SIGNATURE-----

Timestamp of file with hash 73e12c06b9e21bd03f9dc8f12311837a91583686ee46b861540ec6de544476d4 -

@kiminuo kiminuo force-pushed the feature/2021-05-get-data-dir-step-2 branch from dfb94ae to 457515a Compare May 23, 2021 07:18
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Approach ACK 457515a.

@maflcko
Copy link
Member

maflcko commented May 24, 2021

ACK 457515a 🚊

Show signature and timestamp

Signature:

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

ACK 457515aab1042d842ee2ac6752ebf577ae6dee2b 🚊
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUibDgwAqnNrcU52+PTrpofeW2/FPyAMU3psifPGg3tyNYmI379eF9mbddfGk+Nv
heuP8JcCDj3JY1MPjqGsj6X5Bhof4zldeGHEpP/Zx+eW+IazU39RsdlCEv21X32n
+bCL7cnV4+6PJENrtKpJqxyET1Y6zguEjU+0O1kUeZdvYeLPP6K4SGgXKoYDxZl6
J3coLN7s0839Pn+qCNXFs/GEAjZR4j/RXXfbIUxx/L1bdBK5y/gAau5br/FMY+WS
ld465ZH1kOFdg80AyCxV4dY1B2QuIUw+zwE+8q7U7JVATAGOqQGkOBt/DKkd8+6U
2u7bbwkHieOba4XNfMXKvoApUmcD0pJTroSYo2P8Z9kSwVm7YCxGxBxP5Z2gC2qa
yKXQJkv07LUgMpXCIrfjky+hx4AVclLzlMYi800/8EAfrEDFxxPidUUEjOUFp8e2
cyNG8fkTd32Be41h0MDNidKQ+uLLv5dDin4cPDvHfNO7Q7qYuf/d7hSM3wnGeVwo
oVWPT/P3
=joGU
-----END PGP SIGNATURE-----

Timestamp of file with hash cbcc6143812dabddaf1ceda66348759c62c6dfc96fa21f1fab33a29027c960f4 -

kiminuo added 6 commits May 24, 2021 10:29
…as an intended replacement for `ArgsManager.GetDataDirPath(net_identifier)`
…GetDataDirBase()` in tests

-BEGIN VERIFY SCRIPT-
git ls-files src/test/*_tests.cpp src/test/util/setup_common.cpp | xargs sed -i 's/.GetDataDirPath()/.GetDataDirBase()/g';
-END VERIFY SCRIPT-
…()` calls

-BEGIN VERIFY SCRIPT-
git ls-files -- 'src' ':(exclude)src/util/system.h' ':(exclude)src/util/system.cpp' | xargs sed -i 's/GetDataDir()/gArgs.GetDataDirNet()/g';
-END VERIFY SCRIPT-
…rNet()` calls

-BEGIN VERIFY SCRIPT-
git ls-files -- 'src' ':(exclude)src/util/system.h' ':(exclude)src/util/system.cpp' | xargs sed -i 's/GetDataDir(true)/gArgs.GetDataDirNet()/g';
-END VERIFY SCRIPT-
@kiminuo kiminuo force-pushed the feature/2021-05-get-data-dir-step-2 branch from 457515a to aca0e5d Compare May 24, 2021 08:31
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK aca0e5d

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

re-ACK aca0e5d 👃

Show signature and timestamp

Signature:

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

re-ACK aca0e5dcdb174ef7e88b76910d6fffd633688235 👃
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiN6Qv/RgP9uS/QKuYzESznN0Tb9TySTikTypK4lmJTJloWTVxqVMWSRaeey4wP
lgnhjfPjicCgooYTHZWb9T1qrQyFrjlRuyBkDANMY0zLvuLikxfTVEc+txoxvIib
cqYHxrf8sfKrv50JJZNpspRNBxgNrgl/0vdDNHisX3+rwm7/oRb6o5WXsWPa3xmv
3UKTnWZ75Z9XTRE5pqQKDtwGsidFay8GVCJPrq0NuB8o50nQBAByfUCD1thOdE5g
nNfunXEPM2hRwgy7/T8AL6fd69STFPoOuiSCWXX+5ASbWNUB8Mwl48o93DxZdIlK
/Sk3jk+q+zTl8nc6aOT3sKR3HK9P5XLUtY5tcmDH6kx9S89/IsCots2gEHL9R0Le
Wxu5hKBcttxMLH6dN/qLa8mK/Q5foDbFEft7Yv0XYYocI9Tc5APA5xkUyYng7Pb7
1FDXJC6Xal/+4aXHNwRLeXIaJgJ6LxQ4mq7xxlIGx5zUH53vIr88rL8B8uRBTn+5
DGxzYjRs
=z/lk
-----END PGP SIGNATURE-----

Timestamp of file with hash f424bad1e3eed91a429f67534ae92bee38c1b1ae4c61eae9451b352c20c8a36b -

@maflcko maflcko merged commit 5990009 into bitcoin:master May 24, 2021
@kiminuo kiminuo deleted the feature/2021-05-get-data-dir-step-2 branch May 24, 2021 09:11
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 25, 2021
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
Copied GetMainchainAuthCookieFile logic from GetAuthCookieFile, since
the former no longer compiled.
@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.

6 participants