diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index f09560169..3e01ecf14 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -22,6 +22,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc" + "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/urfave/cli" ) @@ -1537,7 +1538,7 @@ func releaseOutput(ctx *cli.Context) error { return fmt.Errorf("error parsing outpoint: %w", err) } - lockID := walletrpc.LndInternalLockID[:] + lockID := chanfunding.LndInternalLockID[:] lockIDStr := ctx.String("lockid") if lockIDStr != "" { var err error diff --git a/lncfg/config.go b/lncfg/config.go index 07c37875d..889b327f6 100644 --- a/lncfg/config.go +++ b/lncfg/config.go @@ -69,10 +69,6 @@ const ( // closure. DefaultOutgoingCltvRejectDelta = DefaultOutgoingBroadcastDelta + 3 - // DefaultReservationTimeout is the default time we wait until we remove - // an unfinished (zombiestate) open channel flow from memory. - DefaultReservationTimeout = 10 * time.Minute - // DefaultZombieSweeperInterval is the default time interval at which // unfinished (zombiestate) open channel flows are purged from memory. DefaultZombieSweeperInterval = 1 * time.Minute diff --git a/lncfg/dev.go b/lncfg/dev.go index 7eb295824..0c887457f 100644 --- a/lncfg/dev.go +++ b/lncfg/dev.go @@ -4,6 +4,8 @@ package lncfg import ( "time" + + "github.com/lightningnetwork/lnd/lnwallet/chanfunding" ) // IsDevBuild returns a bool to indicate whether we are in a development @@ -37,7 +39,7 @@ func (d *DevConfig) GetUnsafeDisconnect() bool { // GetReservationTimeout returns the config value for `ReservationTimeout`. func (d *DevConfig) GetReservationTimeout() time.Duration { - return DefaultReservationTimeout + return chanfunding.DefaultReservationTimeout } // GetZombieSweeperInterval returns the config value for`ZombieSweeperInterval`. diff --git a/lncfg/dev_integration.go b/lncfg/dev_integration.go index 86a4af275..0f0227e01 100644 --- a/lncfg/dev_integration.go +++ b/lncfg/dev_integration.go @@ -4,6 +4,8 @@ package lncfg import ( "time" + + "github.com/lightningnetwork/lnd/lnwallet/chanfunding" ) // IsDevBuild returns a bool to indicate whether we are in a development @@ -33,7 +35,7 @@ func (d *DevConfig) ChannelReadyWait() time.Duration { // GetReservationTimeout returns the config value for `ReservationTimeout`. func (d *DevConfig) GetReservationTimeout() time.Duration { if d.ReservationTimeout == 0 { - return DefaultReservationTimeout + return chanfunding.DefaultReservationTimeout } return d.ReservationTimeout diff --git a/lnrpc/walletrpc/psbt.go b/lnrpc/walletrpc/psbt.go index b05d75054..19b102473 100644 --- a/lnrpc/walletrpc/psbt.go +++ b/lnrpc/walletrpc/psbt.go @@ -6,23 +6,18 @@ package walletrpc import ( "fmt" "math" - "time" "github.com/btcsuite/btcd/wire" base "github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wtxmgr" "github.com/lightningnetwork/lnd/lnwallet" + "github.com/lightningnetwork/lnd/lnwallet/chanfunding" ) const ( defaultMaxConf = math.MaxInt32 ) -var ( - // DefaultLockDuration is the default duration used to lock outputs. - DefaultLockDuration = 10 * time.Minute -) - // verifyInputsUnspent checks that all inputs are contained in the list of // known, non-locked UTXOs given. func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error { @@ -56,13 +51,14 @@ func lockInputs(w lnwallet.WalletController, for idx := range outpoints { lock := &base.ListLeasedOutputResult{ LockedOutput: &wtxmgr.LockedOutput{ - LockID: LndInternalLockID, + LockID: chanfunding.LndInternalLockID, Outpoint: outpoints[idx], }, } expiration, pkScript, value, err := w.LeaseOutput( - lock.LockID, lock.Outpoint, DefaultLockDuration, + lock.LockID, lock.Outpoint, + chanfunding.DefaultLockDuration, ) if err != nil { // If we run into a problem with locking one output, we @@ -72,7 +68,7 @@ func lockInputs(w lnwallet.WalletController, for i := 0; i < idx; i++ { op := locks[i].Outpoint if err := w.ReleaseOutput( - LndInternalLockID, op, + chanfunding.LndInternalLockID, op, ); err != nil { log.Errorf("could not release the "+ "lock on %v: %v", op, err) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 3e71070aa..79cc3e78e 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -184,18 +184,6 @@ var ( // configuration file in this package. DefaultWalletKitMacFilename = "walletkit.macaroon" - // LndInternalLockID is the binary representation of the SHA256 hash of - // the string "lnd-internal-lock-id" and is used for UTXO lock leases to - // identify that we ourselves are locking an UTXO, for example when - // giving out a funded PSBT. The ID corresponds to the hex value of - // ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98. - LndInternalLockID = wtxmgr.LockID{ - 0xed, 0xe1, 0x9a, 0x92, 0xed, 0x32, 0x1a, 0x47, - 0x05, 0xf8, 0xa1, 0xcc, 0xcc, 0x1d, 0x4f, 0x61, - 0x82, 0x54, 0x5d, 0x4b, 0xb4, 0xfa, 0xe0, 0x8b, - 0xd5, 0x93, 0x78, 0x31, 0xb7, 0xe3, 0x8f, 0x98, - } - // allWitnessTypes is a mapping between the witness types defined in the // `input` package, and the witness types in the protobuf definition. // This map is necessary because the native enum and the protobuf enum @@ -482,7 +470,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context, // Don't allow our internal ID to be used externally for locking. Only // unlocking is allowed. - if lockID == LndInternalLockID { + if lockID == chanfunding.LndInternalLockID { return nil, errors.New("reserved id cannot be used") } @@ -492,7 +480,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context, } // Use the specified lock duration or fall back to the default. - duration := DefaultLockDuration + duration := chanfunding.DefaultLockDuration if req.ExpirationSeconds != 0 { duration = time.Duration(req.ExpirationSeconds) * time.Second } diff --git a/lnwallet/chanfunding/wallet_assembler.go b/lnwallet/chanfunding/wallet_assembler.go index 651bc5558..062fd2328 100644 --- a/lnwallet/chanfunding/wallet_assembler.go +++ b/lnwallet/chanfunding/wallet_assembler.go @@ -3,6 +3,7 @@ package chanfunding import ( "fmt" "math" + "time" "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcutil" @@ -10,10 +11,34 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/wallet" + "github.com/btcsuite/btcwallet/wtxmgr" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" ) +const ( + // DefaultReservationTimeout is the default time we wait until we remove + // an unfinished (zombiestate) open channel flow from memory. + DefaultReservationTimeout = 10 * time.Minute + + // DefaultLockDuration is the default duration used to lock outputs. + DefaultLockDuration = 10 * time.Minute +) + +var ( + // LndInternalLockID is the binary representation of the SHA256 hash of + // the string "lnd-internal-lock-id" and is used for UTXO lock leases to + // identify that we ourselves are locking an UTXO, for example when + // giving out a funded PSBT. The ID corresponds to the hex value of + // ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98. + LndInternalLockID = wtxmgr.LockID{ + 0xed, 0xe1, 0x9a, 0x92, 0xed, 0x32, 0x1a, 0x47, + 0x05, 0xf8, 0xa1, 0xcc, 0xcc, 0x1d, 0x4f, 0x61, + 0x82, 0x54, 0x5d, 0x4b, 0xb4, 0xfa, 0xe0, 0x8b, + 0xd5, 0x93, 0x78, 0x31, 0xb7, 0xe3, 0x8f, 0x98, + } +) + // FullIntent is an intent that is fully backed by the internal wallet. This // intent differs from the ShimIntent, in that the funding transaction will be // constructed internally, and will consist of only inputs we wholly control. diff --git a/server.go b/server.go index cb1540a2c..938221887 100644 --- a/server.go +++ b/server.go @@ -53,6 +53,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" + "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/lightningnetwork/lnd/lnwallet/rpcwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/nat" @@ -1276,7 +1277,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, // For the reservationTimeout and the zombieSweeperInterval different // values are set in case we are in a dev environment so enhance test // capacilities. - reservationTimeout := lncfg.DefaultReservationTimeout + reservationTimeout := chanfunding.DefaultReservationTimeout zombieSweeperInterval := lncfg.DefaultZombieSweeperInterval // Get the development config for funding manager. If we are not in