Closing

object Closing

Functions

btcAddressFromScriptPubKey
Link copied to clipboard
common
fun btcAddressFromScriptPubKey(scriptPubKey: ByteVector, chainHash: ByteVector32): String?
checkClosingDustAmounts
Link copied to clipboard
common

Check that all closing outputs are above bitcoin's dust limit for their script type, otherwise there is a risk that the closing transaction will not be relayed to miners' mempool and will not confirm. The various dust limits are detailed in https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#dust-limits

checkClosingSignature
Link copied to clipboard
common
fun checkClosingSignature(keyManager: KeyManager, commitments: Commitments, localScriptPubkey: ByteArray, remoteScriptPubkey: ByteArray, remoteClosingFee: Satoshi, remoteClosingSig: ByteVector64): Either<ChannelException, Pair<Transactions.TransactionWithInputInfo.ClosingTx, ClosingSigned>>
claimCurrentLocalCommitTxOutputs
Link copied to clipboard
common
fun claimCurrentLocalCommitTxOutputs(keyManager: KeyManager, commitments: Commitments, tx: Transaction, feerates: OnChainFeerates): LocalCommitPublished

Claim all the outputs that we've received from our current commit tx. This will be done using 2nd stage HTLC transactions.

claimRemoteCommitTxOutputs
Link copied to clipboard
common
fun claimRemoteCommitTxOutputs(keyManager: KeyManager, commitments: Commitments, remoteCommit: RemoteCommit, tx: Transaction, feerates: OnChainFeerates): RemoteCommitPublished

Claim all the outputs that we've received from their current commit tx.

claimRevokedHtlcTxOutputs
Link copied to clipboard
common
fun claimRevokedHtlcTxOutputs(keyManager: KeyManager, commitments: Commitments, revokedCommitPublished: RevokedCommitPublished, htlcTx: Transaction, feerates: OnChainFeerates): Pair<RevokedCommitPublished, List<Transactions.TransactionWithInputInfo.ClaimHtlcDelayedOutputPenaltyTx>>

Claims the output of an [HtlcSuccessTx] or [HtlcTimeoutTx] transaction using a revocation key.

claimRevokedRemoteCommitTxHtlcOutputs
Link copied to clipboard
common
fun claimRevokedRemoteCommitTxHtlcOutputs(keyManager: KeyManager, commitments: Commitments, revokedCommitPublished: RevokedCommitPublished, feerates: OnChainFeerates, htlcInfos: List<ChannelAction.Storage.HtlcInfo>): RevokedCommitPublished

Once we've fetched htlc information for a revoked commitment from the DB, we create penalty transactions to claim all htlc outputs.

claimRevokedRemoteCommitTxOutputs
Link copied to clipboard
common
fun claimRevokedRemoteCommitTxOutputs(keyManager: KeyManager, commitments: Commitments, tx: Transaction, feerates: OnChainFeerates): Pair<RevokedCommitPublished, Long>?

When an unexpected transaction spending the funding tx is detected:

extractPreimages
Link copied to clipboard
common
fun LocalCommit.extractPreimages(tx: Transaction): Set<Pair<UpdateAddHtlc, ByteVector32>>

In CLOSING state, any time we see a new transaction, we try to extract a preimage from it in order to fulfill the corresponding incoming htlc in an upstream channel.

firstClosingFee
Link copied to clipboard
common
fun firstClosingFee(commitments: Commitments, localScriptPubkey: ByteVector, remoteScriptPubkey: ByteVector, requestedFeerate: ClosingFeerates): ClosingFees
fun firstClosingFee(commitments: Commitments, localScriptPubkey: ByteArray, remoteScriptPubkey: ByteArray, requestedFeerate: ClosingFeerates): ClosingFees
inputsAlreadySpent
Link copied to clipboard
common
fun Transaction.inputsAlreadySpent(irrevocablySpent: Map<OutPoint, Transaction>): Boolean

This helper function tells if the utxos consumed by the given transaction has already been irrevocably spent (possibly by this very transaction)

isValidFinalScriptPubkey
Link copied to clipboard
common
fun isValidFinalScriptPubkey(scriptPubKey: ByteVector, allowAnySegwit: Boolean): Boolean
makeClosingTx
Link copied to clipboard
common
fun makeClosingTx(keyManager: KeyManager, commitments: Commitments, localScriptPubkey: ByteArray, remoteScriptPubkey: ByteArray, closingFees: ClosingFees): Pair<Transactions.TransactionWithInputInfo.ClosingTx, ClosingSigned>
makeFirstClosingTx
Link copied to clipboard
common
fun makeFirstClosingTx(keyManager: KeyManager, commitments: Commitments, localScriptPubkey: ByteArray, remoteScriptPubkey: ByteArray, requestedFeerate: ClosingFeerates): Pair<Transactions.TransactionWithInputInfo.ClosingTx, ClosingSigned>
nextClosingFee
Link copied to clipboard
common
fun nextClosingFee(localClosingFee: Satoshi, remoteClosingFee: Satoshi): Satoshi
onChainOutgoingHtlcs
Link copied to clipboard
common
fun onChainOutgoingHtlcs(localCommit: LocalCommit, remoteCommit: RemoteCommit, nextRemoteCommit_opt: RemoteCommit?, tx: Transaction): Set<UpdateAddHtlc>

As soon as a local or remote commitment reaches min_depth, we know which htlcs will be settled on-chain (whether or not they actually have an output in the commitment tx).

overriddenOutgoingHtlcs
Link copied to clipboard
common
fun overriddenOutgoingHtlcs(localCommit: LocalCommit, remoteCommit: RemoteCommit, nextRemoteCommit: RemoteCommit?, revokedCommitPublished: List<RevokedCommitPublished>, tx: Transaction): Set<UpdateAddHtlc>

If a commitment tx reaches min_depth, we need to fail the outgoing htlcs that will never reach the blockchain. It could be because only us had signed them, or because a revoked commitment got confirmed.

timedOutHtlcs
Link copied to clipboard
common
fun LocalCommit.timedOutHtlcs(localCommitPublished: LocalCommitPublished, localDustLimit: Satoshi, tx: Transaction): Set<UpdateAddHtlc>
fun RemoteCommit.timedOutHtlcs(remoteCommitPublished: RemoteCommitPublished, remoteDustLimit: Satoshi, tx: Transaction): Set<UpdateAddHtlc>

In CLOSING state, when we are notified that a transaction has been confirmed, we analyze it to find out if one or more htlcs have timed out and need to be failed in an upstream channel.