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.
This commit is contained in:
Elle Mouton 2023-04-21 14:51:56 +02:00
parent 4355ce62d2
commit 7b186716a1
No known key found for this signature in database
GPG key ID: D7D916376026F177
6 changed files with 22 additions and 25 deletions

View file

@ -13,6 +13,11 @@
the entire retribution struct. This reduces the amount of data that needs to the entire retribution struct. This reduces the amount of data that needs to
be held in memory. 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) # Contributors (Alphabetical Order)
* Elle Mouton * Elle Mouton

View file

@ -490,6 +490,7 @@ func (b *Batcher) cleanup(ctx context.Context) {
rpcOP := &lnrpc.OutPoint{ rpcOP := &lnrpc.OutPoint{
OutputIndex: lockedUTXO.Outpoint.OutputIndex, OutputIndex: lockedUTXO.Outpoint.OutputIndex,
TxidBytes: lockedUTXO.Outpoint.TxidBytes, TxidBytes: lockedUTXO.Outpoint.TxidBytes,
TxidStr: lockedUTXO.Outpoint.TxidStr,
} }
_, err := b.cfg.WalletKitServer.ReleaseOutput( _, err := b.cfg.WalletKitServer.ReleaseOutput(
ctx, &walletrpc.ReleaseOutputRequest{ ctx, &walletrpc.ReleaseOutputRequest{

View file

@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "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, // Now that we know we have a proper mapping to an address,
// we'll convert the regular outpoint to an lnrpc variant. // we'll convert the regular outpoint to an lnrpc variant.
outpoint := &OutPoint{ outpoint := MarshalOutPoint(&utxo.OutPoint)
TxidBytes: utxo.OutPoint.Hash[:],
TxidStr: utxo.OutPoint.Hash.String(),
OutputIndex: utxo.OutPoint.Index,
}
utxoResp := Utxo{ utxoResp := Utxo{
AddressType: addrType, AddressType: addrType,
@ -173,3 +170,12 @@ func MarshallOutputType(o txscript.ScriptClass) OutputScriptType {
return OutputScriptType_SCRIPT_TYPE_PUBKEY_HASH 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,
}
}

View file

@ -756,10 +756,7 @@ func (w *WalletKit) PendingSweeps(ctx context.Context,
pendingInput.OutPoint) pendingInput.OutPoint)
} }
op := &lnrpc.OutPoint{ op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint)
TxidBytes: pendingInput.OutPoint.Hash[:],
OutputIndex: pendingInput.OutPoint.Index,
}
amountSat := uint32(pendingInput.Amount) amountSat := uint32(pendingInput.Amount)
satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerKVByte() / 1000) satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerKVByte() / 1000)
broadcastAttempts := uint32(pendingInput.BroadcastAttempts) broadcastAttempts := uint32(pendingInput.BroadcastAttempts)
@ -1241,12 +1238,8 @@ func marshallLeases(locks []*base.ListLeasedOutputResult) []*UtxoLease {
lock := lock lock := lock
rpcLocks[idx] = &UtxoLease{ rpcLocks[idx] = &UtxoLease{
Id: lock.LockID[:], Id: lock.LockID[:],
Outpoint: &lnrpc.OutPoint{ Outpoint: lnrpc.MarshalOutPoint(&lock.Outpoint),
TxidBytes: lock.Outpoint.Hash[:],
TxidStr: lock.Outpoint.Hash.String(),
OutputIndex: lock.Outpoint.Index,
},
Expiration: uint64(lock.Expiration.Unix()), Expiration: uint64(lock.Expiration.Unix()),
PkScript: lock.PkScript, PkScript: lock.PkScript,
Value: uint64(lock.Value), Value: uint64(lock.Value),

View file

@ -265,11 +265,7 @@ func (r *Manager) getHtlcAmtLimits(tx kvdb.RTx, chanPoint wire.OutPoint) (
func makeFailureItem(outPoint wire.OutPoint, updateFailure lnrpc.UpdateFailure, func makeFailureItem(outPoint wire.OutPoint, updateFailure lnrpc.UpdateFailure,
errStr string) *lnrpc.FailedUpdate { errStr string) *lnrpc.FailedUpdate {
outpoint := &lnrpc.OutPoint{ outpoint := lnrpc.MarshalOutPoint(&outPoint)
TxidBytes: outPoint.Hash[:],
TxidStr: outPoint.Hash.String(),
OutputIndex: outPoint.Index,
}
return &lnrpc.FailedUpdate{ return &lnrpc.FailedUpdate{
Outpoint: outpoint, Outpoint: outpoint,

View file

@ -4496,11 +4496,7 @@ func rpcChannelResolution(report *channeldb.ResolverReport) (*lnrpc.Resolution,
res := &lnrpc.Resolution{ res := &lnrpc.Resolution{
AmountSat: uint64(report.Amount), AmountSat: uint64(report.Amount),
Outpoint: &lnrpc.OutPoint{ Outpoint: lnrpc.MarshalOutPoint(&report.OutPoint),
OutputIndex: report.OutPoint.Index,
TxidStr: report.OutPoint.Hash.String(),
TxidBytes: report.OutPoint.Hash[:],
},
} }
if report.SpendTxID != nil { if report.SpendTxID != nil {