Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ func (w *WalletKit) NextAddr(ctx context.Context,
case AddressType_HYBRID_NESTED_WITNESS_PUBKEY_HASH:
return nil, fmt.Errorf("invalid address type for next "+
"address: %v", req.Type)

case AddressType_TAPROOT_PUBKEY:
addrType = lnwallet.TaprootPubkey
}

addr, err := w.cfg.Wallet.NewAddress(addrType, req.Change, account)
Expand Down Expand Up @@ -858,24 +861,27 @@ func (w *WalletKit) BumpFee(ctx context.Context,
"transaction")
}

signDesc := &input.SignDescriptor{
Output: &wire.TxOut{
PkScript: utxo.PkScript,
Value: int64(utxo.Value),
},
HashType: txscript.SigHashAll,
}

var witnessType input.WitnessType
switch utxo.AddressType {
case lnwallet.WitnessPubKey:
witnessType = input.WitnessKeyHash
case lnwallet.NestedWitnessPubKey:
witnessType = input.NestedWitnessKeyHash
case lnwallet.TaprootPubkey:
witnessType = input.TaprootPubKeySpend
signDesc.HashType = txscript.SigHashDefault
default:
return nil, fmt.Errorf("unknown input witness %v", op)
}

signDesc := &input.SignDescriptor{
Output: &wire.TxOut{
PkScript: utxo.PkScript,
Value: int64(utxo.Value),
},
HashType: txscript.SigHashAll,
}

// We'll use the current height as the height hint since we're dealing
// with an unconfirmed transaction.
_, currentHeight, err := w.cfg.Chain.GetBestBlock()
Expand All @@ -884,8 +890,9 @@ func (w *WalletKit) BumpFee(ctx context.Context,
err)
}

input := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight))
if _, err = w.cfg.Sweeper.SweepInput(input, sweep.Params{Fee: feePreference}); err != nil {
inp := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight))
sweepParams := sweep.Params{Fee: feePreference}
if _, err = w.cfg.Sweeper.SweepInput(inp, sweepParams); err != nil {
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion lnwallet/rpcwallet/rpcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error {
// ones to sign. If there is any input without witness data that we
// cannot sign because it's not our UTXO, this will be a hard failure.
tx := packet.UnsignedTx
sigHashes := input.NewTxSigHashesV0Only(tx)
prevOutFetcher := basewallet.PsbtPrevOutputFetcher(packet)
sigHashes := txscript.NewTxSigHashes(tx, prevOutFetcher)
for idx, txIn := range tx.TxIn {
in := packet.Inputs[idx]

Expand Down
19 changes: 11 additions & 8 deletions sweep/tx_input_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,28 @@ func (t *txInputSet) tryAddWalletInputsIfNeeded() error {
// createWalletTxInput converts a wallet utxo into an object that can be added
// to the other inputs to sweep.
func createWalletTxInput(utxo *lnwallet.Utxo) (input.Input, error) {
signDesc := &input.SignDescriptor{
Output: &wire.TxOut{
PkScript: utxo.PkScript,
Value: int64(utxo.Value),
},
HashType: txscript.SigHashAll,
}

var witnessType input.WitnessType
switch utxo.AddressType {
case lnwallet.WitnessPubKey:
witnessType = input.WitnessKeyHash
case lnwallet.NestedWitnessPubKey:
witnessType = input.NestedWitnessKeyHash
case lnwallet.TaprootPubkey:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also make the default addresses for the sweeper P2TR as well?

So we'd change this argument here: https://github.com/lightningnetwork/lnd/blob/master/server.go#L4422-L4424

That'll also indirectly cause all on chain sweeps (force closes, etc) to go into P2TR addresses.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also be able to change this as well:

lnd/peer/brontide.go

Lines 2162 to 2175 in de6fcf1

// genDeliveryScript returns a new script to be used to send our funds to in
// the case of a cooperative channel close negotiation.
func (p *Brontide) genDeliveryScript() ([]byte, error) {
deliveryAddr, err := p.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false, lnwallet.DefaultAccountName,
)
if err != nil {
return nil, err
}
peerLog.Infof("Delivery addr for channel close: %v",
deliveryAddr)
return txscript.PayToAddrScript(deliveryAddr)
}
.

In practice we should always be using the upfront shutdown addr, but this should be safe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need to update this, so older nodes will accept a P2TR addr as an upfront shutdown script:

lnd/lnwallet/wallet.go

Lines 2247 to 2268 in dceb101

// validateUpfrontShutdown checks whether the provided upfront_shutdown_script
// is of a valid type that we accept.
func validateUpfrontShutdown(shutdown lnwire.DeliveryAddress,
params *chaincfg.Params) bool {
// We don't need to worry about a large UpfrontShutdownScript since it
// was already checked in lnwire when decoding from the wire.
scriptClass, _, _, _ := txscript.ExtractPkScriptAddrs(shutdown, params)
switch scriptClass {
case txscript.PubKeyHashTy,
txscript.WitnessV0PubKeyHashTy,
txscript.ScriptHashTy,
txscript.WitnessV0ScriptHashTy:
// The above four types are permitted according to BOLT#02.
// Everything else is disallowed.
return true
default:
return false
}
}

I think this means that we shouldn't yet switch over the default co-op close addr due to this stricter validation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re the above, here's where we generate our upfront shutdown addr:

lnd/funding/manager.go

Lines 1363 to 1375 in 262591c

shutdown, err := getUpfrontShutdownScript(
f.cfg.EnableUpfrontShutdown, peer, acceptorResp.UpfrontShutdown,
func() (lnwire.DeliveryAddress, error) {
addr, err := f.cfg.Wallet.NewAddress(
lnwallet.WitnessPubKey, false,
lnwallet.DefaultAccountName,
)
if err != nil {
return nil, err
}
return txscript.PayToAddrScript(addr)
},
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other areas that are safe to change:

witnessType = input.TaprootPubKeySpend
signDesc.HashType = txscript.SigHashDefault
default:
return nil, fmt.Errorf("unknown address type %v",
utxo.AddressType)
}

signDesc := &input.SignDescriptor{
Output: &wire.TxOut{
PkScript: utxo.PkScript,
Value: int64(utxo.Value),
},
HashType: txscript.SigHashAll,
}

// A height hint doesn't need to be set, because we don't monitor these
// inputs for spend.
heightHint := uint32(0)
Expand Down