Commit Graph

174 Commits

Author SHA1 Message Date
TheCharlatan 41eba5bd71
kernel: Remove key module from kernel library
The key module's functionality is not used by the kernel library, but
currently kernel users are still required to initialize the key module's
`secp256k1_context_sign` global as part of the `kernel::Context` through
`ECC_Start`.
2024-05-09 15:56:08 +02:00
MarcoFalke dddd40ba82
scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes
-BEGIN VERIFY SCRIPT-
 perl -0777 -pi -e 's/#if defined\(HAVE_CONFIG_H\)\n#include <config\/bitcoin-config.h>.*\n#endif.*\n/#include <config\/bitcoin-config.h> \/\/ IWYU pragma: keep\n/g' $( git grep -l '#include <config/bitcoin-config.h>' )
-END VERIFY SCRIPT-
2024-05-01 08:33:04 +02:00
Fabian Jahr 8f39aaae41
refactor: Remove hooking code for urlDecode
The point of this was to be able to build bitcoin-tx and bitcoin-wallet without libevent, see #18504.

Now that we use our own implementation of urlDecode this is not needed anymore.

Co-authored-by: stickies-v <stickies-v@protonmail.com>
2024-04-24 23:23:38 +02:00
Ryan Ofsky 6db04be102 Get rid of shutdown.cpp/shutdown.h, use SignalInterrupt directly
This change is mostly a refectoring that removes some code and gets rid of an
unnecessary layer of indirection after #27861

But it is not a pure refactoring since StartShutdown, AbortShutdown, and
WaitForShutdown functions used to abort on failure, and the replacement code
logs or returns errors instead.
2023-12-04 15:39:15 -04:00
Ryan Ofsky 73133c36aa refactor: Add NodeContext::shutdown member
Add NodeContext::shutdown variable and start using it to replace the
kernel::Context::interrupt variable. The latter can't easily be removed right
away but will be removed later in this PR.

Moving the interrupt object from the kernel context to the node context
increases flexibility of the kernel API so it is possible to use multiple
interrupt objects, or avoid creating one if one is not needed. It will also
allow getting rid of the kernel::g_context global later in this PR, replacing
it with a private SignalInterrupt instance in init.cpp

There is no change in behavior in this commit outside of unit tests. In unit
tests there should be no visible change either, but internally now each test
has its own interrupt variable so the variable will be automatically reset
between tests.
2023-12-04 15:39:15 -04:00
fanquake 32e2ffc393
Remove the syscall sandbox
After initially being merged in #20487, it's no-longer clear that an
internal syscall sandboxing mechanism is something that Bitcoin Core
should have/maintain, especially when compared to better
maintained/supported alterantives, i.e firejail.

Note that given where it's used, the sandbox also gets dragged into the
kernel.

There is some related discussion in #24771.

This should not require any sort of deprecation, as this was only ever
an opt-in, experimental feature.

Closes #24771.
2023-06-16 10:38:19 +01:00
furszy 61c569ab60
refactor: decouple early return commands from AppInit
Cleaned up the init flow to make it more obvious when
the 'exit_status' value will and won't be returned.

This is because it was confusing that `AppInit` was
returning true under two different circumstances:

1) When bitcoind was launched only to retrieve the "-help"
or "-version" information. In this case, the app was
not initialized.

2) When the user triggers a shutdown. In this case,
the app was fully initialized.
2023-06-10 11:10:29 -03:00
furszy 3b2c61e819
Return EXIT_FAILURE on post-init fatal errors
It seems odd to return `EXIT_SUCCESS` when the node aborted
execution due a fatal internal error or any post-init problem
that triggers an unrequested shutdown.

e.g. blocks or coins db I/O errors, disconnect block failure,
failure during thread import (external blocks loading process
error), among others.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2023-06-09 17:52:23 -03:00
TheCharlatan 7d3b35004b
refactor: Move system from util to common library
Since the kernel library no longer depends on the system file, move it
to the common library instead in accordance to the diagram in
doc/design/libraries.md.
2023-05-20 12:08:13 +02:00
TheCharlatan be55f545d5
move-only: Extract common/args and common/config.cpp from util/system
This is an extraction of ArgsManager related functions from util/system
into their own common file.

