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 committed 2024-03-13 09:50:16 -07:00
1 parent 07ba9d6015
commit 4d2ab7423f
8 files changed
+42 -31

No files matched your search

+2 -1
View File
@@ -22,6 +22,7 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@@ -1537,7 +1538,7 @@ func releaseOutput(ctx *cli.Context) error {
return fmt.Errorf("error parsing outpoint: %w", err) return fmt.Errorf("error parsing outpoint: %w", err)
} }
lockID := walletrpc.LndInternalLockID[:] lockID := chanfunding.LndInternalLockID[:]
lockIDStr := ctx.String("lockid") lockIDStr := ctx.String("lockid")
if lockIDStr != "" { if lockIDStr != "" {
var err error var err error
-4
View File
@@ -69,10 +69,6 @@ const (
// closure. // closure.
DefaultOutgoingCltvRejectDelta = DefaultOutgoingBroadcastDelta + 3 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 // DefaultZombieSweeperInterval is the default time interval at which
// unfinished (zombiestate) open channel flows are purged from memory. // unfinished (zombiestate) open channel flows are purged from memory.
DefaultZombieSweeperInterval = 1 * time.Minute DefaultZombieSweeperInterval = 1 * time.Minute
+3 -1
View File
@@ -4,6 +4,8 @@ package lncfg
import ( import (
"time" "time"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
) )
// IsDevBuild returns a bool to indicate whether we are in a development // 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`. // GetReservationTimeout returns the config value for `ReservationTimeout`.
func (d *DevConfig) GetReservationTimeout() time.Duration { func (d *DevConfig) GetReservationTimeout() time.Duration {
return DefaultReservationTimeout return chanfunding.DefaultReservationTimeout
} }
// GetZombieSweeperInterval returns the config value for`ZombieSweeperInterval`. // GetZombieSweeperInterval returns the config value for`ZombieSweeperInterval`.
+3 -1
View File
@@ -4,6 +4,8 @@ package lncfg
import ( import (
"time" "time"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
) )
// IsDevBuild returns a bool to indicate whether we are in a development // 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`. // GetReservationTimeout returns the config value for `ReservationTimeout`.
func (d *DevConfig) GetReservationTimeout() time.Duration { func (d *DevConfig) GetReservationTimeout() time.Duration {
if d.ReservationTimeout == 0 { if d.ReservationTimeout == 0 {
return DefaultReservationTimeout return chanfunding.DefaultReservationTimeout
} }
return d.ReservationTimeout return d.ReservationTimeout
+5 -9
View File
@@ -6,23 +6,18 @@ package walletrpc
import ( import (
"fmt" "fmt"
"math" "math"
"time"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
base "github.com/btcsuite/btcwallet/wallet" base "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/wtxmgr" "github.com/btcsuite/btcwallet/wtxmgr"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
) )
const ( const (
defaultMaxConf = math.MaxInt32 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 // verifyInputsUnspent checks that all inputs are contained in the list of
// known, non-locked UTXOs given. // known, non-locked UTXOs given.
func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error { func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
@@ -56,13 +51,14 @@ func lockInputs(w lnwallet.WalletController,
for idx := range outpoints { for idx := range outpoints {
lock := &base.ListLeasedOutputResult{ lock := &base.ListLeasedOutputResult{
LockedOutput: &wtxmgr.LockedOutput{ LockedOutput: &wtxmgr.LockedOutput{
LockID: LndInternalLockID, LockID: chanfunding.LndInternalLockID,
Outpoint: outpoints[idx], Outpoint: outpoints[idx],
}, },
} }
expiration, pkScript, value, err := w.LeaseOutput( expiration, pkScript, value, err := w.LeaseOutput(
lock.LockID, lock.Outpoint, DefaultLockDuration, lock.LockID, lock.Outpoint,
chanfunding.DefaultLockDuration,
) )
if err != nil { if err != nil {
// If we run into a problem with locking one output, we // 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++ { for i := 0; i < idx; i++ {
op := locks[i].Outpoint op := locks[i].Outpoint
if err := w.ReleaseOutput( if err := w.ReleaseOutput(
LndInternalLockID, op, chanfunding.LndInternalLockID, op,
); err != nil { ); err != nil {
log.Errorf("could not release the "+ log.Errorf("could not release the "+
"lock on %v: %v", op, err) "lock on %v: %v", op, err)
+2 -14
View File
@@ -184,18 +184,6 @@ var (
// configuration file in this package. // configuration file in this package.
DefaultWalletKitMacFilename = "walletkit.macaroon" 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 // allWitnessTypes is a mapping between the witness types defined in the
// `input` package, and the witness types in the protobuf definition. // `input` package, and the witness types in the protobuf definition.
// This map is necessary because the native enum and the protobuf enum // 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 // Don't allow our internal ID to be used externally for locking. Only
// unlocking is allowed. // unlocking is allowed.
if lockID == LndInternalLockID { if lockID == chanfunding.LndInternalLockID {
return nil, errors.New("reserved id cannot be used") 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. // Use the specified lock duration or fall back to the default.
duration := DefaultLockDuration duration := chanfunding.DefaultLockDuration
if req.ExpirationSeconds != 0 { if req.ExpirationSeconds != 0 {
duration = time.Duration(req.ExpirationSeconds) * time.Second duration = time.Duration(req.ExpirationSeconds) * time.Second
} }
+25
View File
@@ -3,6 +3,7 @@ package chanfunding
import ( import (
"fmt" "fmt"
"math" "math"
"time"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
@@ -10,10 +11,34 @@ import (
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
"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/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "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 // 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 // intent differs from the ShimIntent, in that the funding transaction will be
// constructed internally, and will consist of only inputs we wholly control. // constructed internally, and will consist of only inputs we wholly control.
+2 -1
View File
@@ -53,6 +53,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/lightningnetwork/lnd/lnwallet/rpcwallet" "github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/nat" "github.com/lightningnetwork/lnd/nat"
@@ -1276,7 +1277,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
// For the reservationTimeout and the zombieSweeperInterval different // For the reservationTimeout and the zombieSweeperInterval different
// values are set in case we are in a dev environment so enhance test // values are set in case we are in a dev environment so enhance test
// capacilities. // capacilities.
reservationTimeout := lncfg.DefaultReservationTimeout reservationTimeout := chanfunding.DefaultReservationTimeout
zombieSweeperInterval := lncfg.DefaultZombieSweeperInterval zombieSweeperInterval := lncfg.DefaultZombieSweeperInterval
// Get the development config for funding manager. If we are not in // Get the development config for funding manager. If we are not in