Commit Graph

93 Commits

Author SHA1 Message Date
Ava Chow c1223188e0
Merge bitcoin/bitcoin#29672: validation: Make translations of fatal errors consistent
824f47294a node: Use log levels in noui_ThreadSafeMessageBox (TheCharlatan)
ddc7872c08 node: Make translations of fatal errors consistent (TheCharlatan)

Pull request description:

  The extra `bilingual_str` argument of the fatal error notifications and `node::AbortNode()` is often unused and when used usually contains the same string as the message argument. It also seems to be confusing, since it is not consistently used for errors requiring user action. For example some assumeutxo fatal errors require the user to do something, but are not translated.

  So simplify the fatal error and abort node interfaces by only passing a translated string. This slightly changes the fatal errors displayed to the user.

ACKs for top commit:
  stickies-v:
    re-ACK 824f47294a
  maflcko:
    ACK 824f47294a 🔎
  achow101:
    ACK 824f47294a
  hebasto:
    re-ACK 824f47294a.

Tree-SHA512: 2868ee7b045fe7f3ac582ce5039141b398480b7627734976201dafaaef7544b8461635a7292fee4a7f32ff1bfc26f9bd4d0c292dca424ba42fb7fc4483d7ce8d
2024-03-22 14:50:58 -04:00
TheCharlatan ddc7872c08
node: Make translations of fatal errors consistent
The extra `bilingual_str` argument of the fatal error notifications and
`node::AbortNode()` is often unused and when used usually contains the
same string as the message argument. It also seems to be confusing,
since it is not consistently used for errors requiring user action. For
example some assumeutxo fatal errors require the user to do something,
but are not translated.

So simplify the fatal error and abort node interfaces by only passing a
translated string. This slightly changes the fatal errors displayed to
the user.

Also de-duplicate the abort error log since it is repeated in noui.cpp.
2024-03-21 16:40:22 +01:00
Ava Chow bf1b6383db
Merge bitcoin/bitcoin#29671: index: avoid "failed to commit" errors on initialization
f65b0f6401 index: Move last_locator_write_time and logging to end of threadsync loop (Fabian Jahr)

Pull request description:

  In the index sync thread, when initializing an index for the first time, stop callng BaseIndex::Commit when m_best_block_index is null, to avoid a spurious "failed to commit" error from that function. This error started happening in commit 7878f97bf1 from https://github.com/bitcoin/bitcoin/pull/25494 and was reported by pstratem in https://github.com/bitcoin/bitcoin/pull/26903 with an alternate fix.

ACKs for top commit:
  achow101:
    ACK f65b0f6401
  ryanofsky:
    Code review ACK f65b0f6401. Just moved log "Syncing" log line since last commit to avoid having to call now() twice.
  furszy:
    ACK f65b0f6401
  TheCharlatan:
    ACK f65b0f6401

Tree-SHA512: afa8f05786318d36346d167ff53ea0b3bc8abdb0ad04465d199dc3eb91e9f837369e24fcb7e24b5757b02d698ec504e61da6ac365eaf006c874fc07a424a7e20
2024-03-20 16:38:32 -04:00
Fabian Jahr f65b0f6401
index: Move last_locator_write_time and logging to end of threadsync loop
This avoids having commit print a needless error message during init.

Co-authored-by: furszy <mfurszy@protonmail.com>
2024-03-19 18:20:39 +01:00
furszy 0faafb57f8
index: decrease ThreadSync cs_main contention
Only NextSyncBlock requires cs_main lock. The
other function calls like Commit or Rewind will
lock or not cs_main internally when they need it.

Avoiding keeping cs_main locked when Commit() or
Rewind() write data to disk.
2024-03-12 11:55:04 -03:00
furszy bcbd7eb8d4
bench: basic block filter index initial sync
Introduce benchmark for the block filter index sync.
And makes synchronous 'Sync()' mechanism accessible.
2024-03-12 09:30:42 -03:00
MarcoFalke fad0335517
scripted-diff: Replace error() with LogError()
This fixes the log output when -logsourcelocations is used.

Also, instead of 'ERROR:', the log will now say '[error]', like other
errors logged with LogError.

-BEGIN VERIFY SCRIPT-
 sed -i --regexp-extended 's!  error\("([^"]+)"!  LogError("\1\\n"!g' $( git grep -l '  error(' ./src/ )
