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

multi: anchor fee test coverage #605

Merged
merged 7 commits into from
Jan 9, 2024
Merged

multi: anchor fee test coverage #605

merged 7 commits into from
Jan 9, 2024

Conversation

jharveyb
Copy link
Contributor

@jharveyb jharveyb commented Oct 19, 2023

Fixes #671

Verifies fixes for various issues with fee estimation.

There are also some issues with cleaning up caretaker state if the caretaker returns an error, which is not recoverable from inside the caretaker.

Batch finalization could be manually reattempted by the user.

Also added extra logging of fee rates and transaction weights.

Should also change units exposed to the user.

In line with our other software, this flag could be called --sat_per_vbyte and be measured in sat/vB. We use the term fee_rate a bit differently in LND.

@jharveyb
Copy link
Contributor Author

Will split out the caretaker shutdown issue discovered here into a separate PR. I think we can move testing for that fix into the existing unit tests for the planter, where we trigger the error with a different mock wallet anchor that always fails.

@dstadulis dstadulis added this to the v0.4 milestone Nov 14, 2023
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 4b0bcd5 to a8c6988 Compare November 14, 2023 21:17
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from a8c6988 to 93fb244 Compare November 22, 2023 18:41
@jharveyb jharveyb changed the base branch from main to caretaker_stop_fixes November 22, 2023 18:41
@jharveyb
Copy link
Contributor Author

Split caretaker fixes into #693 , the fee estimation itest here depends on fixes added there.

@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 93fb244 to 1a530c0 Compare November 22, 2023 18:48
@jharveyb jharveyb force-pushed the caretaker_stop_fixes branch from 5ae0a56 to 83d5141 Compare November 22, 2023 18:48
@jharveyb jharveyb force-pushed the caretaker_stop_fixes branch 4 times, most recently from 93ca166 to c19f2d6 Compare December 4, 2023 21:30
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 1a530c0 to 372e47e Compare December 6, 2023 18:37
@jharveyb jharveyb force-pushed the caretaker_stop_fixes branch from c19f2d6 to 2b6900c Compare December 6, 2023 18:37
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 372e47e to 6af7724 Compare December 6, 2023 18:39
@jharveyb
Copy link
Contributor Author

jharveyb commented Dec 6, 2023

I think I've narrowed this down to possible issues with inputs that are older types like P2PKH.

In the minter we don't adjust the fee, but we still record it. In the freighter, we use a weight estimator unique to this repo to calculate TX weight, and then adjust the change output.

We could instead reuse weight & fee logic that IIUC is already being used as part of FundPsbt():

https://github.com/btcsuite/btcwallet/blob/5df09dd4335865dde2a9a6d94a26a7f5779af825/wallet/txsizes/size.go#L203

Most of this logic is already publicly exposed by these packages. We could also then unify fee estimation across the minter and freighter.

I think the old user issues about bad fee estimates on testnet during minting were just due to bad fee estimates.

@jharveyb
Copy link
Contributor Author

jharveyb commented Dec 6, 2023

Acceptance Criteria:

  • new weight and fee estimator that reuses code from btcwallet
  • itest that exercises the new manual feerate sanity-checking logic in the relevant RPC calls
  • update RPC calls to use sat/vB
  • itest that exercises correct feerates on minting and transfer when backing wallet only has old (NP2WKH, P2WKH) input types

@jharveyb jharveyb force-pushed the caretaker_stop_fixes branch from 2b6900c to 05b82da Compare December 8, 2023 19:15
@dstadulis
Copy link
Collaborator

There's a round issue that has caused the tests to fail. @jharveyb has identified root cause and addressing it.

@jharveyb
Copy link
Contributor Author

Specifically this unit conversion from sat/kw to sat/vB when constructing the FundPsbt call:

SatPerVbyte: uint64(feeRate.FeePerKVByte()) / 1000,

Where e.x. a feerate of 3125 sat/kw or 12.5 sat/vB is rounded down to 12 sat/vB.

@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 6af7724 to 935db82 Compare December 12, 2023 19:14
@jharveyb
Copy link
Contributor Author

Pushed up my latest state; discovered a separate issue about dust change handling in the freighter.

@jharveyb jharveyb changed the base branch from caretaker_stop_fixes to main December 14, 2023 00:57
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 935db82 to b646d2f Compare December 14, 2023 01:38
@jharveyb
Copy link
Contributor Author

Made tracking issue for dusty change: #738. Going to defer that for a separate PR.

@jharveyb jharveyb force-pushed the fee_estimation_testing branch 2 times, most recently from 5f4543e to 9b7d58d Compare December 14, 2023 17:33
@jharveyb jharveyb marked this pull request as ready for review December 14, 2023 17:56
@jharveyb
Copy link
Contributor Author

From offline discussion: the standard for fee unit handling is to use sat/kW on the RPC interface, but expose sat/vB as the unit on the CLI. We then convert from sat/vB to sat/kW before making our RPC call.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very nice improvements and test additions!
Needs one change for the RPC to remain at sat/kw, the rest looks good 💯

tapgarden/caretaker.go Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Show resolved Hide resolved
itest/assertions.go Show resolved Hide resolved
itest/utils.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
taprpc/taprootassets.proto Outdated Show resolved Hide resolved
cmd/tapcli/assets.go Show resolved Hide resolved
Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

Great itest and clear changes. Nice work.

I can only think of small things that might need addressing. My second review should be quick.

tapgarden/caretaker.go Outdated Show resolved Hide resolved
tapgarden/mock.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
itest/fee_estimation_test.go Outdated Show resolved Hide resolved
itest/fee_estimation_test.go Outdated Show resolved Hide resolved
itest/utils.go Outdated Show resolved Hide resolved

// ResetNodeWallet sets the wallet state of the given node to own 100 P2TR UTXOs
// of BTC, which matches the wallet state when initializing the itest harness.
func ResetNodeWallet(t *harnessTest, wallet *node.HarnessNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should call this function when initializing the itest harness to be certain that it's the default state.

@jharveyb
Copy link
Contributor Author

#605 (comment)

(Can't reply to comment directly) - the rounding up here is a difference of 3 sat/kw or 12 sat/kvB; so extremely small, even for a hypothetical large transfer TX.

This is also what we do in Pool:

https://github.com/lightninglabs/pool/blob/59c7c2b40009503851de6da3b3f9b4d90b34e208/cmd/pool/account.go#L172

Without the rounding, the TX would get rejected later on by LND before broadcast anyways, so the alternative (no rounding) is not allowing the user to specify a fee below 2 sat/vB.

@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 92957ce to e1e20fd Compare December 21, 2023 01:26
@jharveyb
Copy link
Contributor Author

Updated, would like to resolve the detail on possible inputs for transfers that don't have WitnessUtxo set.

@jharveyb
Copy link
Contributor Author

Made final updates re: non-witness inputs, ready for final approval.

@jharveyb jharveyb requested review from ffranr and guggero December 21, 2023 20:33
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, this is very close! CLI needs to be updated since the parseFeeRate() is used for other commands too. Other than that this looks good.

tapgarden/mock.go Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Outdated Show resolved Hide resolved
cmd/tapcli/assets.go Show resolved Hide resolved
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 7ee40f5 to 1d8b487 Compare December 22, 2023 17:54
@jharveyb jharveyb requested a review from guggero December 22, 2023 17:56
@lightninglabs-deploy
Copy link

@guggero: review reminder
@ffranr: review reminder

Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

🎆

tapfreighter/wallet.go Outdated Show resolved Hide resolved
In this commit, we add extra logging of fee rates to the minter, and
also remove a reimplementation of psbt.GetTxFee(). We also deduplicate
some dummy PkScript generation.
In this commit, we remove the amount of tap-specific code handling fee
estimation by replacing EstimateWeight() with EstimateFee(). This is a
thin wrapper around txsizes.EstimateVirttualSize(), and is very similar
to the implementation in txauthor/NewUnsignedTransaction.
In this commit, we add a new itest that exercises the minter and
freighter when using multiple input types like P2WKH and various fee
rates.
@jharveyb jharveyb force-pushed the fee_estimation_testing branch from 1d8b487 to 9a47eb8 Compare January 9, 2024 03:29
@jharveyb jharveyb added this pull request to the merge queue Jan 9, 2024
Merged via the queue into main with commit 5a25a46 Jan 9, 2024
14 checks passed
@guggero guggero deleted the fee_estimation_testing branch January 9, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[feature]: further test coverage for manual fee rates and fee rate estimation
5 participants