Esempio n. 1
0
void queue_pkt_htlc_add(struct peer *peer, struct htlc *htlc)
{
	UpdateAddHtlc *u = tal(peer, UpdateAddHtlc);
	union htlc_staging stage;

	update_add_htlc__init(u);

	u->id = htlc->id;
	u->amount_msat = htlc->msatoshis;
	u->r_hash = sha256_to_proto(u, &htlc->rhash);
	u->expiry = abs_locktime_to_proto(u, &htlc->expiry);
	u->route = tal(u, Routing);
	routing__init(u->route);
	u->route->info.data = tal_dup_arr(u, u8,
					  htlc->routing,
					  tal_count(htlc->routing),
					  0);
	u->route->info.len = tal_count(u->route->info.data);

	/* BOLT #2:
	 *
	 * The sending node MUST add the HTLC addition to the unacked
	 * changeset for its remote commitment
	 */
	if (!cstate_add_htlc(peer->remote.staging_cstate, htlc, OURS))
		fatal("Could not add HTLC?");

	stage.add.add = HTLC_ADD;
	stage.add.htlc = htlc;
	add_unacked(&peer->remote, &stage);

	remote_changes_pending(peer);

	queue_pkt(peer, PKT__PKT_UPDATE_ADD_HTLC, u);
}
Esempio n. 2
0
void queue_pkt_htlc_add(struct peer *peer,
		  const struct htlc_progress *htlc_prog)
{
	UpdateAddHtlc *u = tal(peer, UpdateAddHtlc);

	update_add_htlc__init(u);
	assert(htlc_prog->stage.type == HTLC_ADD);

	u->id = htlc_prog->stage.add.htlc.id;
	u->amount_msat = htlc_prog->stage.add.htlc.msatoshis;
	u->r_hash = sha256_to_proto(u, &htlc_prog->stage.add.htlc.rhash);
	u->expiry = abs_locktime_to_proto(u, &htlc_prog->stage.add.htlc.expiry);
	/* FIXME: routing! */
	u->route = tal(u, Routing);
	routing__init(u->route);

	/* We're about to send this, so their side will have it from now on. */
	if (!funding_b_add_htlc(peer->them.staging_cstate,
				htlc_prog->stage.add.htlc.msatoshis,
				&htlc_prog->stage.add.htlc.expiry,
				&htlc_prog->stage.add.htlc.rhash,
				htlc_prog->stage.add.htlc.id))
		fatal("Could not add HTLC?");

	peer_add_htlc_expiry(peer, &htlc_prog->stage.add.htlc.expiry);
	
	queue_pkt_with_ack(peer, PKT__PKT_UPDATE_ADD_HTLC, u,
			   add_our_htlc_ourside,
			   tal_dup(peer, struct channel_htlc,
				   &htlc_prog->stage.add.htlc));
}