-END VERIFY SCRIPT-
2024-03-11 13:49:37 +01:00
MarcoFalke fa1d624348
scripted-diff: return error(...); ==> error(...); return false;
This is needed for the next commit.

-BEGIN VERIFY SCRIPT-
 # Separate sed invocations to replace one-line, and two-line error(...) calls
 sed -i             --regexp-extended 's!( +)return (error\(.*\);)!\1\2\n\1return false;!g'             $( git grep -l 'return error(' )
 sed -i --null-data --regexp-extended 's!( +)return (error\([^\n]*\n[^\n]*\);)!\1\2\n\1return false;!g' $( git grep -l 'return error(' )
-END VERIFY SCRIPT-
2024-03-11 13:49:25 +01:00
TheCharlatan 84f5c135b8
refactor: De-globalize g_signals 2024-02-15 14:37:01 +01:00
Ryan Ofsky feeb7b816a refactor: Remove calls to StartShutdown from KernelNotifications
Use SignalInterrupt object instead. There is a slight change in behavior here
because the previous StartShutdown code used to abort on failure and the
new code logs errors instead.
2023-12-04 15:39:15 -04:00
James O'Beirne 373cf91531 validation: indexing changes for assumeutxo
When using an assumedvalid chainstate, only process validationinterface
callbacks from the background chainstate within indexes. This ensures
that all indexes are built in-order.

Later, we can possibly designate indexes which can be built out of order
and continue their operation during snapshot use.

Once the background sync has completed, restart the indexes so that
they continue to index the now-validated snapshot chainstate.
2023-09-30 06:38:47 -04:00
James O'Beirne 4d8f4dcb45 validation: pass ChainstateRole for validationinterface calls
This allows consumers to decide how to handle events from background or
assumedvalid chainstates.
2023-09-30 06:38:47 -04:00
fanquake 0a1029aa29
lint: remove /* Continued */ markers from codebase 2023-08-03 17:52:24 +01:00
furszy ca91c244ef
index: verify blocks data existence only once
At present, during init, we traverse the chain (once per index)
to confirm that all necessary blocks to sync each index up to
the current tip are present.

To make the process more efficient, we can fetch the oldest block
from the indexers and perform the chain data existence check from
that point only once.

This also moves the pruning violation check to the end of the
'loadinit' thread, which is where the reindex, block loading and
chain activation processes happen.

Making the node's startup process faster, allowing us to remove
the global g_indexes_ready_to_sync flag, and enabling the
execution of the pruning violation verification even when the
reindex or reindex-chainstate flags are enabled (which has being
skipped so far).
2023-07-10 10:50:50 -03:00
furszy fcbdaeef4d
init: don't start indexes sync thread prematurely
By moving the 'StartIndexes()' call into the 'initload'
thread, we can remove the threads active wait. Optimizing
the available resources.

The only difference with the current state is that now the
indexes threads will only be started when they can process
work and not before it.
2023-07-10 10:50:50 -03:00
furszy 2ec89f1970
refactor: simplify pruning violation check
By generalizing 'GetFirstStoredBlock' and implementing
'CheckBlockDataAvailability' we can dedup code and
avoid repeating work when multiple indexes are enabled.
E.g. get the oldest block across all indexes and
perform the pruning violation check from that point
up to the tip only once (this feature is being introduced
in a follow-up commit).

This commit shouldn't change behavior in any way.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2023-07-10 10:50:50 -03:00
furszy c82ef91eae
make GetFirstStoredBlock assert that 'start_block' always has data
And transfer the responsibility of verifying whether 'start_block'
has data or not to the caller.

This is because the 'GetFirstStoredBlock' function responsibility
is to return the first block containing data. And the current
implementation can return 'start_block' when it has no data!. Which
is misleading at least.

Edge case behavior change:
Previously, if the block tip lacked data but all preceding blocks
contained data, there was no prune violation. And now, such
scenario will result in a prune violation.
2023-07-10 10:47:17 -03:00
furszy 430e7027a1
refactor: index, decouple 'Init' from 'Start'
So indexes can be initialized without spawning
the sync thread.

This makes asynchronous indexes startup
possible in the following commits.
2023-07-10 10:47:17 -03:00
TheCharlatan 6eb33bd0c2
kernel: Add fatalError method to notifications
FatalError replaces what previously was the AbortNode function in
shutdown.cpp.

