mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-17 03:54:31 +01:00
channeld: increment fee states properly.
By iterating through them forward, we would often increment them more than once! Always print feestate transitions, which is how I worked this out. Changelog-Fixed: Protocol: handle complex feerate transitions correctly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -937,7 +937,6 @@ static bool fee_incstate(struct channel *channel,
|
||||
enum htlc_state hstate)
|
||||
{
|
||||
int preflags, postflags;
|
||||
const int committed_f = HTLC_FLAG(sidechanged, HTLC_F_COMMITTED);
|
||||
|
||||
preflags = htlc_state_flags(hstate);
|
||||
postflags = htlc_state_flags(hstate + 1);
|
||||
@@ -953,12 +952,11 @@ static bool fee_incstate(struct channel *channel,
|
||||
if (!inc_fee_state(channel->fee_states, hstate))
|
||||
return false;
|
||||
|
||||
if (!(preflags & committed_f) && (postflags & committed_f))
|
||||
status_debug("Feerate: %s->%s %s now %u",
|
||||
htlc_state_name(hstate),
|
||||
htlc_state_name(hstate+1),
|
||||
side_to_str(sidechanged),
|
||||
*channel->fee_states->feerate[hstate+1]);
|
||||
status_debug("Feerate: %s->%s %s now %u",
|
||||
htlc_state_name(hstate),
|
||||
htlc_state_name(hstate+1),
|
||||
side_to_str(sidechanged),
|
||||
*channel->fee_states->feerate[hstate+1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -973,7 +971,7 @@ static int change_htlcs(struct channel *channel,
|
||||
struct htlc_map_iter it;
|
||||
struct htlc *h;
|
||||
int cflags = 0;
|
||||
size_t i;
|
||||
int i;
|
||||
struct balance owed[NUM_SIDES];
|
||||
|
||||
for (i = 0; i < NUM_SIDES; i++)
|
||||
@@ -1005,8 +1003,8 @@ static int change_htlcs(struct channel *channel,
|
||||
}
|
||||
}
|
||||
|
||||
/* Update fees. */
|
||||
for (i = 0; i < n_hstates; i++) {
|
||||
/* Update fees (do backwards, to avoid double-increment!). */
|
||||
for (i = n_hstates - 1; i >= 0; i--) {
|
||||
if (fee_incstate(channel, sidechanged, htlc_states[i]))
|
||||
cflags |= (htlc_state_flags(htlc_states[i])
|
||||
^ htlc_state_flags(htlc_states[i]+1));
|
||||
|
||||
Reference in New Issue
Block a user