mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-23 15:22:38 +02:00
chanfunding: use {Lease|Release}Output
not {Lock|Unlock}Outpoint
This commit is contained in:
parent
4d2ab7423f
commit
6ad86a800c
@ -1,9 +1,12 @@
|
|||||||
package chanfunding
|
package chanfunding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/wallet"
|
"github.com/btcsuite/btcwallet/wallet"
|
||||||
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,18 +37,18 @@ type CoinSelectionLocker interface {
|
|||||||
WithCoinSelectLock(func() error) error
|
WithCoinSelectLock(func() error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutpointLocker allows a caller to lock/unlock an outpoint. When locked, the
|
// OutputLeaser allows a caller to lease/release an output. When leased, the
|
||||||
// outpoints shouldn't be used for any sort of channel funding of coin
|
// outputs shouldn't be used for any sort of channel funding or coin selection.
|
||||||
// selection. Locked outpoints are not expected to be persisted between
|
// Leased outputs are expected to be persisted between restarts.
|
||||||
// restarts.
|
type OutputLeaser interface {
|
||||||
type OutpointLocker interface {
|
// LeaseOutput leases a target output, rendering it unusable for coin
|
||||||
// LockOutpoint locks a target outpoint, rendering it unusable for coin
|
|
||||||
// selection.
|
// selection.
|
||||||
LockOutpoint(o wire.OutPoint)
|
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
|
||||||
|
time.Time, []byte, btcutil.Amount, error)
|
||||||
|
|
||||||
// UnlockOutpoint unlocks a target outpoint, allowing it to be used for
|
// ReleaseOutput releases a target output, allowing it to be used for
|
||||||
// coin selection once again.
|
// coin selection once again.
|
||||||
UnlockOutpoint(o wire.OutPoint)
|
ReleaseOutput(i wtxmgr.LockID, o wire.OutPoint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request is a new request for funding a channel. The items in the struct
|
// Request is a new request for funding a channel. The items in the struct
|
||||||
|
@ -62,9 +62,9 @@ type FullIntent struct {
|
|||||||
// change from the main funding transaction.
|
// change from the main funding transaction.
|
||||||
ChangeOutputs []*wire.TxOut
|
ChangeOutputs []*wire.TxOut
|
||||||
|
|
||||||
// coinLocker is the Assembler's instance of the OutpointLocker
|
// coinLeaser is the Assembler's instance of the OutputLeaser
|
||||||
// interface.
|
// interface.
|
||||||
coinLocker OutpointLocker
|
coinLeaser OutputLeaser
|
||||||
|
|
||||||
// coinSource is the Assembler's instance of the CoinSource interface.
|
// coinSource is the Assembler's instance of the CoinSource interface.
|
||||||
coinSource CoinSource
|
coinSource CoinSource
|
||||||
@ -219,7 +219,13 @@ func (f *FullIntent) Outputs() []*wire.TxOut {
|
|||||||
// NOTE: Part of the chanfunding.Intent interface.
|
// NOTE: Part of the chanfunding.Intent interface.
|
||||||
func (f *FullIntent) Cancel() {
|
func (f *FullIntent) Cancel() {
|
||||||
for _, coin := range f.InputCoins {
|
for _, coin := range f.InputCoins {
|
||||||
f.coinLocker.UnlockOutpoint(coin.OutPoint)
|
err := f.coinLeaser.ReleaseOutput(
|
||||||
|
LndInternalLockID, coin.OutPoint,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Failed to release UTXO %s (%v))",
|
||||||
|
coin.OutPoint, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.ShimIntent.Cancel()
|
f.ShimIntent.Cancel()
|
||||||
@ -241,9 +247,9 @@ type WalletConfig struct {
|
|||||||
// access to the current set of coins returned by the CoinSource.
|
// access to the current set of coins returned by the CoinSource.
|
||||||
CoinSelectLocker CoinSelectionLocker
|
CoinSelectLocker CoinSelectionLocker
|
||||||
|
|
||||||
// CoinLocker is what the WalletAssembler uses to lock coins that may
|
// CoinLeaser is what the WalletAssembler uses to lease coins that may
|
||||||
// be used as inputs for a new funding transaction.
|
// be used as inputs for a new funding transaction.
|
||||||
CoinLocker OutpointLocker
|
CoinLeaser OutputLeaser
|
||||||
|
|
||||||
// Signer allows the WalletAssembler to sign inputs on any potential
|
// Signer allows the WalletAssembler to sign inputs on any potential
|
||||||
// funding transactions.
|
// funding transactions.
|
||||||
@ -518,7 +524,13 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
|
|||||||
for _, coin := range selectedCoins {
|
for _, coin := range selectedCoins {
|
||||||
outpoint := coin.OutPoint
|
outpoint := coin.OutPoint
|
||||||
|
|
||||||
w.cfg.CoinLocker.LockOutpoint(outpoint)
|
_, _, _, err = w.cfg.CoinLeaser.LeaseOutput(
|
||||||
|
LndInternalLockID, outpoint,
|
||||||
|
DefaultReservationTimeout,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newIntent := &FullIntent{
|
newIntent := &FullIntent{
|
||||||
@ -528,7 +540,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
|
|||||||
musig2: r.Musig2,
|
musig2: r.Musig2,
|
||||||
},
|
},
|
||||||
InputCoins: selectedCoins,
|
InputCoins: selectedCoins,
|
||||||
coinLocker: w.cfg.CoinLocker,
|
coinLeaser: w.cfg.CoinLeaser,
|
||||||
coinSource: w.cfg.CoinSource,
|
coinSource: w.cfg.CoinSource,
|
||||||
signer: w.cfg.Signer,
|
signer: w.cfg.Signer,
|
||||||
}
|
}
|
||||||
|
@ -2990,7 +2990,7 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
|||||||
chanfunding.WalletConfig{
|
chanfunding.WalletConfig{
|
||||||
CoinSource: lnwallet.NewCoinSource(alice),
|
CoinSource: lnwallet.NewCoinSource(alice),
|
||||||
CoinSelectLocker: alice,
|
CoinSelectLocker: alice,
|
||||||
CoinLocker: alice,
|
CoinLeaser: alice,
|
||||||
Signer: alice.Cfg.Signer,
|
Signer: alice.Cfg.Signer,
|
||||||
DustLimit: 600,
|
DustLimit: 600,
|
||||||
CoinSelectionStrategy: wallet.CoinSelectionLargest,
|
CoinSelectionStrategy: wallet.CoinSelectionLargest,
|
||||||
|
@ -851,7 +851,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
|||||||
cfg := chanfunding.WalletConfig{
|
cfg := chanfunding.WalletConfig{
|
||||||
CoinSource: &CoinSource{l},
|
CoinSource: &CoinSource{l},
|
||||||
CoinSelectLocker: l,
|
CoinSelectLocker: l,
|
||||||
CoinLocker: l,
|
CoinLeaser: l,
|
||||||
Signer: l.Cfg.Signer,
|
Signer: l.Cfg.Signer,
|
||||||
DustLimit: DustLimitForSize(
|
DustLimit: DustLimitForSize(
|
||||||
input.P2WSHSize,
|
input.P2WSHSize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user