funding: remove dead code and sanity check pending chan ID (#7887)

* funding: remove unused field `newChanBarriers`

This commit removes the occurance of `newChanBarriers` as it's not used
anywhere.

* funding: rename method names to clear the funding flow

Slightly refactored the names so it's easier to see which side is
processing what messages.

* lnwallet: sanity check empty pending channel ID

This commit adds a sanity check to make sure an empty pending channel ID
will not be accepted.
This commit is contained in:
Yong
2023-10-09 16:58:18 +08:00
committed by GitHub
parent 80bfd17cf2
commit ec2377db79
4 changed files with 80 additions and 52 deletions

View File

@@ -62,6 +62,14 @@ var (
ErrReservedValueInvalidated = errors.New("reserved wallet balance " +
"invalidated: transaction would leave insufficient funds for " +
"fee bumping anchor channel closings (see debug log for details)")
// ErrEmptyPendingChanID is returned when an empty value is used for
// the pending channel ID.
ErrEmptyPendingChanID = errors.New("pending channel ID is empty")
// ErrDuplicatePendingChanID is returned when an existing pending
// channel ID is registered again.
ErrDuplicatePendingChanID = errors.New("duplicate pending channel ID")
)
// PsbtFundingRequired is a type that implements the error interface and
@@ -670,9 +678,15 @@ func (l *LightningWallet) RegisterFundingIntent(expectedID [32]byte,
l.intentMtx.Lock()
defer l.intentMtx.Unlock()
// Sanity check the pending channel ID is not empty.
var zeroID [32]byte
if expectedID == zeroID {
return ErrEmptyPendingChanID
}
if _, ok := l.fundingIntents[expectedID]; ok {
return fmt.Errorf("pendingChanID(%x) already has intent "+
"registered", expectedID[:])
return fmt.Errorf("%w: already has intent registered: %v",
ErrDuplicatePendingChanID, expectedID[:])
}
l.fundingIntents[expectedID] = shimIntent