mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
daemon/htlc: including routing information.
This is the logical place for it to belong: with the HTLC. For the manually-created HTLCs, we create a simple one-hop route. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -172,7 +172,8 @@ void queue_pkt_htlc_add(struct peer *peer,
|
||||
u64 id,
|
||||
u64 msatoshis,
|
||||
const struct sha256 *rhash,
|
||||
u32 expiry)
|
||||
u32 expiry,
|
||||
const u8 *route)
|
||||
{
|
||||
UpdateAddHtlc *u = tal(peer, UpdateAddHtlc);
|
||||
union htlc_staging stage;
|
||||
@@ -197,11 +198,14 @@ void queue_pkt_htlc_add(struct peer *peer,
|
||||
* changeset for its remote commitment
|
||||
*/
|
||||
htlc = funding_add_htlc(peer->remote.staging_cstate,
|
||||
msatoshis, &locktime, rhash, id, OURS);
|
||||
msatoshis, &locktime, rhash, id,
|
||||
route, tal_count(route), OURS);
|
||||
if (!htlc)
|
||||
fatal("Could not add HTLC?");
|
||||
|
||||
stage.add.add = HTLC_ADD;
|
||||
/* FIXME: This assumes stage's lifetime >= htlc, since we copy
|
||||
* htlc.route pointer. Why not just make stage.add.htlc a ptr? */
|
||||
stage.add.htlc = *htlc;
|
||||
add_unacked(&peer->remote, &stage);
|
||||
|
||||
@@ -347,7 +351,10 @@ static void apply_changeset(struct peer *peer,
|
||||
changes[i].add.htlc.msatoshis,
|
||||
&changes[i].add.htlc.expiry,
|
||||
&changes[i].add.htlc.rhash,
|
||||
changes[i].add.htlc.id, side))
|
||||
changes[i].add.htlc.id,
|
||||
changes[i].add.htlc.routing,
|
||||
tal_count(changes[i].add.htlc.routing),
|
||||
side))
|
||||
fatal("Adding HTLC to %s failed",
|
||||
side == OURS ? "ours" : "theirs");
|
||||
continue;
|
||||
@@ -654,7 +661,9 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
|
||||
* ...and the receiving node MUST add the HTLC addition to the
|
||||
* unacked changeset for its local commitment. */
|
||||
htlc = funding_add_htlc(peer->local.staging_cstate,
|
||||
u->amount_msat, &expiry, &rhash, u->id, THEIRS);
|
||||
u->amount_msat, &expiry, &rhash, u->id,
|
||||
u->route->info.data, u->route->info.len,
|
||||
THEIRS);
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
#include "lightningd.h"
|
||||
#include "log.h"
|
||||
#include "names.h"
|
||||
#include "onion.h"
|
||||
#include "payment.h"
|
||||
#include "peer.h"
|
||||
#include "permute_tx.h"
|
||||
#include "protobuf_convert.h"
|
||||
#include "pseudorand.h"
|
||||
#include "routing.h"
|
||||
#include "secrets.h"
|
||||
#include "state.h"
|
||||
#include "timeout.h"
|
||||
@@ -554,7 +556,8 @@ static bool command_htlc_fulfill(struct peer *peer,
|
||||
|
||||
static bool command_htlc_add(struct peer *peer, u64 msatoshis,
|
||||
unsigned int expiry,
|
||||
const struct sha256 *rhash)
|
||||
const struct sha256 *rhash,
|
||||
const u8 *route)
|
||||
{
|
||||
struct channel_state *cstate;
|
||||
struct abs_locktime locktime;
|
||||
@@ -600,7 +603,9 @@ static bool command_htlc_add(struct peer *peer, u64 msatoshis,
|
||||
*/
|
||||
cstate = copy_funding(peer, peer->remote.staging_cstate);
|
||||
if (!funding_add_htlc(cstate, msatoshis,
|
||||
&locktime, rhash, peer->htlc_id_counter, OURS)) {
|
||||
&locktime, rhash, peer->htlc_id_counter,
|
||||
route, tal_count(route),
|
||||
OURS)) {
|
||||
log_unusual(peer->log, "add_htlc: fail: Cannot afford %"PRIu64
|
||||
" milli-satoshis in their commit tx",
|
||||
msatoshis);
|
||||
@@ -610,7 +615,9 @@ static bool command_htlc_add(struct peer *peer, u64 msatoshis,
|
||||
|
||||
cstate = copy_funding(peer, peer->local.staging_cstate);
|
||||
if (!funding_add_htlc(cstate, msatoshis,
|
||||
&locktime, rhash, peer->htlc_id_counter, OURS)) {
|
||||
&locktime, rhash, peer->htlc_id_counter,
|
||||
route, tal_count(route),
|
||||
OURS)) {
|
||||
log_unusual(peer->log, "add_htlc: fail: Cannot afford %"PRIu64
|
||||
" milli-satoshis in our commit tx",
|
||||
msatoshis);
|
||||
@@ -619,7 +626,7 @@ static bool command_htlc_add(struct peer *peer, u64 msatoshis,
|
||||
tal_free(cstate);
|
||||
|
||||
queue_pkt_htlc_add(peer, peer->htlc_id_counter,
|
||||
msatoshis, rhash, expiry);
|
||||
msatoshis, rhash, expiry, route);
|
||||
|
||||
/* Make sure we never offer the same one twice. */
|
||||
peer->htlc_id_counter++;
|
||||
@@ -2491,6 +2498,15 @@ const struct json_command getpeers_command = {
|
||||
"Returns a 'peers' array"
|
||||
};
|
||||
|
||||
/* A zero-fee single route to this peer. */
|
||||
static const u8 *dummy_single_route(const tal_t *ctx,
|
||||
const struct peer *peer,
|
||||
u64 msatoshis)
|
||||
{
|
||||
struct node_connection **path = tal_arr(ctx, struct node_connection *, 0);
|
||||
return onion_create(ctx, path, msatoshis, 0);
|
||||
}
|
||||
|
||||
static void json_newhtlc(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
@@ -2543,7 +2559,8 @@ static void json_newhtlc(struct command *cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!command_htlc_add(peer, msatoshis, expiry, &rhash)) {
|
||||
if (!command_htlc_add(peer, msatoshis, expiry, &rhash,
|
||||
dummy_single_route(cmd, peer, msatoshis))) {
|
||||
command_fail(cmd, "could not add htlc");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user