mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-11 01:54:25 +01:00
channel_state: add htlcs array.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
18
funding.c
18
funding.c
@@ -36,7 +36,17 @@ static bool subtract_fees(uint64_t *funder, uint64_t *non_funder,
|
||||
*funder -= *funder_fee;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static uint64_t htlcs_total(UpdateAddHtlc *const *htlcs)
|
||||
{
|
||||
size_t i, n = tal_count(htlcs);
|
||||
uint64_t total = 0;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
total += htlcs[i]->amount;
|
||||
return total;
|
||||
}
|
||||
|
||||
bool funding_delta(const OpenChannel *oa,
|
||||
const OpenChannel *ob,
|
||||
const OpenAnchor *anchor,
|
||||
@@ -53,7 +63,8 @@ bool funding_delta(const OpenChannel *oa,
|
||||
a = a_side->pay + a_side->fee;
|
||||
b = b_side->pay + b_side->fee;
|
||||
fee = a_side->fee + b_side->fee;
|
||||
assert(a + b == anchor->amount);
|
||||
assert(a + b + htlcs_total(a_side->htlcs) + htlcs_total(b_side->htlcs)
|
||||
== anchor->amount);
|
||||
|
||||
/* Only one can be funder. */
|
||||
if (is_funder(oa) == is_funder(ob))
|
||||
@@ -101,6 +112,9 @@ struct channel_state *initial_funding(const tal_t *ctx,
|
||||
{
|
||||
struct channel_state *state = talz(ctx, struct channel_state);
|
||||
|
||||
state->a.htlcs = tal_arr(state, UpdateAddHtlc *, 0);
|
||||
state->b.htlcs = tal_arr(state, UpdateAddHtlc *, 0);
|
||||
|
||||
if (fee > anchor->amount)
|
||||
return tal_free(state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user