@ -619,11 +619,36 @@ static void htlc_incstate(struct channel *channel,
}
}
}
}
static void check_lockedin ( const struct htlc * h ,
struct peer * peer ,
void ( * oursfail ) ( struct peer * peer ,
const struct htlc * htlc ) ,
void ( * theirslocked ) ( struct peer * peer ,
const struct htlc * htlc ) ,
void ( * theirsfulfilled ) ( struct peer * peer ,
const struct htlc * htlc ) )
{
/* If it was fulfilled, we handled it immediately. */
if ( h - > state = = RCVD_REMOVE_ACK_REVOCATION & & ! h - > r )
oursfail ( peer , h ) ;
else if ( h - > state = = RCVD_ADD_ACK_REVOCATION )
theirslocked ( peer , h ) ;
else if ( h - > state = = RCVD_REMOVE_ACK_COMMIT & & h - > r )
theirsfulfilled ( peer , h ) ;
}
/* FIXME: Commit to storage when this happens. */
/* FIXME: Commit to storage when this happens. */
static bool change_htlcs ( struct channel * channel ,
static bool change_htlcs ( struct channel * channel ,
enum side sidechanged ,
enum side sidechanged ,
const enum htlc_state * htlc_states ,
const enum htlc_state * htlc_states ,
size_t n_hstates )
size_t n_hstates ,
struct peer * peer ,
void ( * oursfail ) ( struct peer * peer ,
const struct htlc * htlc ) ,
void ( * theirslocked ) ( struct peer * peer ,
const struct htlc * htlc ) ,
void ( * theirsfulfilled ) ( struct peer * peer ,
const struct htlc * htlc ) )
{
{
struct htlc_map_iter it ;
struct htlc_map_iter it ;
struct htlc * h ;
struct htlc * h ;
@ -636,6 +661,10 @@ static bool change_htlcs(struct channel *channel,
for ( i = 0 ; i < n_hstates ; i + + ) {
for ( i = 0 ; i < n_hstates ; i + + ) {
if ( h - > state = = htlc_states [ i ] ) {
if ( h - > state = = htlc_states [ i ] ) {
htlc_incstate ( channel , h , sidechanged ) ;
htlc_incstate ( channel , h , sidechanged ) ;
check_lockedin ( h , peer ,
oursfail ,
theirslocked ,
theirsfulfilled ) ;
changed = true ;
changed = true ;
}
}
}
}
@ -651,10 +680,16 @@ bool channel_sent_commit(struct channel *channel)
SENT_ADD_REVOCATION ,
SENT_ADD_REVOCATION ,
SENT_REMOVE_HTLC } ;
SENT_REMOVE_HTLC } ;
status_trace ( " sent commit " ) ;
status_trace ( " sent commit " ) ;
return change_htlcs ( channel , REMOTE , states , ARRAY_SIZE ( states ) ) ;
return change_htlcs ( channel , REMOTE , states , ARRAY_SIZE ( states ) ,
NULL , NULL , NULL , NULL ) ;
}
}
bool channel_rcvd_revoke_and_ack ( struct channel * channel )
bool channel_rcvd_revoke_and_ack ( struct channel * channel ,
struct peer * peer ,
void ( * oursfail ) ( struct peer * peer ,
const struct htlc * htlc ) ,
void ( * theirslocked ) ( struct peer * peer ,
const struct htlc * htlc ) )
{
{
const enum htlc_state states [ ] = { SENT_ADD_COMMIT ,
const enum htlc_state states [ ] = { SENT_ADD_COMMIT ,
SENT_REMOVE_ACK_COMMIT ,
SENT_REMOVE_ACK_COMMIT ,
@ -662,11 +697,15 @@ bool channel_rcvd_revoke_and_ack(struct channel *channel)
SENT_REMOVE_COMMIT } ;
SENT_REMOVE_COMMIT } ;
status_trace ( " received revoke_and_ack " ) ;
status_trace ( " received revoke_and_ack " ) ;
return change_htlcs ( channel , LOCAL , states , ARRAY_SIZE ( states ) ) ;
return change_htlcs ( channel , LOCAL , states , ARRAY_SIZE ( states ) ,
peer , oursfail , theirslocked , NULL ) ;
}
}
/* FIXME: We can actually merge these two... */
/* FIXME: We can actually merge these two... */
bool channel_rcvd_commit ( struct channel * channel )
bool channel_rcvd_commit ( struct channel * channel ,
struct peer * peer ,
void ( * theirsfulfilled ) ( struct peer * peer ,
const struct htlc * htlc ) )
{
{
const enum htlc_state states [ ] = { RCVD_ADD_REVOCATION ,
const enum htlc_state states [ ] = { RCVD_ADD_REVOCATION ,
RCVD_REMOVE_HTLC ,
RCVD_REMOVE_HTLC ,
@ -674,7 +713,8 @@ bool channel_rcvd_commit(struct channel *channel)
RCVD_REMOVE_REVOCATION } ;
RCVD_REMOVE_REVOCATION } ;
status_trace ( " received commit " ) ;
status_trace ( " received commit " ) ;
return change_htlcs ( channel , LOCAL , states , ARRAY_SIZE ( states ) ) ;
return change_htlcs ( channel , LOCAL , states , ARRAY_SIZE ( states ) ,
peer , NULL , NULL , theirsfulfilled ) ;
}
}
bool channel_sent_revoke_and_ack ( struct channel * channel )
bool channel_sent_revoke_and_ack ( struct channel * channel )
@ -684,7 +724,8 @@ bool channel_sent_revoke_and_ack(struct channel *channel)
RCVD_ADD_COMMIT ,
RCVD_ADD_COMMIT ,
RCVD_REMOVE_ACK_COMMIT } ;
RCVD_REMOVE_ACK_COMMIT } ;
status_trace ( " sent revoke_and_ack " ) ;
status_trace ( " sent revoke_and_ack " ) ;
return change_htlcs ( channel , REMOTE , states , ARRAY_SIZE ( states ) ) ;
return change_htlcs ( channel , REMOTE , states , ARRAY_SIZE ( states ) ,
NULL , NULL , NULL , NULL ) ;
}
}
static char * fmt_channel_view ( const tal_t * ctx , const struct channel_view * view )
static char * fmt_channel_view ( const tal_t * ctx , const struct channel_view * view )