From 7b186716a18a96bed3dcf24e694b98c67ceeebfc Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 21 Apr 2023 14:51:56 +0200 Subject: [PATCH] multi: populate both string and byte TXID in lnrpc.Outpoint This commit adds a a new `MarshalOutPoint` helper in the `lnrpc` package that can be used to convert a `wire.Outpoint` to an `lnrpc.Outpoint`. By using this helper, we are less likely to forget to populate both the string and byte form of the TXID. --- docs/release-notes/release-notes-0.17.0.md | 5 +++++ funding/batch.go | 1 + lnrpc/marshall_utils.go | 16 +++++++++++----- lnrpc/walletrpc/walletkit_server.go | 13 +++---------- routing/localchans/manager.go | 6 +----- rpcserver.go | 6 +----- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/docs/release-notes/release-notes-0.17.0.md b/docs/release-notes/release-notes-0.17.0.md index 43f9a4e90..284ce44fd 100644 --- a/docs/release-notes/release-notes-0.17.0.md +++ b/docs/release-notes/release-notes-0.17.0.md @@ -12,6 +12,11 @@ wtdb.BackupIDs](https://github.com/lightningnetwork/lnd/pull/7623) instead of the entire retribution struct. This reduces the amount of data that needs to be held in memory. + +## Misc + +* [Ensure that both the byte and string form of a TXID is populated in the + lnrpc.Outpoint message](https://github.com/lightningnetwork/lnd/pull/7624). # Contributors (Alphabetical Order) diff --git a/funding/batch.go b/funding/batch.go index 3b18a7b5d..6769858ed 100644 --- a/funding/batch.go +++ b/funding/batch.go @@ -490,6 +490,7 @@ func (b *Batcher) cleanup(ctx context.Context) { rpcOP := &lnrpc.OutPoint{ OutputIndex: lockedUTXO.Outpoint.OutputIndex, TxidBytes: lockedUTXO.Outpoint.TxidBytes, + TxidStr: lockedUTXO.Outpoint.TxidStr, } _, err := b.cfg.WalletKitServer.ReleaseOutput( ctx, &walletrpc.ReleaseOutputRequest{ diff --git a/lnrpc/marshall_utils.go b/lnrpc/marshall_utils.go index bdd8a00f0..8f307f6cf 100644 --- a/lnrpc/marshall_utils.go +++ b/lnrpc/marshall_utils.go @@ -8,6 +8,7 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" + "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" ) @@ -106,11 +107,7 @@ func MarshalUtxos(utxos []*lnwallet.Utxo, activeNetParams *chaincfg.Params) ( // Now that we know we have a proper mapping to an address, // we'll convert the regular outpoint to an lnrpc variant. - outpoint := &OutPoint{ - TxidBytes: utxo.OutPoint.Hash[:], - TxidStr: utxo.OutPoint.Hash.String(), - OutputIndex: utxo.OutPoint.Index, - } + outpoint := MarshalOutPoint(&utxo.OutPoint) utxoResp := Utxo{ AddressType: addrType, @@ -173,3 +170,12 @@ func MarshallOutputType(o txscript.ScriptClass) OutputScriptType { return OutputScriptType_SCRIPT_TYPE_PUBKEY_HASH } } + +// MarshalOutPoint converts a wire.OutPoint to its proto counterpart. +func MarshalOutPoint(op *wire.OutPoint) *OutPoint { + return &OutPoint{ + TxidBytes: op.Hash[:], + TxidStr: op.Hash.String(), + OutputIndex: op.Index, + } +} diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 287572dd0..bce1f65f5 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -756,10 +756,7 @@ func (w *WalletKit) PendingSweeps(ctx context.Context, pendingInput.OutPoint) } - op := &lnrpc.OutPoint{ - TxidBytes: pendingInput.OutPoint.Hash[:], - OutputIndex: pendingInput.OutPoint.Index, - } + op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint) amountSat := uint32(pendingInput.Amount) satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerKVByte() / 1000) broadcastAttempts := uint32(pendingInput.BroadcastAttempts) @@ -1241,12 +1238,8 @@ func marshallLeases(locks []*base.ListLeasedOutputResult) []*UtxoLease { lock := lock rpcLocks[idx] = &UtxoLease{ - Id: lock.LockID[:], - Outpoint: &lnrpc.OutPoint{ - TxidBytes: lock.Outpoint.Hash[:], - TxidStr: lock.Outpoint.Hash.String(), - OutputIndex: lock.Outpoint.Index, - }, + Id: lock.LockID[:], + Outpoint: lnrpc.MarshalOutPoint(&lock.Outpoint), Expiration: uint64(lock.Expiration.Unix()), PkScript: lock.PkScript, Value: uint64(lock.Value), diff --git a/routing/localchans/manager.go b/routing/localchans/manager.go index 4cec09354..2155e6285 100644 --- a/routing/localchans/manager.go +++ b/routing/localchans/manager.go @@ -265,11 +265,7 @@ func (r *Manager) getHtlcAmtLimits(tx kvdb.RTx, chanPoint wire.OutPoint) ( func makeFailureItem(outPoint wire.OutPoint, updateFailure lnrpc.UpdateFailure, errStr string) *lnrpc.FailedUpdate { - outpoint := &lnrpc.OutPoint{ - TxidBytes: outPoint.Hash[:], - TxidStr: outPoint.Hash.String(), - OutputIndex: outPoint.Index, - } + outpoint := lnrpc.MarshalOutPoint(&outPoint) return &lnrpc.FailedUpdate{ Outpoint: outpoint, diff --git a/rpcserver.go b/rpcserver.go index 528ca18d2..f1cb8c86e 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4496,11 +4496,7 @@ func rpcChannelResolution(report *channeldb.ResolverReport) (*lnrpc.Resolution, res := &lnrpc.Resolution{ AmountSat: uint64(report.Amount), - Outpoint: &lnrpc.OutPoint{ - OutputIndex: report.OutPoint.Index, - TxidStr: report.OutPoint.Hash.String(), - TxidBytes: report.OutPoint.Hash[:], - }, + Outpoint: lnrpc.MarshalOutPoint(&report.OutPoint), } if report.SpendTxID != nil {