aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/sqlite.h
AgeCommit message (Collapse)Author
2024-02-06sqlite: Ensure that only one SQLiteBatch is writing to db at a timeAva Chow
A SQLiteBatch need to wait for any other batch to finish writing before it can begin writing, otherwise db txn state may be incorrectly modified. To enforce this, each SQLiteDatabase has a semaphore which acts as a lock and is acquired by a batch when it begins a write, erase, or a transaction, and is released by it when it is done. To avoid deadlocking on itself for writing during a transaction, SQLiteBatch also keeps track of whether it has begun a transaction.
2024-01-30sqlite: introduce HasActiveTxn methodfurszy
Util function to clean up code and let us verify, in the following-up commit, that dangling, to-be-reverted db transactions cannot occur anymore.
2024-01-30sqlite: add ability to interrupt statementsfurszy
By encapsulating sqlite3_exec into its own standalone method and introducing the 'SQliteExecHandler' class, we enable the ability to test db statements execution failures within the unit test framework. This is used in the following-up commit to exercise a deadlock and improve our wallet db error handling code. Moreover, the future encapsulation of other sqlite functions within this class will contribute to minimize the impact of any future API changes.
2023-07-06wallet: sqlite: force sqlite3.h to be included by the cpp filesCory Fields
This way sqlite usage is explicit.
2023-06-01wallet: Add GetPrefixCursor to DatabaseBatchAndrew Chow
In order to get records beginning with a prefix, we will need a cursor specifically for that prefix. So add a GetPrefixCursor function and DatabaseCursor classes for dealing with those prefixes. Tested on each supported db engine. 1) Write two different key->value elements to db. 2) Create a new prefix cursor and walk-through every returned element, verifying that it gets parsed properly. 3) Try to move the cursor outside the filtered range: expect failure and flag complete=true. Co-Authored-By: Ryan Ofsky <ryan@ofsky.org> Co-Authored-By: furszy <matiasfurszyfer@protonmail.com>
2023-04-12wallet: Add DatabaseBatch::ErasePrefix methodRyan Ofsky
This new function is not used yet this commit, but next commit adds usages and test coverage for both BDB and sqlite.
2023-03-06Merge bitcoin/bitcoin#25491: wallet: use Mutex for g_sqlite_mutex instead of ↵Andrew Chow
GlobalMutex 4163093d6374e865dc57e33dbea0e7e359062e0a wallet: use Mutex for g_sqlite_mutex instead of GlobalMutex (Vasil Dimov) Pull request description: Using `Mutex` provides stronger guarantee than `GlobalMutex` wrt Clang's thread safety analysis. Thus it is better to reduce the usage of `GlobalMutex` in favor of `Mutex`. Using `Mutex` for `g_sqlite_mutex` is ok because its usage is limited in `wallet/sqlite.cpp` and it does not require propagating the negative annotations to not relevant code. ACKs for top commit: achow101: ACK 4163093d6374e865dc57e33dbea0e7e359062e0a hebasto: re-ACK 4163093d6374e865dc57e33dbea0e7e359062e0a TheCharlatan: ACK 4163093d6374e865dc57e33dbea0e7e359062e0a Tree-SHA512: 4913bcb8437ecf0e6b6cb781d02a6d24ffb4bf3e2e1899fa60785eab41c4c65dbdd9600bcb696290c873661b873ad61e5a4c4f205b7e66fdef2ae17c676cd12f
2023-01-26Use DataStream where possibleMarcoFalke
2023-01-23Merge bitcoin/bitcoin#26690: wallet: Refactor database cursor into its own ↵fanquake
object with proper return codes 4aebd832a405090c2608e4b60bb4f34501bcea61 db: Change DatabaseCursor::Next to return status enum (Andrew Chow) d79e8dcf2981ef1964a2fde8c472b5de1ca1c963 wallet: Have cursor users use DatabaseCursor directly (Andrew Chow) 7a198bba0a1d0a0f0fd4ca947955cb52b84bdd4b wallet: Introduce DatabaseCursor RAII class for managing cursor (Andrew Chow) 69efbc011bb74fcd8dd9ed2a8a5d31bc9e323c10 Move SafeDbt out of BerkeleyBatch (Andrew Chow) Pull request description: Instead of having database cursors be tied to a particular `DatabaseBatch` object and requiring its setup and teardown be separate functions in that batch, we can have cursors be separate RAII classes. This makes it easier to create and destroy cursors as well as having cursors that have slightly different behaviors. Additionally, since reading data from a cursor is a tri-state, this PR changes the return value of the `Next` function (formerly `ReadAtCursor`) to return an Enum rather than the current system of 2 booleans. This greatly simplifies and unifies the code that deals with cursors as now there is no confusion as to what the function returns when there are no records left to be read. Extracted from #24914 ACKs for top commit: furszy: diff ACK 4aebd83 theStack: Code-review ACK 4aebd832a405090c2608e4b60bb4f34501bcea61 Tree-SHA512: 5d0be56a18de5b08c777dd5a73ba5a6ef1e696fdb07d1dca952a88ded07887b7c5c04342f9a76feb2f6fe24a45dc31f094f1f5d9500e6bdf4a44f4edb66dcaa1
2022-12-24scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: - 2021: f47dda2c58b5d8d623e0e7ff4e74bc352dfa83d7 - 2020: fa0074e2d82928016a43ca408717154a1c70a4db - 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2022-12-16db: Change DatabaseCursor::Next to return status enumAndrew Chow
Next()'s result is a tri-state - failed, more to go, complete. Replace the way that this is returned with an enum with values FAIL, MORE, and DONE rather than with two booleans.
2022-12-14wallet: Introduce DatabaseCursor RAII class for managing cursorAndrew Chow
Instead of having DatabaseBatch deal with opening and closing database cursors, have a separate RAII class that deals with those. For now, DatabaseBatch manages DatabaseCursor, but this will change later.
2022-10-14wallet: use Mutex for g_sqlite_mutex instead of GlobalMutexVasil Dimov
Using `Mutex` provides stronger guarantee than `GlobalMutex` wrt Clang's thread safety analysis. Thus it is better to reduce the usage of `GlobalMutex` in favor of `Mutex`. Using `Mutex` for `g_sqlite_mutex` is ok because its usage is limited in `wallet/sqlite.cpp` and it does not require propagating the negative annotations to not relevant code.
2022-03-16Replace use of `ArgsManager` with `DatabaseOptions`Kiminuo
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
2022-01-06Add src/wallet/* code to wallet:: namespaceRussell Yanofsky
2021-01-04doc: fix various typosIkko Ashimine
Co-authored-by: Peter Yordanov <ppyordanov@yahoo.com>
2020-12-04refactor: Consolidate redundant wallet database path and exists functionsRussell Yanofsky
No change in behavior. Just remove a little bit of code, reduce macro usage, remove duplicative functions, and make BDB and SQLite implementations more consistent with each other.
2020-12-04MOVEONLY: Move IsBDBFile, IsSQLiteFile, and ListWalletDirRussell Yanofsky
This commit does not change to any code and behavior. It it is easily reviewed with the --color-moved=dimmed_zebra git diff option. Motivation for this change is to: - Consolidate redundant functions IsBDBFile /ExistsBerkeleyDatabase / SplitWalletPath, and IsSQLiteFile / ExistsSQLiteDatabase in the next commits - Detect SQLite wallets consistently regardless whether bitcoin is built with SQLite support in the next commits - Avoid attempting to open SQLite databases with the BDB library when bitcoin is built without SQLite support in the next commits
2020-10-14rpc, wallet: Expose database format in getwalletinfoJoão Barbosa
2020-10-14Determine wallet file type based on file magicAndrew Chow
2020-10-14Implement SQLiteDatabase::VerifyAndrew Chow
2020-10-14Implement SQLiteBatch::StartCursor, ReadAtCursor, and CloseCursorAndrew Chow
2020-10-14Add SetupSQLStatementsAndrew Chow
2020-10-14Initialize and Shutdown sqlite3 globalsAndrew Chow
sqlite3 recommends that sqlite3_initialize be called when the application starts, and sqlite3_shutdown when it stops. Since we don't always use sqlite3, we initialize it when a SQLiteDatabse is constructed (calling sqlite3_initialize after initialized is a no-op). We call sqlite3_shutdown when we see that there are no databases opened. The number of open databases is tracked by an atomic g_dbs_open.
2020-10-14Constructors, destructors, and relevant private fields for SQLiteDatabase/BatchAndrew Chow
2020-10-14Implement SQLiteDatabaseVersionAndrew Chow
2020-10-14Add SQLiteDatabase and SQLiteBatch dummy classesAndrew Chow