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 committed 2024-08-09 21:51:18 +08:00
1 parent 9801ee036b
commit aba8507b2a
3 files changed
+23 -10

No files matched your search

+1 -1
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 // We'll gather all of the information required by the UtxoSweeper in
// order to sweep the output. // order to sweep the output.
utxo, err := w.cfg.Wallet.FetchInputInfo(op) utxo, err := w.cfg.Wallet.FetchOutpointInfo(op)
if err != nil { if err != nil {
return err return err
} }
+19 -6
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 // 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 // own. If not, then we can't continue because our wallet state
// is out of sync. // is out of sync.
info, err := r.WalletController.FetchInputInfo( info, err := r.WalletController.FetchOutpointInfo(
&txIn.PreviousOutPoint, &txIn.PreviousOutPoint,
) )
if err != nil { 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 // 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 // to a coin we own. If we can't, then we'll continue as it
// isn't our input. // isn't our input.
utxo, err := r.FetchInputInfo(&txIn.PreviousOutPoint) utxo, err := r.FetchOutpointInfo(&txIn.PreviousOutPoint)
if err != nil { if err != nil {
continue continue
} }
@@ -906,7 +906,7 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
} }
txIn := tx.TxIn[idx] txIn := tx.TxIn[idx]
info, err := r.WalletController.FetchInputInfo( info, err := r.WalletController.FetchOutpointInfo(
&txIn.PreviousOutPoint, &txIn.PreviousOutPoint,
) )
if err != nil { if err != nil {
@@ -1015,19 +1015,32 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
signDesc.KeyDesc.PubKey = fullDesc.PubKey signDesc.KeyDesc.PubKey = fullDesc.PubKey
} }
var derivation *psbt.Bip32Derivation
// Make sure we actually know about the input. We either have been // 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 // watching the UTXO on-chain or we have been given all the required
// info in the sign descriptor. // 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 { 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: case err == nil:
in.WitnessUtxo = &wire.TxOut{ in.WitnessUtxo = &wire.TxOut{
Value: int64(info.Value), Value: int64(info.Value),
PkScript: info.PkScript, PkScript: info.PkScript,
} }
in.NonWitnessUtxo = info.PrevTx 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 // 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 // we haven't published yet (e.g. a channel funding TX). So we need to
+3 -3
View File
@@ -1646,7 +1646,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
[]*input.Script, 0, len(ourContribution.Inputs), []*input.Script, 0, len(ourContribution.Inputs),
) )
for _, txIn := range fundingTx.TxIn { for _, txIn := range fundingTx.TxIn {
_, err := l.FetchInputInfo(&txIn.PreviousOutPoint) _, err := l.FetchOutpointInfo(&txIn.PreviousOutPoint)
if err != nil { if err != nil {
continue 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, // its outpoint. If the coin isn't under the control of the backing CoinSource,
// then an error should be returned. // then an error should be returned.
func (c *CoinSource) CoinFromOutPoint(op wire.OutPoint) (*wallet.Coin, error) { 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 { if err != nil {
return nil, err 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 // passed outpoint. A nil value will be returned if the passed outpoint doesn't
// exist. // exist.
func (w *WalletPrevOutputFetcher) FetchPrevOutput(op wire.OutPoint) *wire.TxOut { func (w *WalletPrevOutputFetcher) FetchPrevOutput(op wire.OutPoint) *wire.TxOut {
utxo, err := w.wc.FetchInputInfo(&op) utxo, err := w.wc.FetchOutpointInfo(&op)
if err != nil { if err != nil {
return nil return nil
} }