mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
gossip: Use the getfilteredblock method to look up scid outputs
Just a tiny shim to reconcile the `get_output` with `getfileteredblock`. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
3dbaae38e3
commit
98447e454e
@@ -59,6 +59,34 @@ static void got_txout(struct bitcoind *bitcoind,
|
|||||||
tal_free(scid);
|
tal_free(scid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void got_filteredblock(struct bitcoind *bitcoind,
|
||||||
|
struct filteredblock *fb,
|
||||||
|
void *arg)
|
||||||
|
{
|
||||||
|
struct short_channel_id *scid = (struct short_channel_id *)arg;
|
||||||
|
struct filteredblock_outpoint *fbo = NULL, *o;
|
||||||
|
struct bitcoin_tx_output txo;
|
||||||
|
|
||||||
|
wallet_filteredblock_add(bitcoind->ld->wallet, fb);
|
||||||
|
|
||||||
|
u32 outnum = short_channel_id_outnum(scid);
|
||||||
|
u32 txindex = short_channel_id_txnum(scid);
|
||||||
|
for (size_t i=0; i<tal_count(fb->outpoints); i++) {
|
||||||
|
o = fb->outpoints[i];
|
||||||
|
if (o->txindex == txindex && o->outnum == outnum) {
|
||||||
|
fbo = o;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fbo) {
|
||||||
|
txo.amount = fbo->satoshis;
|
||||||
|
txo.script = (u8 *)fbo->scriptPubKey;
|
||||||
|
got_txout(bitcoind, &txo, scid);
|
||||||
|
} else
|
||||||
|
got_txout(bitcoind, NULL, scid);
|
||||||
|
}
|
||||||
|
|
||||||
static void get_txout(struct subd *gossip, const u8 *msg)
|
static void get_txout(struct subd *gossip, const u8 *msg)
|
||||||
{
|
{
|
||||||
struct short_channel_id *scid = tal(gossip, struct short_channel_id);
|
struct short_channel_id *scid = tal(gossip, struct short_channel_id);
|
||||||
@@ -80,21 +108,16 @@ static void get_txout(struct subd *gossip, const u8 *msg)
|
|||||||
towire_gossip_get_txout_reply(
|
towire_gossip_get_txout_reply(
|
||||||
scid, scid, op->sat, op->scriptpubkey));
|
scid, scid, op->sat, op->scriptpubkey));
|
||||||
tal_free(scid);
|
tal_free(scid);
|
||||||
} else if (blockheight >= topo->min_blockheight &&
|
} else if (wallet_have_block(gossip->ld->wallet, blockheight)) {
|
||||||
blockheight <= topo->max_blockheight) {
|
/* We should have known about this outpoint since its header
|
||||||
/* We should have known about this outpoint since it is included
|
* is in the DB. The fact that we don't means that this is
|
||||||
* in the range in the DB. The fact that we don't means that
|
* either a spent outpoint or an invalid one. Return a
|
||||||
* this is either a spent outpoint or an invalid one. Return a
|
|
||||||
* failure. */
|
* failure. */
|
||||||
subd_send_msg(gossip, take(towire_gossip_get_txout_reply(
|
subd_send_msg(gossip, take(towire_gossip_get_txout_reply(
|
||||||
NULL, scid, AMOUNT_SAT(0), NULL)));
|
NULL, scid, AMOUNT_SAT(0), NULL)));
|
||||||
tal_free(scid);
|
tal_free(scid);
|
||||||
} else {
|
} else {
|
||||||
bitcoind_getoutput(topo->bitcoind,
|
bitcoind_getfilteredblock(topo->bitcoind, short_channel_id_blocknum(scid), got_filteredblock, scid);
|
||||||
short_channel_id_blocknum(scid),
|
|
||||||
short_channel_id_txnum(scid),
|
|
||||||
short_channel_id_outnum(scid),
|
|
||||||
got_txout, scid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ from fixtures import * # noqa: F401,F403
|
|||||||
from utils import wait_for
|
from utils import wait_for
|
||||||
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_db_dangling_peer_fix(node_factory):
|
def test_db_dangling_peer_fix(node_factory):
|
||||||
# This was taken from test_fail_unconfirmed() node.
|
# This was taken from test_fail_unconfirmed() node.
|
||||||
l1 = node_factory.get_node(dbfile='dangling-peer.sqlite3.xz')
|
l1 = node_factory.get_node(dbfile='dangling-peer.sqlite3.xz')
|
||||||
@@ -21,7 +18,6 @@ def test_db_dangling_peer_fix(node_factory):
|
|||||||
l2.fund_channel(l1, 200000, wait_for_active=True)
|
l2.fund_channel(l1, 200000, wait_for_active=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=True)
|
|
||||||
def test_block_backfill(node_factory, bitcoind):
|
def test_block_backfill(node_factory, bitcoind):
|
||||||
"""Test whether we backfill data from the blockchain correctly.
|
"""Test whether we backfill data from the blockchain correctly.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user