multi: move 3 vars from walletrpc+lncfg to chanfunding

This commit moves the constants LndInternalLockID and
DefaultLockDuration from the walletrpc package to the chanfunding
package, moves DefaultReservationTimeout from lncfg to chanfunding,
and also updates the lncli package with the new location.
This commit is contained in:
Alex Akselrod 2024-02-21 13:20:19 -08:00
parent 07ba9d6015
commit 4d2ab7423f
No known key found for this signature in database
GPG Key ID: 57D7612D178AA487
8 changed files with 42 additions and 31 deletions

View File

@ -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

View File

@ -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

View File

@ -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`.

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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.

View File

@ -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