This commit is part of the libbitcoinkernel project and further removes
the shutdown's and, more generally, the kernel library's dependency on
interface_ui with a kernel notification method. By removing interface_ui
from the kernel library, its dependency on boost is reduced to just
boost::multi_index. At the same time it also takes a step towards
de-globalising the interrupt infrastructure.

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Co-authored-by: TheCharlatan <seb.kung@gmail.com>
2023-06-28 09:52:33 +02:00
TheCharlatan 3fa9094b92
scripted-diff: Rename FatalError to FatalErrorf
This is done in preparation for the next commit where a new FatalError
function is introduced. FatalErrorf follows common convention to append
'f' for functions accepting format arguments.

-BEGIN VERIFY SCRIPT-
sed -i 's/FatalError/FatalErrorf/g' $( git grep -l 'FatalError')
-END VERIFY SCRIPT-
2023-06-28 09:52:30 +02: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
Sebastian Falbesoner 3c06926cf2
refactor: index: use `AbortNode` in fatal error helper
Deduplicates code in the `FatalError` template function by using
`AbortNode` which does the exact same thing if called without any user
message (i.e. without second parameter specified). The template is still
kept for ease-of-use w.r.t. not having to call `tfm::format(...)` at the
call-side each time, and also to keep the diff minimal.
2023-06-08 16:38:36 -03:00
furszy 3126454dcf
index: prevent race by calling 'CustomInit' prior setting 'synced' flag
The 'm_synced' flag enables 'BlockConnected' events to be processed by
the index. If we set the flag before calling 'CustomInit', we could be
dispatching a block connected event to an uninitialized index child
class.

e.g. BlockFilterIndex, initializes the next filter position
inside 'CustomInit'. So, if `CustomInit` is not called prior receiving
the block event, the index will use 'next_filter_position=0' which
overwrites the first filter in disk.
2023-05-22 12:56:16 -03:00
Martin Zumsande 97844d9268 index: Enable reindex-chainstate with active indexes
This is achieved by letting the index sync thread wait until
reindex-chainstate is finished.

This also disables the pruning check when reindexing the chainstate (which is
incompatible with prune mode) because there would be no chain at this point
in init.
2023-05-17 11:14:28 -04:00
Martin Zumsande 60bec3c82d index: Use first block from locator instead of looking for fork point
The index sync code has logic to go back the chain to the forking point, while
also updating index-specific state, which is necessary to prevent
possible corruption of the coinstatsindex.

Also add a test for this (a reorg happens while the index is deactivated)
that would not pass before this change.
2023-05-17 11:14:10 -04:00
TheCharlatan f0bb1021f0
refactor: Move functions to BlockManager methods
This is a commit in preparation for the next few commits. The functions
are moved to methods to avoid their re-declaration for the purpose of
passing in BlockManager options.

The functions that were now moved into the BlockManager should no longer
use the params as an argument, but instead use the member variable.

In the moved ReadBlockFromDisk and UndoReadFromDisk, change
the function signature to accept a reference to a CBlockIndex instead of
a raw pointer. The pointer is expected to be non-null, so reflect that
in the type.

To allow for the move of functions to BlockManager methods all call
sites require an instantiated BlockManager, or a callback to one.
2023-05-10 19:06:53 +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 aaced5633b
refactor: Move error() from util/system.h to logging.h
error is a low-level function with a sole dependency on LogPrintf, which
is defined in logging.h

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:54 +01:00
Ryan Ofsky d172b5c671 Add InitError(error, details) overload
This is only used in the current PR to avoid ugly
`strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)`
boilerplate in init code. But in the future the function could be extended and
more widely used to include more details in GUI error messages or display them
in a more readable way, see code comment.
2023-02-28 12:04:47 -05:00
Ryan Ofsky 2eaeded37f refactor, dbwrapper: Add DBParams and DBOptions structs
Add DBParams and DBOptions structs to remove ArgsManager uses from dbwrapper.

To reduce size of this commit, this moves references to gArgs variable out of
dbwrapper.cpp to calling code in txdb.cpp. But these moves are temporary. The
gArgs references in txdb.cpp are moved out to calling code in init.cpp in later
commits.

This commit does not change behavior.
2023-02-10 04:39:11 -04:00
MarcoFalke faf7b4f1fc
Add BlockManager::IsPruneMode() 2023-01-16 17:31:32 +01: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
Ryan Ofsky 8891949bdc index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability
Since commit f08c9fb0c6 from PR
https://github.com/bitcoin/bitcoin/pull/21726, index
`BlockUntilSyncedToCurrentChain` behavior has been less reliable, and there has
also been a race condition in the `coinstatsindex_initial_sync` unit test.

