Browse Source

lightningd: implement gossip_get_txout/gossip_get_txout_reply.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
e22dd5ad71
  1. 4
      gossipd/gossip.c
  2. 11
      gossipd/gossip_wire.csv
  3. 31
      lightningd/gossip_control.c

4
gossipd/gossip.c

@ -1601,6 +1601,9 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_GETPEERS_REQUEST: case WIRE_GOSSIP_GETPEERS_REQUEST:
return get_peers(conn, daemon, master->msg_in); return get_peers(conn, daemon, master->msg_in);
case WIRE_GOSSIP_GET_TXOUT_REPLY:
/* FIXME */
/* We send these, we don't receive them */ /* We send these, we don't receive them */
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLY:
case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL: case WIRE_GOSSIPCTL_RELEASE_PEER_REPLYFAIL:
@ -1616,6 +1619,7 @@ static struct io_plan *recv_req(struct io_conn *conn, struct daemon_conn *master
case WIRE_GOSSIP_GET_UPDATE_REPLY: case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_SEND_GOSSIP: case WIRE_GOSSIP_SEND_GOSSIP:
case WIRE_GOSSIP_LOCAL_ADD_CHANNEL: case WIRE_GOSSIP_LOCAL_ADD_CHANNEL:
case WIRE_GOSSIP_GET_TXOUT:
break; break;
} }

11
gossipd/gossip_wire.csv

@ -157,3 +157,14 @@ gossip_local_add_channel,,cltv_expiry_delta,u16
gossip_local_add_channel,,htlc_minimum_msat,u64 gossip_local_add_channel,,htlc_minimum_msat,u64
gossip_local_add_channel,,fee_base_msat,u32 gossip_local_add_channel,,fee_base_msat,u32
gossip_local_add_channel,,fee_proportional_millionths,u32 gossip_local_add_channel,,fee_proportional_millionths,u32
# Gossipd->master get this tx output please.
gossip_get_txout,3018
gossip_get_txout,,short_channel_id,struct short_channel_id
# master->gossipd here is the output, or empty if none.
gossip_get_txout_reply,3118
gossip_get_txout_reply,,short_channel_id,struct short_channel_id
gossip_get_txout_reply,,len,u16
gossip_get_txout_reply,,outscript,len*u8

Can't render this file because it has a wrong number of fields in line 5.

31
lightningd/gossip_control.c

@ -1,3 +1,5 @@
#include "bitcoind.h"
#include "chaintopology.h"
#include "gossip_control.h" #include "gossip_control.h"
#include "lightningd.h" #include "lightningd.h"
#include "peer_control.h" #include "peer_control.h"
@ -53,6 +55,31 @@ static void peer_nongossip(struct subd *gossip, const u8 *msg,
peer_fd, gossip_fd, in_pkt); peer_fd, gossip_fd, in_pkt);
} }
static void got_txout(struct bitcoind *bitcoind,
const struct bitcoin_tx_output *output,
struct short_channel_id *scid)
{
/* output will be NULL if it wasn't found */
subd_send_msg(bitcoind->ld->gossip,
towire_gossip_get_txout_reply(scid, scid, output->script));
tal_free(scid);
}
static void get_txout(struct subd *gossip, const u8 *msg)
{
struct short_channel_id *scid = tal(gossip, struct short_channel_id);
if (!fromwire_gossip_get_txout(msg, NULL, scid))
fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s",
tal_hex(msg, msg));
/* FIXME: Block less than 6 deep? */
bitcoind_getoutput(gossip->ld->topology->bitcoind,
scid->blocknum, scid->txnum, scid->outnum,
got_txout, scid);
}
static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds) static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
{ {
enum gossip_wire_type t = fromwire_peektype(msg); enum gossip_wire_type t = fromwire_peektype(msg);
@ -72,6 +99,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPCTL_PEER_ADDRHINT: case WIRE_GOSSIPCTL_PEER_ADDRHINT:
case WIRE_GOSSIP_GET_UPDATE: case WIRE_GOSSIP_GET_UPDATE:
case WIRE_GOSSIP_SEND_GOSSIP: case WIRE_GOSSIP_SEND_GOSSIP:
case WIRE_GOSSIP_GET_TXOUT_REPLY:
/* This is a reply, so never gets through to here. */ /* This is a reply, so never gets through to here. */
case WIRE_GOSSIP_GET_UPDATE_REPLY: case WIRE_GOSSIP_GET_UPDATE_REPLY:
case WIRE_GOSSIP_GETNODES_REPLY: case WIRE_GOSSIP_GETNODES_REPLY:
@ -97,6 +125,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
return 2; return 2;
peer_nongossip(gossip, msg, fds[0], fds[1]); peer_nongossip(gossip, msg, fds[0], fds[1]);
break; break;
case WIRE_GOSSIP_GET_TXOUT:
get_txout(gossip, msg);
break;
} }
return 0; return 0;
} }

Loading…
Cancel
Save