@ -284,18 +284,18 @@ void add_peer(struct lightningd *ld, u64 unique_id,
peer - > ld = ld ;
peer - > ld = ld ;
peer - > unique_id = unique_id ;
peer - > unique_id = unique_id ;
peer - > owner = NULL ;
peer - > owner = NULL ;
peer - > scid = NULL ;
peer - > id = * id ;
peer - > id = * id ;
peer - > fd = fd ;
peer - > fd = fd ;
peer - > reconnected = false ;
peer - > reconnected = false ;
peer - > gossip_client_fd = - 1 ;
peer - > gossip_client_fd = - 1 ;
peer - > cs = tal_dup ( peer , struct crypto_state , cs ) ;
peer - > cs = tal_dup ( peer , struct crypto_state , cs ) ;
peer - > funding_txid = NULL ;
peer - > funding_txid = NULL ;
peer - > remote_funding_locked = false ;
peer - > scid = NULL ;
peer - > seed = NULL ;
peer - > seed = NULL ;
peer - > balance = NULL ;
peer - > balance = NULL ;
peer - > state = UNINITIALIZED ;
peer - > state = UNINITIALIZED ;
peer - > channel_info = NULL ;
peer - > channel_info = NULL ;
peer - > next_per_commitment_point = NULL ;
peer - > last_was_revoke = false ;
peer - > last_was_revoke = false ;
peer - > last_sent_commit = NULL ;
peer - > last_sent_commit = NULL ;
peer - > num_commits_sent = peer - > num_commits_received
peer - > num_commits_sent = peer - > num_commits_received
@ -859,12 +859,14 @@ static int peer_got_funding_locked(struct peer *peer, const u8 *msg)
return - 1 ;
return - 1 ;
}
}
/* In case of re-transmit. */
if ( peer - > remote_funding_locked ) {
peer - > next_per_commitment_point
log_broken ( peer - > log , " channel_got_funding_locked twice " ) ;
= tal_free ( peer - > next_per_commitment_point ) ;
return - 1 ;
peer - > next_per_commitment_point
}
= tal_dup ( peer , struct pubkey , & next_per_commitment_point ) ;
update_per_commit_point ( peer , & next_per_commitment_point ) ;
log_debug ( peer - > log , " Got funding_locked " ) ;
log_debug ( peer - > log , " Got funding_locked " ) ;
peer - > remote_funding_locked = true ;
return 0 ;
return 0 ;
}
}
@ -953,7 +955,7 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
if ( peer - > scid ) {
if ( peer - > scid ) {
funding_channel_id = * peer - > scid ;
funding_channel_id = * peer - > scid ;
log_debug ( peer - > log , " Got funding confirmations " ) ;
log_debug ( peer - > log , " Already have funding locked in " ) ;
peer_set_condition ( peer , GETTING_HSMFD , CHANNELD_NORMAL ) ;
peer_set_condition ( peer , GETTING_HSMFD , CHANNELD_NORMAL ) ;
} else {
} else {
log_debug ( peer - > log , " Waiting for funding confirmations " ) ;
log_debug ( peer - > log , " Waiting for funding confirmations " ) ;
@ -974,7 +976,8 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
& peer - > channel_info - > theirbase . revocation ,
& peer - > channel_info - > theirbase . revocation ,
& peer - > channel_info - > theirbase . payment ,
& peer - > channel_info - > theirbase . payment ,
& peer - > channel_info - > theirbase . delayed_payment ,
& peer - > channel_info - > theirbase . delayed_payment ,
& peer - > channel_info - > their_per_commit_point ,
& peer - > channel_info - > remote_per_commit ,
& peer - > channel_info - > old_remote_per_commit ,
peer - > funder = = LOCAL ,
peer - > funder = = LOCAL ,
cfg - > fee_base ,
cfg - > fee_base ,
cfg - > fee_per_satoshi ,
cfg - > fee_per_satoshi ,
@ -994,7 +997,7 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
fulfilled_htlcs , fulfilled_sides ,
fulfilled_htlcs , fulfilled_sides ,
failed_htlcs , failed_sides ,
failed_htlcs , failed_sides ,
peer - > scid ! = NULL ,
peer - > scid ! = NULL ,
peer - > next_per_commitment_point ! = NULL ,
peer - > remote_funding_locked ,
& funding_channel_id ,
& funding_channel_id ,
peer - > reconnected ,
peer - > reconnected ,
peer - > funding_signed ) ;
peer - > funding_signed ) ;
@ -1064,7 +1067,7 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
& channel_info - > theirbase . revocation ,
& channel_info - > theirbase . revocation ,
& channel_info - > theirbase . payment ,
& channel_info - > theirbase . payment ,
& channel_info - > theirbase . delayed_payment ,
& channel_info - > theirbase . delayed_payment ,
& channel_info - > th eir _per_commit_poin t ,
& channel_info - > remo te_per_commit,
& fc - > peer - > minimum_depth ,
& fc - > peer - > minimum_depth ,
& channel_info - > remote_fundingkey ,
& channel_info - > remote_fundingkey ,
& funding_txid ) ) {
& funding_txid ) ) {
@ -1074,6 +1077,9 @@ static bool opening_funder_finished(struct subd *opening, const u8 *resp,
return false ;
return false ;
}
}
/* old_remote_per_commit not valid yet, copy valid one. */
channel_info - > old_remote_per_commit = channel_info - > remote_per_commit ;
/* Generate the funding tx. */
/* Generate the funding tx. */
if ( fc - > change
if ( fc - > change
& & ! bip32_pubkey ( fc - > peer - > ld - > bip32_base ,
& & ! bip32_pubkey ( fc - > peer - > ld - > bip32_base ,
@ -1145,7 +1151,6 @@ static bool opening_fundee_finished(struct subd *opening,
/* At this point, we care about peer */
/* At this point, we care about peer */
peer - > channel_info = channel_info = tal ( peer , struct channel_info ) ;
peer - > channel_info = channel_info = tal ( peer , struct channel_info ) ;
peer - > funding_txid = tal ( peer , struct sha256_double ) ;
peer - > funding_txid = tal ( peer , struct sha256_double ) ;
if ( ! fromwire_opening_fundee_reply ( peer , reply , NULL ,
if ( ! fromwire_opening_fundee_reply ( peer , reply , NULL ,
& channel_info - > their_config ,
& channel_info - > their_config ,
@ -1154,7 +1159,7 @@ static bool opening_fundee_finished(struct subd *opening,
& channel_info - > theirbase . revocation ,
& channel_info - > theirbase . revocation ,
& channel_info - > theirbase . payment ,
& channel_info - > theirbase . payment ,
& channel_info - > theirbase . delayed_payment ,
& channel_info - > theirbase . delayed_payment ,
& channel_info - > th eir _per_commit_poin t ,
& channel_info - > remo te_per_commit,
& channel_info - > remote_fundingkey ,
& channel_info - > remote_fundingkey ,
peer - > funding_txid ,
peer - > funding_txid ,
& peer - > funding_outnum ,
& peer - > funding_outnum ,
@ -1165,6 +1170,8 @@ static bool opening_fundee_finished(struct subd *opening,
tal_hex ( reply , reply ) ) ;
tal_hex ( reply , reply ) ) ;
return false ;
return false ;
}
}
/* old_remote_per_commit not valid yet, copy valid one. */
channel_info - > old_remote_per_commit = channel_info - > remote_per_commit ;
/* We should have sent and received the first commitsig */
/* We should have sent and received the first commitsig */
if ( ! peer_save_commitsig_received ( peer , 0 )
if ( ! peer_save_commitsig_received ( peer , 0 )