It seems better for `BlockUntilSyncedToCurrentChain` to actually wait for the
last connected block to be fully processed, than to be able to return before
prune locks are set, so this switches the order of `m_best_block_index =
block;` and `UpdatePruneLock` statements in `SetBestBlockIndex` to make it more
reliable.

Also since commit f08c9fb0c6, there has been a
race condition in the `coinstatsindex_initial_sync` test. Before that commit,
the atomic index best block pointer `m_best_block_index` was updated as the
last step of `BaseIndex::BlockConnected`, so `BlockUntilSyncedToCurrentChain`
could safely be used in tests to wait for the last `BlockConnected`
notification to be finished before stopping and destroying the index. But
after that commit, calling `BlockUntilSyncedToCurrentChain` is no longer
sufficient, and there is a race between the test shutdown code which destroys
the index object and the new code introduced in that commit calling
`AllowPrune()` and `GetName()` on the index object. Reproducibility
instructions for this are in
https://github.com/bitcoin/bitcoin/issues/25365#issuecomment-1259744133

This commit fixes the `coinstatsindex_initial_sync` race condition, even though
it will require an additional change to silence TSAN false positives,
https://github.com/bitcoin/bitcoin/pull/26188, after it is fixed. So this
partially addresses but does not resolve the bug reporting TSAN errors
https://github.com/bitcoin/bitcoin/issues/25365.

