New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: add RunCommandParseJSON #15382
util: add RunCommandParseJSON #15382
Conversation
6bdabd7
to
c284e7d
Compare
See earlier discussion in #14912 (review) for different approaches like |
This C++11 python-inspired subprocess module may or may not be of relevant interest, as it avoids Boost in favor of straight C++11: http://templated-thoughts.blogspot.com/2016/03/sub-processing-with-modern-c.html |
@jgarzik thanks! 1600 lines of code seems a bit overkill, but on the other hand it looks very clean and presumably better than anything I would come up with. It currently doesn't have Windows support, but they're open to patches. Speaking of UniValue :-) I think I need to reorder the Makefile to prevent some Travis instances from failing with |
7050b82
to
44ee037
Compare
The |
@practicalswift agreed, but I don't know if the functional test framework can launch a Testnet node without triggering a real IBD. I suppose I can configure it to not connect to any peers. |
0ae6e68
to
e2f681b
Compare
src/rpc/misc.cpp
Outdated
if (request.fHelp || request.params.size() != 1) | ||
throw std::runtime_error( | ||
RPCHelpMan{"runcommand", | ||
"\nRun command and parse JSON from stdout (-regtest only)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this RPC exposed? For testing purposes? It should be a unit test in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's restricted to regtest (similar to setmocktime
). Main reasons I didn't build a unit test:
- no idea how
- potentially creates even more cross-platform headaches
runCommand
is also only tested via functional tests (viablocknotify
, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially creates even more cross-platform headaches
What you mean? Because of the command itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sjors how about supporting -exec "cmd"
in bitcoin_test binary (or in any other test binary), then that could be used in the functional test (instead of this RPC).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to have this RPC only enabled in regtest. If you wanted to add more protection against misuse, you could disable it without gArgs.GetBoolArg("-enable-unsafe-runcommand-rpc", false)
or similar.
If you did want to drop the RPC and just write a unit test for runCommandParseJSON
, I don't think it would be difficult to do by just having the unit test write a temporary json file and then calling runCommandParseJSON
with cat path_to_file
on unix and type path_to_file
on windows.
a05525a
to
35cf444
Compare
AppVeyor seems unhappy about the
|
test/functional/mocks/command.py
Outdated
parser.set_defaults(func=command) | ||
|
||
if len(sys.argv) == 1: | ||
args = parser.parse_args(['-h']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indentation :-)
7e84a5a
to
a194e3c
Compare
I switched to boost::process, which should give us Windows support. It's included with the depends Boost 1.64. Because the minimum Boost version is 1.47, this functionality is just not compiled for older versions of Boost. |
Performing a series of link checks for a Boost component that is header-only doesn't make much sense, and currently means we just have another confusing Boost macro in our tree. I'm not sure why this was originally done this way; maybe Sjors or luke-jr can elaborate (bitcoin#15382 (929cda5))? The macro also has the side-effect of producing confusing error messages. i.e in bitcoin#20744, the CI is currently failing with: ```bash checking for boostlib >= 1.58.0 (105800) lib path in "/tmp/cirrus-ci-build/depends/x86_64-pc-linux-gnu/lib"... yes checking for boostlib >= 1.58.0 (105800)... yes checking whether the Boost::Process library is available... yes configure: error: Could not find a version of the Boost::Process library! ``` This isn't useful, given there is no such thing as a `Boost::Process` library. This PR just removes the macro entirely, but maintains a `--with-boost-process` (defaulting to off), flag to configure. Hopefully this will also be removed, in favour of `--enable-disable-external-signer` if/when bitcoin#16546 is merged.
7bf04e3 build: remove mostly pointless BOOST_PROCESS macro (fanquake) Pull request description: Performing a series of link checks for a Boost component that is header-only doesn't make much sense, and currently means we just have another confusing Boost macro in our tree. I'm not sure why this was originally done this way; maybe Sjors or luke-jr can elaborate (#15382 (929cda5))? The macro also has the side-effect of producing confusing error messages. i.e in #20744, the CI is currently failing with: ```bash checking for boostlib >= 1.58.0 (105800) lib path in "/tmp/cirrus-ci-build/depends/x86_64-pc-linux-gnu/lib"... yes checking for boostlib >= 1.58.0 (105800)... yes checking whether the Boost::Process library is available... yes configure: error: Could not find a version of the Boost::Process library! ``` This isn't useful, given there is no such thing as a `Boost::Process` library. This PR just removes the macro entirely, but maintains a `--with-boost-process` (defaulting to off), flag to configure. Hopefully this will also be removed, in favour of `--enable/disable-external-signer` if/when #16546 is merged. ACKs for top commit: laanwj: ACK 7bf04e3 Tree-SHA512: b270a0250f32df2078f986c165b8977967d8c06df80bf2773f3442f74b395a3bfa6544af1024d9b6524d90d47a0f6304194b3aced0e2ecb88e75916da945ccb6
7bf04e3 build: remove mostly pointless BOOST_PROCESS macro (fanquake) Pull request description: Performing a series of link checks for a Boost component that is header-only doesn't make much sense, and currently means we just have another confusing Boost macro in our tree. I'm not sure why this was originally done this way; maybe Sjors or luke-jr can elaborate (bitcoin#15382 (929cda5))? The macro also has the side-effect of producing confusing error messages. i.e in bitcoin#20744, the CI is currently failing with: ```bash checking for boostlib >= 1.58.0 (105800) lib path in "/tmp/cirrus-ci-build/depends/x86_64-pc-linux-gnu/lib"... yes checking for boostlib >= 1.58.0 (105800)... yes checking whether the Boost::Process library is available... yes configure: error: Could not find a version of the Boost::Process library! ``` This isn't useful, given there is no such thing as a `Boost::Process` library. This PR just removes the macro entirely, but maintains a `--with-boost-process` (defaulting to off), flag to configure. Hopefully this will also be removed, in favour of `--enable/disable-external-signer` if/when bitcoin#16546 is merged. ACKs for top commit: laanwj: ACK 7bf04e3 Tree-SHA512: b270a0250f32df2078f986c165b8977967d8c06df80bf2773f3442f74b395a3bfa6544af1024d9b6524d90d47a0f6304194b3aced0e2ecb88e75916da945ccb6
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
contains only 8314c23
…ration changes 88a91e2 [build] AppVeyor: clean cache when build configuration changes (Sjors Provoost) Pull request description: AppVeyor builds started starting failing on master after I cleaned the cache in bitcoin#15382. In addition, it appeared that a new dependency (boost-process) wasn't getting added in that PR without at least cleaning the vcpkg cache. Tree-SHA512: 1ad87bf6ca866cc20db04682cdf7572b59d22a7eaf346f390fc476c5e28bc5422733277fd765e5c9fd2ea88107b52fccd13f1f7e55493f567c4c4a1c16d7cb3a
…ge list 29eb039 Moves vcpkg list to a text file and updates the appveyor job and readme to use it. (Aaron Clauson) Pull request description: bitcoin#17364 attempted to save a couple of minutes by skipping the `vcpkg` steps if the vcpkg install directory was already cached. The discussion in bitcoin#15382 highlights the approach used in bitcoin#17364 does not accommodate adding a new package. ~~This PR improves the approach to individually check whether each vcpg package is installed rather than checking for the existence of the vcpkg install directory.~~ This PR moves the list of required vcpkg packages into a separate file and uses changes to that file to invalidate the appveyor cache. Whenever the cache is invalidated the vcpkg sources will be updated, the vcpkg binary built and the required packages installed from the latest port files. ACKs for top commit: MarcoFalke: ACK 29eb039 Tree-SHA512: 0c2a170f4e4b47ca0f9cef14f1e3892001b441a6d84f50bf5fd8a26bc4cdbd9358dfce7ef180d37150262e849650e9857d6b2bcd686964b963c3de6cd708a2f3
contains only 8314c23
Prerequisite for external signer support in #16546. Big picture overview in this gist.
This adds a new dependency boost process. This is part of Boost since 1.64 which is part of
depends
. Because the minimum Boost version is 1.47, this functionality is skipped for older versions of Boost.Use
./configure --with-boost-process
to opt in, which checks for the presence of Boost::Process.We add
UniValue runCommandParseJSON(const std::string& strCommand)
tosystem.{h,cpp}
which calls an arbitrary command and processes the JSON returned by it. This is currently only called by the test suite.For testing purposes this adds a new regtest-only RPC method(this is no longer the case)runcommand
, as well astest/mocks/command.py
used by functional tests.TODO: