1
0
Fork 0
mirror of https://github.com/lightningnetwork/lnd.git synced 2025-03-13 11:09:23 +01:00

lnrpc+lnwallet: replace FetchInputInfo with new methods

This commit replaces the usage of `FetchInputInfo` with
`FetchOutpointInfo` and `FetchDerivationInfo` to remove unncessary
fetching of the derivation path.
This commit is contained in:
yyforyongyu 2024-08-08 21:53:27 +08:00
parent 9801ee036b
commit aba8507b2a
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
3 changed files with 23 additions and 10 deletions
lnrpc/walletrpc
lnwallet

View file

@ -1142,7 +1142,7 @@ func (w *WalletKit) sweepNewInput(op *wire.OutPoint, currentHeight uint32,
//
// We'll gather all of the information required by the UtxoSweeper in
// order to sweep the output.
utxo, err := w.cfg.Wallet.FetchInputInfo(op)
utxo, err := w.cfg.Wallet.FetchOutpointInfo(op)
if err != nil {
return err
}

View file

@ -154,7 +154,7 @@ func (r *RPCKeyRing) SendOutputs(inputs fn.Set[wire.OutPoint],
// watch-only wallet if it can map this outpoint into a coin we
// own. If not, then we can't continue because our wallet state
// is out of sync.
info, err := r.WalletController.FetchInputInfo(
info, err := r.WalletController.FetchOutpointInfo(
&txIn.PreviousOutPoint,
)
if err != nil {
@ -289,7 +289,7 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error {
// We can only sign this input if it's ours, so we try to map it
// to a coin we own. If we can't, then we'll continue as it
// isn't our input.
utxo, err := r.FetchInputInfo(&txIn.PreviousOutPoint)
utxo, err := r.FetchOutpointInfo(&txIn.PreviousOutPoint)
if err != nil {
continue
}
@ -906,7 +906,7 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
}
txIn := tx.TxIn[idx]
info, err := r.WalletController.FetchInputInfo(
info, err := r.WalletController.FetchOutpointInfo(
&txIn.PreviousOutPoint,
)
if err != nil {
@ -1015,19 +1015,32 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
signDesc.KeyDesc.PubKey = fullDesc.PubKey
}
var derivation *psbt.Bip32Derivation
// Make sure we actually know about the input. We either have been
// watching the UTXO on-chain or we have been given all the required
// info in the sign descriptor.
info, err := r.WalletController.FetchInputInfo(&txIn.PreviousOutPoint)
info, err := r.WalletController.FetchOutpointInfo(
&txIn.PreviousOutPoint,
)
// If the wallet is aware of this outpoint, we go ahead and fetch the
// derivation info.
if err == nil {
derivation, err = r.WalletController.FetchDerivationInfo(
info.PkScript,
)
}
switch {
// No error, we do have the full UTXO and derivation info available.
// No error, we do have the full UTXO info available.
case err == nil:
in.WitnessUtxo = &wire.TxOut{
Value: int64(info.Value),
PkScript: info.PkScript,
}
in.NonWitnessUtxo = info.PrevTx
in.Bip32Derivation = []*psbt.Bip32Derivation{info.Derivation}
in.Bip32Derivation = []*psbt.Bip32Derivation{derivation}
// The wallet doesn't know about this UTXO, so it's probably a TX that
// we haven't published yet (e.g. a channel funding TX). So we need to

View file

@ -1646,7 +1646,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
[]*input.Script, 0, len(ourContribution.Inputs),
)
for _, txIn := range fundingTx.TxIn {
_, err := l.FetchInputInfo(&txIn.PreviousOutPoint)
_, err := l.FetchOutpointInfo(&txIn.PreviousOutPoint)
if err != nil {
continue
}
@ -2592,7 +2592,7 @@ func (c *CoinSource) ListCoins(minConfs int32,
// its outpoint. If the coin isn't under the control of the backing CoinSource,
// then an error should be returned.
func (c *CoinSource) CoinFromOutPoint(op wire.OutPoint) (*wallet.Coin, error) {
inputInfo, err := c.wallet.FetchInputInfo(&op)
inputInfo, err := c.wallet.FetchOutpointInfo(&op)
if err != nil {
return nil, err
}
@ -2689,7 +2689,7 @@ func NewWalletPrevOutputFetcher(wc WalletController) *WalletPrevOutputFetcher {
// passed outpoint. A nil value will be returned if the passed outpoint doesn't
// exist.
func (w *WalletPrevOutputFetcher) FetchPrevOutput(op wire.OutPoint) *wire.TxOut {
utxo, err := w.wc.FetchInputInfo(&op)
utxo, err := w.wc.FetchOutpointInfo(&op)
if err != nil {
return nil
}