github.com/decred/dcrlnd@v0.7.6/lnwallet/dcrlnd_features.go (about)

     1  package lnwallet
     2  
     3  import "strings"
     4  
     5  // ReasonsChannelUnclean returns a string with the reason(s) the channel is not
     6  // clean or an empty string if it is clean.
     7  func (lc *LightningChannel) ReasonsChannelUnclean() string {
     8  	lc.RLock()
     9  	defer lc.RUnlock()
    10  
    11  	var reasons []string
    12  
    13  	// Check whether we have a pending commitment for our local state.
    14  	if lc.localCommitChain.hasUnackedCommitment() {
    15  		reasons = append(reasons, "localChainHasUnackedCommit")
    16  	}
    17  
    18  	// Check whether our counterparty has a pending commitment for their
    19  	// state.
    20  	if lc.remoteCommitChain.hasUnackedCommitment() {
    21  		reasons = append(reasons, "remoteChainHasUnackedCommit")
    22  	}
    23  
    24  	// We call ActiveHtlcs to ensure there are no HTLCs on either
    25  	// commitment.
    26  	if len(lc.channelState.ActiveHtlcs()) != 0 {
    27  		reasons = append(reasons, "hasActiveHtlcs")
    28  	}
    29  
    30  	// Now check that both local and remote commitments are signing the
    31  	// same updates.
    32  	if lc.oweCommitment(true) {
    33  		reasons = append(reasons, "owedLocalCommit")
    34  	}
    35  
    36  	if lc.oweCommitment(false) {
    37  		reasons = append(reasons, "owesRemoteCommit")
    38  	}
    39  
    40  	// If we reached this point, the channel has no HTLCs and both
    41  	// commitments sign the same updates.
    42  	return strings.Join(reasons, ",")
    43  
    44  }