Config file related functions are moved to common/config.cpp.

The background of this commit is an ongoing effort to decouple the
libbitcoinkernel library from the ArgsManager. The ArgsManager belongs
into the common library, since the kernel library should not depend on
it. See doc/design/libraries.md for more information on this rationale.
2023-04-19 10:48:30 +02:00
Ben Woosley e7333b420e
refactor: Extract util/exception from util/system
This is a minimal extraction of a single function, but also the only use
of std::exception in util/system.

The background of this commit is an ongoing effort to decouple the
libbitcoinkernel library from the ArgsManager defined in system.h.
Moving the function out of system.h allows including it from a separate
source file without including the ArgsManager definitions from system.h.
2023-03-13 17:09:47 +01:00
Ryan Ofsky 802cc1ef53 Deduplicate bitcoind and bitcoin-qt init code
Add common InitConfig function to deduplicate bitcoind and bitcoin-qt code
reading config files and creating the datadir.

There are a few minor changes in behavior:

- In bitcoin-qt, when there is a problem reading the configuration file, the
  GUI error text has changed from "Error: Cannot parse configuration file:" to
  "Error reading configuration file:" to be consistent with bitcoind.
- In bitcoind, when there is a problem reading the settings.json file, the
  error text has changed from "Failed loading settings file" to "Settings
  file could not be read" to be consistent with bitcoin-qt.
- In bitcoind, when there is a problem writing the settings.json file, the
  error text has changed from "Failed saving settings file" to "Settings file
  could not be written" to be consistent with bitcoin-qt.
- In bitcoin-qt, if there datadir is not accessible (e.g. no permission to read),
  there is an normal error dialog showing "Error: filesystem error: status:
  Permission denied [.../settings.json]", instead of an uncaught exception
2023-02-28 12:04:47 -05:00
Ryan Ofsky c361df90b9 scripted-diff: Remove double newlines after some init errors
Some InitError calls had trailing \n characters, causing double newlines in
error output. After this change InitError calls consistently output one newline
instead of two. Appearance of messages in the GUI does not seem to be affected.
Can be tested with:

  src/bitcoind -regtest -datadir=noexist
  src/qt/bitcoin-qt -regtest -datadir=noexist

-BEGIN VERIFY SCRIPT-
git grep -l InitError src/ | xargs sed -i 's/\(InitError(.*\)\\n"/\1"/'
-END VERIFY SCRIPT-
2023-02-28 12:04:47 -05:00
Ryan Ofsky 9a9d5da11f refactor: Stop using gArgs global in system.cpp
Most of the code in util/system.cpp that was hardcoded to use the global
ArgsManager instance `gArgs` has been changed to work with explicit ArgsManager
instances (for example in https://github.com/bitcoin/bitcoin/pull/20092). But a
few hardcoded references to `gArgs` remain. This commit removes the last ones
so these functions aren't reading or writing global state.
2023-02-27 14:21:13 -05:00
Hennadii Stepanov 306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
fanquake 3a0b352c63
refactor: move url.h/cpp from lib util to lib common 2022-10-31 10:17:04 +00:00
Jon Atack b6a65568df Fix issues identified by codespell 2.2.1 and update ignored words
and also fix spelling in test/lint/lint-locale-dependence.py not caught by the
spelling linter and fix up a paragraph we are touching here in test/README.md.
2022-09-15 13:03:40 +02:00
fanquake cc7b2fdd70
refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
Hennadii Stepanov 018d70b587
scripted-diff: Avoid incompatibility with CMake AUTOUIC feature
-BEGIN VERIFY SCRIPT-
sed -i "s|node/ui_interface|node/interface_ui|g" $(git grep -l "node/ui_interface" ./src)
git mv src/node/ui_interface.cpp src/node/interface_ui.cpp
git mv src/node/ui_interface.h src/node/interface_ui.h
sed -i "s|BITCOIN_NODE_UI_INTERFACE_H|BITCOIN_NODE_INTERFACE_UI_H|g" src/node/interface_ui.h
-END VERIFY SCRIPT-
2022-06-14 10:38:51 +02:00
fanquake fbae8c59a2
compat: Consolidate mingw-w64 ASLR workaround for upstream libsecp changes
Achieve this by adding a MAIN_FUNCTION macro, consolidating the docs, and
introducing the macro across our distributed binaries.

Also update the docs to explain that anyone using binutils < 2.36 is
effected by this issue. Release builds are not, because they use binutils
2.37. Currently LTS Linux distros, like Ubuntu Focal, ship with 2.34.

https://packages.ubuntu.com/focal/binutils
2022-06-11 14:55:13 +01:00
Carl Dong 265d6393bf Move init::SanityCheck to kernel::SanityCheck 2022-06-02 11:42:12 -04:00
Carl Dong fed085a1a4 init: Initialize globals with kernel::Context's life
...instead of explicitly calling init::{Set,Unset}Globals.

Cool thing about this is that in both the testing and bitcoin-chainstate
codepaths, we no longer need to explicitly unset globals. The
kernel::Context goes out of scope and the globals are unset
"automatically".

Also construct kernel::Context outside of AppInitSanityChecks()
2022-06-02 11:40:03 -04:00
laanwj 46971c6dbf util: Replace non-threadsafe strerror
Some uses of non-threadsafe `strerror` have snuck into the code since
they were removed in #4152. Add a wrapper `SysErrorString` for
thread-safe strerror alternatives and replace all uses of `strerror`
with this.
2022-04-28 10:24:06 +02:00
fanquake 2618fb8d15
Output license info when binaries are passed -version
Consolidate to outputting the licensing info when we pass -version to a binary,
i.e bitcoind -version:
```bash
itcoin Core version v22.99.0-fc1f355913f6-dirty
Copyright (C) 2009-2022 The Bitcoin Core developers

Please contribute if you find Bitcoin Core useful. Visit
<https://bitcoincore.org/> for further information about the software.
The source code is available from <https://github.com/bitcoin/bitcoin>.

This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING
or <https://opensource.org/licenses/MIT>
```
2022-02-22 15:36:19 +00:00
Russell Yanofsky 90fc8b089d Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
Hennadii Stepanov f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
practicalswift 4747da3a5b Add syscall sandboxing (seccomp-bpf) 2021-10-01 13:51:10 +00:00
Russell Yanofsky 493fb47c57 Make SetupServerArgs callable without NodeContext
bitcoin-gui code needs to call SetupServerArgs but will not have a
NodeContext object if it is communicating with an external bitcoin-node
process.
2021-06-10 09:58:45 -05:00
Russell Yanofsky ddf7ecc8df multiprocess: Add bitcoin-node process spawning support
Add bitcoin-node startup code to let it spawn and be spawned by other
processes
2021-04-23 03:02:50 -05:00
Russell Yanofsky 9044522ef7 Drop JSONRPCRequest constructors after #21366
This just makes an additional simplification after #21366 replaced
util::Ref with std::any. It was originally suggested
https://github.com/bitcoin/bitcoin/pull/21366#issuecomment-792044351 but
delayed for a followup. It would have prevented usage bug
https://github.com/bitcoin/bitcoin/pull/21572.
2021-04-07 04:53:26 -04:00
Sebastian Falbesoner 8dbb87a393 refactor: replace util::Ref by std::any (C++17) 2021-03-29 23:29:42 +02:00
fanquake ebc4ab721b
refactor: post Optional<> removal cleanups 2021-03-17 14:56:20 +08:00
Wladimir J. van der Laan e017a913d0 bitcoind: Add -daemonwait option to wait for initialization
This adds a `-daemonwait` flag that does the same as `-daemon` except
it, from a user perspective, backgrounds the process only after
initialization is complete.

This can be useful when the process launching bitcoind wants to
guarantee that either the RPC server is running, or that initialization
failed, before continuing. The exit code indicates the initialization
result.

This replaces the use of the libc function `daemon()` by a custom
implementation which is inspired by the glibc implementation, but also
creates a pipe from the child to the parent process for communication.

An additional advantage of having our own `daemon()` implementation is
that no MACOS-specific pragmas are needed anymore to silence a
deprecation warning.
2021-03-04 18:24:00 +01:00
Wladimir J. van der Laan cd03513dc2 init: Signal-safe instant shutdown
Replace the 200ms polling loop with a faster and more efficient waiting
operation.

This was tried a few times before, but given up every time because
solutions use a condition variable which is not safe for use in signals
as they need to be reentrant.

On UNIX-ish OSes, use a safe way: a pipe. When shutdown is requested
write a dummy byte to the pipe. Waiting for shutdown is a matter of a
blocking read from the pipe.

On Windows, there are no signals so using a condition variable is safe.
2020-12-15 17:21:06 +01:00
Tyler Chambers 6690adba08
Warn when binaries are built from a dirty branch.
Adjusted version flag behavior in bitcoin-tx, bitcoin-wallet, and
bitcoind to match. Added functionality in gen-manpages.sh to warning when
attempting to generate man pages for binaries built from a dirty
branch.
2020-11-28 18:43:55 -05:00
MarcoFalke faf0a26711
doc: Update comments for new chain settings (-signet and -chain=signet) 2020-09-22 22:32:25 +02:00
Russell Yanofsky b266b3e0bf refactor: Create interfaces earlier during initialization
Add AppInitInterfaces function so wallet chain and chain client interfaces are
created earlier during initialization. This is needed in the next commit to
allow the gui splash screen to be able to register for wallet events through a
dedicated WalletClient interface instead managing wallets indirectly through
the Node interface. This only works if the wallet client interface is created
before the splash screen needs to use it.
2020-08-27 14:33:00 -04:00
MarcoFalke fa9d5902f7
scripted-diff: gArgs -> args
-BEGIN VERIFY SCRIPT-
 # Replace gArgs with args
 sed -i 's/\<gArgs\>/args/g' src/init.cpp src/bitcoind.cpp
 sed -i 's/&args;/\&gArgs;/g' src/init.cpp

 # Format changed lines
 git diff -U0 | clang-format-diff -p1 -i -v
-END VERIFY SCRIPT-
2020-08-24 07:52:17 +02:00
MarcoFalke fa40017706
init: Pass reference to ArgsManager around instead of relying on global 2020-08-24 07:45:17 +02:00
Russell Yanofsky 9c69cfe4c5 Add <datadir>/settings.json persistent settings storage.
Persistent settings are used in followup PRs #15936 to unify gui settings
between bitcoin-qt and bitcoind, and #15937 to add a load_on_startup flag to
the loadwallet RPC and maintain a dynamic list of wallets that should be loaded
on startup that also can be shared between bitcoind and bitcoin-qt.
2020-07-11 05:41:12 -04:00
MarcoFalke cccc2784a3
scripted-diff: Move ui_interface to the node lib
-BEGIN VERIFY SCRIPT-

 # Move files
 git mv src/ui_interface.h                                          src/node/ui_interface.h
 git mv src/ui_interface.cpp                                        src/node/ui_interface.cpp
 sed -i -e 's/BITCOIN_UI_INTERFACE_H/BITCOIN_NODE_UI_INTERFACE_H/g' src/node/ui_interface.h

 # Adjust includes and makefile
 sed -i -e 's|ui_interface|node/ui_interface|g' $(git grep -l ui_interface)

 # Sort includes
 git diff -U0 | clang-format-diff -p1 -i -v

-END VERIFY SCRIPT-
2020-06-27 11:49:28 -04:00
Russell Yanofsky 6fca33b2ed refactor: Pass NodeContext to RPC and REST methods through util::Ref
This commit does not change behavior
2020-05-13 16:20:13 -04:00
Hennadii Stepanov 7e923d47ba
Make InitError bilingual 2020-05-05 04:46:04 +03:00
MarcoFalke fa488f131f
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-04-16 13:33:09 -04:00
MarcoFalke fad4fa7e2f
node: Add args alias for gArgs global 2020-04-15 15:05:18 -04:00
Russell Yanofsky 01a3392b1b Drop bitcoin-wallet dependency on libevent
Don't require urlDecode function in wallet code since urlDecode implementation
currently uses libevent. Just call urlDecode indirectly though URL_DECODE
function pointer constant if available.

In bitcoind and bitcoin-qt, URL_DECODE is implemented and used to interpret RPC
wallet requests. In bitcoin-wallet, URL_DECODE is null to avoid depending on
libevent.
2020-04-02 08:35:10 -04:00
MarcoFalke fa9af06d91
scripted-diff: Replace MilliSleep with UninterruptibleSleep
This is safe because MilliSleep is never executed in a boost::thread,
the only type of thread that is interruptible.

* The RPC server uses std::thread
* The wallet is either executed in an RPC thread or the main thread
* bitcoin-cli, benchmarks and tests are only one thread (the main thread)

-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/MilliSleep\((\S+)\);/UninterruptibleSleep(std::chrono::milliseconds{\1});/g' $(git grep -l MilliSleep)
-END VERIFY SCRIPT-
2020-02-21 10:06:21 -08:00
Wladimir J. van der Laan 471e5f8829
Merge #16839: Replace Connman and BanMan globals with NodeContext local
362ded410b Avoid using g_rpc_node global in wallet code (Russell Yanofsky)
8922d7f6b7 scripted-diff: Remove g_connman, g_banman globals (Russell Yanofsky)
e6f4f895d5 Pass NodeContext, ConnMan, BanMan references more places (Russell Yanofsky)
4d5448c76b MOVEONLY: Move NodeContext struct to node/context.h (Russell Yanofsky)
301bd41a2e scripted-diff: Rename InitInterfaces to NodeContext (Russell Yanofsky)

Pull request description:

  This change is mainly a naming / organization change intended to simplify #10102. It:

  - Renames struct InitInterfaces to struct NodeContext and moves it from
    src/init.h to src/node/context.h. This is a cosmetic change intended to make
    the point of the struct more obvious.

  - Gets rid of BanMan and ConnMan globals making them NodeContext members
    instead. Getting rid of these globals has been talked about in past as a way
    to implement testing and simulations. Making them NodeContext members is a
    way of keeping them accessible without the globals.

  - Splits g_rpc_interfaces global into g_rpc_node and g_rpc_chain globals. This
    better separates node and wallet rpc methods. Node RPC methods should have
    access NodeContext, while wallet RPC methods should only have indirect access
    to node functionality via interfaces::Chain.

  - Adds NodeContext& references to interfaces::Chain class and the
    interfaces::MakeChain() function. This is needed to access ConnMan and BanMan
    instances without the globals.

  - Gets rid of redundant Node and Chain instances in Qt tests. This is
    needed due to the previous MakeChain change, and also makes test setup a
    little more straightforward. More cleanup could be done in the future, but it
    will require deduplication of bitcoind, bitcoin-qt, and TestingSetup init
    code.

ACKs for top commit:
  laanwj:
    ACK 362ded410b

Tree-SHA512: 9ae6ff1e33423291d1e52056bac95e0874538390892a6e83c4c115b3c73155a8827c0191b46eb3d14e3b3f6c23ccb08095490880fbc3188026319c71739f7db2
2019-10-30 12:35:41 +01:00
Russell Yanofsky e6f4f895d5 Pass NodeContext, ConnMan, BanMan references more places
So g_connman and g_banman globals can be removed next commit.
2019-10-28 10:30:51 -04:00
Russell Yanofsky 301bd41a2e scripted-diff: Rename InitInterfaces to NodeContext
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'struct InitInterfaces'              'struct NodeContext'
s 'InitInterfaces interfaces'          'NodeContext node'
s 'InitInterfaces& interfaces'         'NodeContext\& node'
s 'InitInterfaces m_interfaces'        'NodeContext m_context'
s 'InitInterfaces\* g_rpc_interfaces'  'NodeContext* g_rpc_node'
s 'g_rpc_interfaces = &interfaces'     'g_rpc_node = \&node'
s 'g_rpc_interfaces'                   'g_rpc_node'
s 'm_interfaces'                       'm_context'
s 'interfaces\.chain'                  'node.chain'
s '\(AppInitMain\|Shutdown\|Construct\)(interfaces)' '\1(node)'
s 'init interfaces' 'chain clients'
-END VERIFY SCRIPT-
2019-10-28 10:30:51 -04:00