db: Track the data_version in the database

This increments the `data_version` upon committing dirty transactions, reads
the last data_version upon startup, and tracks the number in memory in
parallel to the DB (see next commit for rationale).

Changelog-Changed: JSON-RPC: Added a `data_version` field to the `db_write` hook which returns a numeric transaction counter.
This commit is contained in:
Christian Decker
2019-12-18 19:45:24 +01:00
committed by neil saitug
parent 4a4184be70
commit 2c11c54dd2
6 changed files with 43 additions and 0 deletions

View File

@@ -175,6 +175,8 @@ void plugin_hook_db_sync(struct db *db)
ph_req->hook = hook;
ph_req->db = db;
json_add_num(req->stream, "data_version", db_data_version_get(db));
json_array_start(req->stream, "writes");
for (size_t i = 0; i < tal_count(changes); i++)
json_add_string(req->stream, NULL, changes[i]);