Skip to content

Commit

Permalink
multi: move 3 vars from walletrpc+lncfg to chanfunding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aakselrod committed Mar 13, 2024
1 parent 07ba9d6 commit 4d2ab74
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lncfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lncfg/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
Expand Down
4 changes: 3 additions & 1 deletion lncfg/dev_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions lnrpc/walletrpc/psbt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 2 additions & 14 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand All @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions lnwallet/chanfunding/wallet_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,42 @@ package chanfunding
import (
"fmt"
"math"
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/txsort"
"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.
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d2ab74

Please sign in to comment.