-
Notifications
You must be signed in to change notification settings - Fork 127
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
[wallet 2/3]: refactor funding logic to use allocation code #1407
Conversation
Pull Request Test Coverage Report for Build 13661304934Details
💛 - Coveralls |
08b7805
to
941d26e
Compare
941d26e
to
06ea429
Compare
8c3d631
to
c28aacf
Compare
06ea429
to
8939b42
Compare
c28aacf
to
f2b9b0f
Compare
ee66eb9
to
86112a5
Compare
f2b9b0f
to
d416a6f
Compare
@@ -328,7 +332,7 @@ func sortPiecesWithProofs(pieces []*piece) { | |||
// asset outputs (asset UTXOs of different sizes from different tranches/asset | |||
// IDs) according to the distribution rules provided as "allocations". | |||
func DistributeCoins(inputs []*proof.Proof, allocations []*Allocation, | |||
chainParams *address.ChainParams, | |||
chainParams *address.ChainParams, interactive bool, |
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.
Still getting through the PR, but is the idea here that we'll start to use DistributeCoins
more widely in the codebase? As otherwise right now, it's always used in an interactive setting.
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.
Yeah, exactly. We'll want to use the allocation code for the wallet's funding logic, which we'll use for the channel funding and in the future for the grouped asset on-chain send.
86112a5
to
cdc7cb2
Compare
We'll generalize the allocation code in future commits so we can re-use it. We need to make sure we don't create circular package dependencies, so we move the code to a more appropriate location.
The version of the virtual packet has an influence on the commitment versions of the outputs created from it, so it's important that it can be configured in a more generic use of the allocation code.
This is a preparatory commit that refactors the piece allocation code a bit. This will make the actual changes in the next commit more easy to understand. This commit changes nothing in the behavior of the code.
The allocation code was previously only used for channel outputs, where all virtual transactions are always interactive. But we want to use the same code for non-interactive transfers (address based send logic) as well, which requires a couple of tweaks.
Since we're going to be using the allocation code for all send logic, we need to add all fields of the vOutput to the allocation, so the values will be applied correctly. Since we also add the explicit LockTime, we need to rename the CLTV field so it's more clear that this field is only used for the HTLC tiebreaking sort procedure. Finally, we add a new Validate method to the allocation that makes sure all required input fields are set.
cdc7cb2
to
be499e2
Compare
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.
🎆
Previously, we generated one allocation per channel asset. That was wrong and only worked because we never actually had multiple asset pieces in a channel. The idea of an allocation is that you only have one per on-chain output and that the different asset pieces are then distributed between the different outputs automatically. Because that means we need a way to give each virtual output of each asset piece a unique script key (where required), we need to turn the field into a functional type. In some places (e.g. the channel funding output) each vOutput of each different vPacket will have the same script key. In other places (e.g. cooperative close), we derived script keys per asset ID upfront so we need to use those for things to work correctly.
Because we'll need to convert a funding template that's potentially given to us over the RPC interface into an allocation, we need to add custom code for that. This will be used in the freighter to interpret the user-provided virtual packet into an allocation in the normal send logic.
With the new funding logic now potentially adding the change output first, we need to make sure the channel funding logic doesn't use hard-coded indexes.
We are now validating the input amount and types when creating the allocations and no longer need this function.
be499e2
to
bb88417
Compare
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.
LGTM 🐎
Reviewed 4 of 16 files at r4, 8 of 9 files at r8, 2 of 2 files at r9, 8 of 8 files at r10, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ffranr and @guggero)
tapchannel/aux_closer.go
line 272 at r10 (raw file):
return accu + o.Amount.Val } localSum := fn.Reduce(commitState.LocalAssets.Val.Outputs, sumAmounts)
😎
Refactors the wallet's funding code to use the pre-existing allocation logic to distribute coins from grouped assets.
Part of the group key support saga:
This change is