Skip to content
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: export coin selection strategy code for re-use #900

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Jan 12, 2024

We want to be able to use the available coin selection strategies outside of just the coin selection methods offered by the wallet. So this PR refactors the code to be re-used.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🩰

wallet/createtx.go Show resolved Hide resolved

// ArrangeCoins takes a list of coins and arranges them according to the
// specified coin selection strategy and fee rate.
func ArrangeCoins[T SelectableCoin](coinSelectionStrategy CoinSelectionStrategy,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type param usage doesn't feel absolutely necessary here? At least in the context of the wallet today, seems like we could jut swap in SelectableCoin as the interface are here instead of T. I think reaching for the type param here would make more sense if we already had several other instances of something like ArrangeCoins that accepted a diff concrete type.

Will take a look at the other dependent PRs here as well. Not a blocker, just mainly curious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for using the type parameter here is because Golang doesn't allow using a struct slice when an interface slice is expected.
For example, if ArrangeCoins took eligigle []SelectableCoin, we couldn't pass in a slice of []*SelectableCredit.
Not a big deal here since we're wrapping the wtxmgr.Credit anyway.
But in lnd we could pass in chanfunding.Coin directly if we use the typed parameter.
But wrapping that wouldn't be a big deal either, so I can go with the interface if you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved this by just moving the chanfunding.Coin declaration into the wallet. I think it makes sense to have a specific type that contains just exactly what's needed for coin selection.

wallet/createtx.go Outdated Show resolved Hide resolved
@guggero guggero force-pushed the export-coin-selection branch 2 times, most recently from 2a66eb0 to 25a24d2 Compare January 15, 2024 11:41
@guggero guggero force-pushed the export-coin-selection branch from 25a24d2 to f1ba877 Compare January 18, 2024 11:14
This commit refactors and then exports the DecorateInputs method that
adds all required information to a PSBT packet's inputs that are
required for signing for them.
@guggero guggero force-pushed the export-coin-selection branch from f1ba877 to d27dac3 Compare January 18, 2024 15:16
@guggero guggero requested a review from Roasbeef January 18, 2024 15:24
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦊

@@ -89,17 +89,33 @@ var (
wtxmgrNamespaceKey = []byte("wtxmgr")
)

type CoinSelectionStrategy int
// Coin represents a spendable UTXO which is available for coin selection.
type Coin struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Roasbeef Roasbeef merged commit 6b096b0 into btcsuite:master Jan 25, 2024
3 checks passed
@guggero guggero deleted the export-coin-selection branch January 29, 2024 06:18
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
wallet: export coin selection strategy code for re-use
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
wallet: export coin selection strategy code for re-use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants