rgb-cln/wallet
Christian Decker 3f3a48dae9 db: Turn the transaction counter into an optimistic lock
The optimistic lock prevents multiple instances of c-lightning making
concurrent modifications to the database. That would be unsafe as it messes up
the state in the DB. The optimistic lock is implemented by checking whether a
gated update on the previous value of the `data_version` actually results in
an update. If that's not the case the DB has been changed under our feet.

The lock provides linearizability of DB modifications: if a database is
changed under the feet of a running process that process will `abort()`, which
from a global point of view is as if it had crashed right after the last
successful commit. Any process that also changed the DB must've started
between the last successful commit and the unsuccessful one since otherwise
its counters would not have matched (which would also have aborted that
transaction). So this reduces all the possible timelines to an equivalent
where the first process died, and the second process recovered from the DB.

This is not that interesting for `sqlite3` where we are also protected via the
PID file, but when running on multiple hosts against the same DB, e.g., with
`postgres`, this protection becomes important.

Changelog-Added: DB: Optimistic logging prevents instances from running concurrently against the same database, providing linear consistency to changes.
2020-01-02 14:12:59 -06:00
..
test db: Track the data_version in the database 2020-01-02 14:12:59 -06:00
.gitignore wallet: Create and manage a sqlite3 database for the wallet 2017-06-06 09:16:10 +09:30
Makefile wallet/Makefile: fix dependency line. 2019-11-28 11:50:13 +01:00
db.c db: Turn the transaction counter into an optimistic lock 2020-01-02 14:12:59 -06:00
db.h db: Track the data_version in the database 2020-01-02 14:12:59 -06:00
db_common.h db: Track the data_version in the database 2020-01-02 14:12:59 -06:00
db_postgres.c db: Implement postgres driver primitives 2019-09-22 02:03:43 +00:00
db_sqlite3.c db: Move remainder of the sqlite3 into the apropriate file 2019-09-22 02:03:43 +00:00
invoices.c wallet: add invoice features into db. 2019-11-24 23:33:17 +00:00
invoices.h wallet: add invoice features into db. 2019-11-24 23:33:17 +00:00
txfilter.c elements: Fix transaction handling for elements transactions 2019-10-03 04:32:57 +00:00
txfilter.h pubkey: rename PUBKEY_DER_LEN to PUBKEY_CMPR_LEN. 2019-04-09 12:37:16 -07:00
wallet.c wallet: remove edgecase around transaction checks 2020-01-02 16:56:42 +01:00
wallet.h wallet: remove edgecase around transaction checks 2020-01-02 16:56:42 +01:00
walletrpc.c bitcoind: remove the chainparams member 2019-11-15 13:14:08 +01:00
walletrpc.h Use expected LIGHTNING_DIR_FILE_H define 2018-03-25 23:54:21 +00:00