mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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.
This commit is contained in:
parent
264b2d1975
commit
fb8661714e
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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…
Reference in New Issue
Block a user