There is no known race condition outside of test code currently, because the
bitcoind `Shutdown` function calls `FlushBackgroundCallbacks` not
`BlockUntilSyncedToCurrentChain` to safely shut down.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Co-authored-by: MacroFake <falke.marco@gmail.com>
2022-10-05 11:06:58 -04:00
stickies-v 200d84d568
refactor: use std::string for index names 2022-09-13 19:10:41 +01:00
MacroFake b8067cd435
Merge bitcoin/bitcoin#22485: doc: BaseIndex sync behavior with empty datadir
11780f29e7 doc: BaseIndex sync behavior with empty datadir (James O'Beirne)

Pull request description:

  Make a note about a potentially confusing behavior with `BaseIndex::m_synced`;
  if the user starts bitcoind with an empty datadir and an index enabled,
  BaseIndex will consider itself synced (as a degenerate case). This affects
  how indices are built during IBD (relying solely on BlockConnected signals vs.
  using ThreadSync()).

ACKs for top commit:
  mzumsande:
    ACK 11780f29e7

Tree-SHA512: 0b530379e57c62e05d2ddca7bb8e2c936786fa00678f9eaa1bb3742d957c48f141d46f936734b03f6673d964abc7eb72c1769f1784b9d3563d218e96296b7afd
2022-07-21 19:54:18 +02:00
James O'Beirne 11780f29e7 doc: BaseIndex sync behavior with empty datadir
Make a note about a potentially confusing behavior with `BaseIndex::m_synced`;
if the user starts bitcoind with an empty datadir and an index enabled,
BaseIndex will consider itself synced (as a degenerate case). This affects
how indices are built during IBD (relying solely on BlockConnected signals vs.
using ThreadSync()).
2022-07-21 10:32:40 -04:00
fanquake 5560682a44
Merge bitcoin/bitcoin#25645: refactor: Remove unused includes from dbwrapper.h
faf98aecf8 Remove unused includes in rpc/fees.cpp (MacroFake)
1111ddeedf Remove unused includes from dbwrapper.h (MacroFake)
fa77fdd047 Add missing includes (MacroFake)
fa869ce2c2 Add missing includes to node/chainstate (MacroFake)

Pull request description:

  Unused includes are confusing, but also cause unrelated compile errors when the unused includes were to be removed.

  Fix that by adding the missing includes where they are needed and then remove them where they are not needed. This is also checked by iwyu.

ACKs for top commit:
  hebasto:
    ACK faf98aecf8, I have reviewed the code and it looks OK, I agree it can be merged.
  jarolrod:
    Code Review ACK faf98aecf8

Tree-SHA512: 75f3c6e6f6ecf8a98233e1a1463c75ca4e0eb3ec341150d274141072fe95413a3c2ec6386d1c527899cc63d43f63f5eb5991509847412773362808ddfb1bb435
2022-07-19 21:54:52 +01:00
MacroFake fa77fdd047
Add missing includes
They are needed, otherwise the next commit will not compile
2022-07-19 14:12:33 +02:00
Ryan Ofsky 7878f97bf1 indexes, refactor: Remove CChainState use in index CommitInternal method
Replace CommitInternal method with CustomCommit and use interfaces::Chain
instead of CChainState to generate block locator.

This commit does not change behavior in any way, except in the
(m_best_block_index == nullptr) case, which was added recently in
https://github.com/bitcoin/bitcoin/pull/24117 as part of an ongoing attempt to
prevent index corruption if bitcoind is interrupted during startup. New
behavior in that case should be slightly better than the old behavior (skipping
the entire custom+base commit now vs only skipping the base commit previously)
and this might avoid more cases of corruption.
2022-07-18 13:39:55 -05:00
Ryan Ofsky ee3a079fab indexes, refactor: Remove CBlockIndex* uses in index Rewind methods
Replace Rewind method with CustomRewind and pass block hashes and
heights instead of CBlockIndex* pointers

This commit does not change behavior in any way.
2022-07-18 13:39:55 -05:00
Ryan Ofsky dc971be083 indexes, refactor: Remove CBlockIndex* uses in index WriteBlock methods
Replace WriteBlock method with CustomAppend and pass BlockInfo struct
instead of CBlockIndex* pointer

This commit does not change behavior in any way.
2022-07-18 13:39:55 -05:00
Ryan Ofsky bef4e405f3 indexes, refactor: Remove CBlockIndex* uses in index Init methods
Replace overriden index Init() methods that use the best block
CBlockIndex* pointer with pure CustomInit() callbacks that are passed
the block hash and height.

This gets rid of more CBlockIndex* pointer uses so indexes can work
outside the bitcoin-node process. It also simplifies the initialization
call sequence so index implementations are not responsible for
initializing the base class.

There is a slight change in behavior here since now the best block
pointer is loaded and checked before the custom index init functions are
called instead of while they are called.
2022-07-18 13:39:55 -05:00
Ryan Ofsky 33b4d48cfc indexes, refactor: Pass Chain interface instead of CChainState class to indexes
Passing abstract Chain interface will let indexes run in separate
processes.

This commit does not change behavior in any way.
2022-07-18 13:39:55 -05: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 e18fd4763e
Merge bitcoin/bitcoin#25074: index: During sync, commit best block after indexing
7171ebc7cb index: Don't commit a best block before indexing it during sync (Martin Zumsande)

Pull request description:

  This changes the periodic commit of the best block during the index sync phase to use the already indexed predecessor of the current block index, instead of committing the current one that will only be indexed (by calling `WriteBlock()`) after committing the best block.

  The previous code would leave the index database in an inconsistent state until the block is actually indexed - if an unclean shutdown happened at just this point in time, the index could get corrupted because at next startup, we'd assume that we have already indexed this block.

ACKs for top commit:
  ryanofsky:
    Code review ACK 7171ebc7cb. Looks great! Just commit message changes since last review

Tree-SHA512: a008de511dd6a1731b7fdf6a90add48d1e53f7f7d6402672adb83e362677fc5b9f5cd021d3111728cb41d73f1b9c2140db79d7e183df0ab359cda8c01b0ef928
2022-05-19 14:00:22 +01:00
Martin Zumsande 7171ebc7cb index: Don't commit a best block before indexing it during sync
Committing a block prior to indexing would leave the index database
in an inconsistent state until it is indexed, which could corrupt the
index in case of a unclean shutdown. Thus commit its predecessor.

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
2022-05-19 13:20:55 +02:00
w0xlt 92b35aba22 index, refactor: Change sync variables to use `std::chrono::steady_clock`
This refactors the sync variables to use `std::chrono::steady_clock`
as it is best suitable for measuring intervals.
2022-05-08 04:02:33 -03:00
Jon Atack 86ce844d3b blockstorage, refactor: pass GetFirstStoredBlock() start_block by reference
instead of by pointer, so as to not accept a nullptr.
2022-04-28 20:42:08 +02:00
Jon Atack ed12c0a49d blockstorage, refactor: make GetFirstStoredBlock() a member of BlockManager
instead of a global
2022-04-28 20:42:08 +02:00
Fabian Jahr f08c9fb0c6
Index: Use prune locks for blockfilterindex
Prior to this change blocks could be pruned up to the last block before the blockfilterindex current best block.
2022-04-25 23:22:00 +02:00