-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PrevId[] UTXO selection for FundVirtualPSBT RPC method; valid for single PrevId at first #1172
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 11734743383Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This is definitely something we want as well and just didn't get to yet.
See inline comment for alternative and slightly more generic approach.
100f726
to
483eb84
Compare
@guggero addressed! Any thoughts on modifying or adding a new itest? I was thinking maybe to modify
Or copy + update the scenario to include an array of 2 inputs perhaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the updates!
Mostly nits remaining. Would be nice to perhaps add an integration test? Do you have time to do that?
if len(raw.Inputs) > 0 { | ||
return nil, fmt.Errorf("template inputs not yet " + | ||
"supported") | ||
for _, input := range raw.Inputs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove a whole level of indentation by removing the if len(raw.Inputs) > 0 {
since for ... range
loops are nil
safe.
return nil, fmt.Errorf("template inputs not yet " + | ||
"supported") | ||
for _, input := range raw.Inputs { | ||
// Create a new chainhash.Hash and set its bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comments should always be full sentences and end with punctuation.
for _, input := range raw.Inputs { | ||
// Create a new chainhash.Hash and set its bytes | ||
var hash chainhash.Hash | ||
err := hash.SetBytes(input.Outpoint.Txid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should use chainhash.NewHash()
instead.
"invalid Txid length: %w", err, | ||
) | ||
} | ||
// Decode the input into an asset.PrevID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if a comment isn't at the beginning of a new block/indentation, we usually add an empty line before to give some breathing space.
var hash chainhash.Hash | ||
err := hash.SetBytes(input.Outpoint.Txid) | ||
if err != nil { | ||
return nil, fmt.Errorf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Multi-line calls to formatting function should follow the different form to more easily distinguish them from non-error/non-logging calls. See https://github.com/lightningnetwork/lnd/blob/master/docs/code_formatting_rules.md#exception-for-log-and-error-message-formatting.
@@ -69,6 +69,7 @@ type Wallet interface { | |||
// selected assets. | |||
FundAddressSend(ctx context.Context, | |||
coinSelectType tapsend.CoinSelectType, | |||
prevIDs []asset.PrevID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: seems to fit on previous line, here and below.
@@ -35,6 +35,9 @@ type CommitmentConstraints struct { | |||
// to satisfy the constraints. | |||
MinAmt uint64 | |||
|
|||
// PrevIDs are the set of inputs allowed to be used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing full stop.
for _, input := range raw.Inputs { | ||
// Create a new chainhash.Hash and set its bytes | ||
var hash chainhash.Hash | ||
err := hash.SetBytes(input.Outpoint.Txid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably check that input.Outpoint
is not nil
.
@@ -2049,9 +2049,31 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context, | |||
|
|||
case req.GetRaw() != nil: | |||
raw := req.GetRaw() | |||
prevIDs := []asset.PrevID{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: var prevIDs []asset.PrevID
style is preferred over empty slice initialization.
Related to #1164
This PR simply implements the plumbing required to utilize the PrevIds payload for FundVirtualPSBT. Similar to how we can only handle 1 address for a raw input, this PR also only implements support for a single PrevId in the PrevIds payload.
At a high level, we perform the following:
constraintsToDbFilter
to utilize the prevID if the length is 1:To-dos:
assetFilter.AnchorPoint = encodedOutpoint
, everything else works as expected and is serving our needs in our demo environment