-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coin moves: persist the coin movement index counter to disk
Should make it easier to track when coin moves in the plugin are disjoint from what c-lightning says it's broadcast already.
- Loading branch information
Showing
11 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,61 @@ | ||
#include <lightningd/coin_mvts.h> | ||
#include <lightningd/notification.h> | ||
|
||
static s64 update_count(struct lightningd *ld) | ||
{ | ||
s64 count; | ||
bool db_in_tx; | ||
db_in_tx = db_in_transaction(ld->wallet->db); | ||
if (!db_in_tx) | ||
db_begin_transaction(ld->wallet->db); | ||
/* This could be written more concisely as | ||
* count = ++ld->coin_moves_count; | ||
* however I believe that's contra-code conventions */ | ||
ld->coin_moves_count++; | ||
count = ld->coin_moves_count; | ||
db_set_intvar(ld->wallet->db, "coin_moves_count", | ||
count); | ||
if (!db_in_tx) | ||
db_commit_transaction(ld->wallet->db); | ||
return count; | ||
} | ||
|
||
void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt) | ||
{ | ||
const struct coin_mvt *cm; | ||
u32 timestamp; | ||
s64 count; | ||
|
||
timestamp = time_now().ts.tv_sec; | ||
count = update_count(ld); | ||
cm = finalize_channel_mvt(mvt, mvt, timestamp, | ||
&ld->id); | ||
&ld->id, count); | ||
notify_coin_mvt(ld, cm); | ||
} | ||
|
||
void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt) | ||
{ | ||
const struct coin_mvt *cm; | ||
u32 timestamp; | ||
s64 count; | ||
|
||
timestamp = time_now().ts.tv_sec; | ||
count = update_count(ld); | ||
cm = finalize_chain_mvt(mvt, mvt, timestamp, | ||
&ld->id); | ||
&ld->id, count); | ||
notify_coin_mvt(ld, cm); | ||
} | ||
|
||
void coin_mvts_init_count(struct lightningd *ld) | ||
{ | ||
s64 count; | ||
db_begin_transaction(ld->wallet->db); | ||
count = db_get_intvar(ld->wallet->db, | ||
"coin_moves_count", -1); | ||
db_commit_transaction(ld->wallet->db); | ||
if (count == -1) | ||
fatal("Something went wrong attmepting to fetch" | ||
"the latest `coin_moves_count` from the intvars " | ||
"table"); | ||
ld->coin_moves_count = count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters