mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
wallet: Add function to add filteredblocks from backfilling
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
f4e434d8e1
commit
3dbaae38e3
2 changed files with 60 additions and 1 deletions
|
@ -8,7 +8,6 @@
|
||||||
#include <common/memleak.h>
|
#include <common/memleak.h>
|
||||||
#include <common/wireaddr.h>
|
#include <common/wireaddr.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <lightningd/bitcoind.h>
|
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/notification.h>
|
#include <lightningd/notification.h>
|
||||||
#include <lightningd/peer_control.h>
|
#include <lightningd/peer_control.h>
|
||||||
|
@ -2412,6 +2411,53 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
||||||
outpointfilter_add(w->utxoset_outpoints, &txid, outnum);
|
outpointfilter_add(w->utxoset_outpoints, &txid, outnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wallet_filteredblock_add(struct wallet *w, struct filteredblock *fb)
|
||||||
|
{
|
||||||
|
if (wallet_have_block(w, fb->height))
|
||||||
|
return;
|
||||||
|
sqlite3_stmt *stmt = db_prepare(w->db, "INSERT OR IGNORE INTO blocks "
|
||||||
|
"(height, hash, prev_hash) "
|
||||||
|
"VALUES (?, ?, ?);");
|
||||||
|
sqlite3_bind_int(stmt, 1, fb->height);
|
||||||
|
sqlite3_bind_sha256_double(stmt, 2, &fb->id.shad);
|
||||||
|
sqlite3_bind_sha256_double(stmt, 3, &fb->prev_hash.shad);
|
||||||
|
db_exec_prepared(w->db, stmt);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < tal_count(fb->outpoints); i++) {
|
||||||
|
struct filteredblock_outpoint *o = fb->outpoints[i];
|
||||||
|
stmt = db_prepare(w->db, "INSERT INTO utxoset ("
|
||||||
|
" txid,"
|
||||||
|
" outnum,"
|
||||||
|
" blockheight,"
|
||||||
|
" spendheight,"
|
||||||
|
" txindex,"
|
||||||
|
" scriptpubkey,"
|
||||||
|
" satoshis"
|
||||||
|
") VALUES(?, ?, ?, ?, ?, ?, ?);");
|
||||||
|
sqlite3_bind_sha256_double(stmt, 1, &o->txid.shad);
|
||||||
|
sqlite3_bind_int(stmt, 2, o->outnum);
|
||||||
|
sqlite3_bind_int(stmt, 3, fb->height);
|
||||||
|
sqlite3_bind_null(stmt, 4);
|
||||||
|
sqlite3_bind_int(stmt, 5, o->txindex);
|
||||||
|
sqlite3_bind_blob(stmt, 6, o->scriptPubKey,
|
||||||
|
tal_count(o->scriptPubKey), SQLITE_TRANSIENT);
|
||||||
|
sqlite3_bind_amount_sat(stmt, 7, o->satoshis);
|
||||||
|
db_exec_prepared(w->db, stmt);
|
||||||
|
|
||||||
|
outpointfilter_add(w->utxoset_outpoints, &o->txid, o->outnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wallet_have_block(struct wallet *w, u32 blockheight)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
sqlite3_stmt *stmt = db_select_prepare(w->db, "height FROM blocks WHERE height = ?");
|
||||||
|
sqlite3_bind_int(stmt, 1, blockheight);
|
||||||
|
result = sqlite3_step(stmt) == SQLITE_ROW;
|
||||||
|
db_stmt_done(stmt);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
||||||
const struct short_channel_id *scid)
|
const struct short_channel_id *scid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <common/channel_config.h>
|
#include <common/channel_config.h>
|
||||||
#include <common/utxo.h>
|
#include <common/utxo.h>
|
||||||
#include <common/wallet.h>
|
#include <common/wallet.h>
|
||||||
|
#include <lightningd/bitcoind.h>
|
||||||
#include <lightningd/chaintopology.h>
|
#include <lightningd/chaintopology.h>
|
||||||
#include <lightningd/htlc_end.h>
|
#include <lightningd/htlc_end.h>
|
||||||
#include <lightningd/invoice.h>
|
#include <lightningd/invoice.h>
|
||||||
|
@ -1023,6 +1024,11 @@ void wallet_block_remove(struct wallet *w, struct block *b);
|
||||||
*/
|
*/
|
||||||
void wallet_blocks_rollback(struct wallet *w, u32 height);
|
void wallet_blocks_rollback(struct wallet *w, u32 height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether we have a block for the given height.
|
||||||
|
*/
|
||||||
|
bool wallet_have_block(struct wallet *w, u32 blockheight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark an outpoint as spent, both in the owned as well as the UTXO set
|
* Mark an outpoint as spent, both in the owned as well as the UTXO set
|
||||||
*
|
*
|
||||||
|
@ -1159,4 +1165,11 @@ void free_unreleased_txs(struct wallet *w);
|
||||||
*/
|
*/
|
||||||
struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx);
|
struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a filteredblock to the blocks and utxoset tables.
|
||||||
|
*
|
||||||
|
* This can be used to backfill the blocks and still unspent UTXOs that were before our wallet birth height.
|
||||||
|
*/
|
||||||
|
void wallet_filteredblock_add(struct wallet *w, struct filteredblock *fb);
|
||||||
|
|
||||||
#endif /* LIGHTNING_WALLET_WALLET_H */
|
#endif /* LIGHTNING_WALLET_WALLET_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue