Browse Source

wallet: Add a gap limit when checking for incoming transactions

Changelog-Added: wallet: The wallet now has a gap limit that is used to check for incoming transactions when scanning the blockchain.
nifty/pset-pre
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
fb8661714e
  1. 2
      lightningd/lightningd.c
  2. 7
      wallet/wallet.c
  3. 3
      wallet/wallet.h

2
lightningd/lightningd.c

@ -572,7 +572,7 @@ static void init_txfilter(struct wallet *w, struct txfilter *filter)
bip32_max_index = db_get_intvar(w->db, "bip32_max_index", 0);
/*~ One of the C99 things I unequivocally approve: for-loop scope. */
for (u64 i = 0; i <= bip32_max_index; i++) {
for (u64 i = 0; i <= bip32_max_index + w->keyscan_gap; i++) {
if (bip32_key_from_parent(w->bip32_base, i, BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) {
abort();
}

7
wallet/wallet.c

@ -60,6 +60,7 @@ struct wallet *wallet_new(struct lightningd *ld, struct timers *timers)
wallet->db = db_setup(wallet, ld);
wallet->log = new_log(wallet, ld->log_book, NULL, "wallet");
wallet->bip32_base = NULL;
wallet->keyscan_gap = 50;
list_head_init(&wallet->unstored_payments);
list_head_init(&wallet->unreleased_txs);
@ -551,7 +552,7 @@ bool wallet_can_spend(struct wallet *w, const u8 *script,
else
return false;
for (i = 0; i <= bip32_max_index; i++) {
for (i = 0; i <= bip32_max_index + w->keyscan_gap; i++) {
u8 *s;
if (bip32_key_from_parent(w->bip32_base, i,
@ -566,6 +567,10 @@ bool wallet_can_spend(struct wallet *w, const u8 *script,
s = p2sh;
}
if (scripteq(s, script)) {
/* If we found a used key in the keyscan_gap we should
* remember that. */
if (i > bip32_max_index)
db_set_intvar(w->db, "bip32_max_index", i);
tal_free(s);
*index = i;
return true;

3
wallet/wallet.h

@ -50,6 +50,9 @@ struct wallet {
/* Unreleased txs, waiting for txdiscard/txsend */
struct list_head unreleased_txs;
/* How many keys should we look ahead at most? */
u64 keyscan_gap;
};
/* A transaction we've txprepared, but haven't signed and released yet */

Loading…
Cancel
Save