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

btcclient+btcjson: defaultMaxFeeRate to BTC/kvB #2142

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

YusukeShimizu
Copy link
Contributor

defaultMaxFeeRate was set to 1e8 / 10(sat/kb) as a parameter.
But BTC/kvB is the expected value, so the units was wrong.
This updates defaultMaxFeeRate to BTC/kvB and sets it to 0.1, which is the default value of Bitcoin Core.

Because maxFeeRate sanity check has been added in bitcoin core v27.0 or later, sendrawtransaction cannot be executed without this change.

Fixes lightningnetwork/lnd#8571

Copy link
Collaborator

@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.

Thanks a lot for the report and the fix!
I confirmed locally that this fixes the Fee rates larger than or equal to 1BTC/kvB are not accepted error in lnd.
I'll create a PR to run full lnd unit and integration tests on bitcoind v27.0 (rc1) soon.

@@ -895,7 +895,7 @@ func NewSendRawTransactionCmd(hexTx string, allowHighFees *bool) *SendRawTransac
// sendrawtransaction JSON-RPC command to a bitcoind node.
//
// A 0 maxFeeRate indicates that a maximum fee rate won't be enforced.
func NewBitcoindSendRawTransactionCmd(hexTx string, maxFeeRate int32) *SendRawTransactionCmd {
func NewBitcoindSendRawTransactionCmd(hexTx string, maxFeeRate float64) *SendRawTransactionCmd {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add a note in the Godoc comment above what the unit for the maxFeeRate is?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can even make a type alias to float64 of the unit? So something like type SatPerVByte = float64. We have some of this in lnd, but it isn't in a sub-module yet, so we'd need to bring in the entire repo. Alternatively, we can just copy over the files/definitions somewhere in btcutil, as they're super useful if you're doing any on chain stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment about maxFeeRate unit.
714e994
I will rebase after review.

We have some of this in lnd

Would it be possible to tell me where in lnd the above mentioned file is located?

I assume that adding a type alias for BTC/kvB will be handled in a separate PR once it is decided, as it requires an update to btcutil.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The fee rate types are here: https://github.com/lightningnetwork/lnd/blob/60bc30dd08bb6abb39d7f8481ebd990d587e5469/lnwallet/chainfee/rates.go.

Yes, because of the Go modules, there first needs to be a PR in btcutil, then after merging that a tag is pushed and then the code can be used in this file here.

But maybe, because bitcoind uses its own fee rate type (BTC/kvB instead of sat/kWU we use in lnd), it would be okay to define the type in this package directly, as AFAIK it's the only place where we actually use BTC/kvB.
It looks like the fee rate is used for fundrawtransaction and sendrawtransaction currently.

Copy link
Contributor Author

@YusukeShimizu YusukeShimizu Mar 23, 2024

Choose a reason for hiding this comment

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

Thank you for sharing.

Yes, I agree with adding the type alias here.
It is used by TestMempoolAccept, fundrawtransaction and SendRawTransaction, so I am replacing their definitions with this type alias.
bd5af2b

Copy link
Collaborator

@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.

Can you please squash the commits? Otherwise looks good to me, thank you!

@coveralls
Copy link

coveralls commented Mar 25, 2024

Pull Request Test Coverage Report for Build 8369564008

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 3 of 6 (50.0%) changed or added relevant lines in 2 files are covered.
  • 851 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-0.003%) to 56.883%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/rawtransactions.go 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
mempool/mempool.go 1 66.84%
btcjson/chainsvrcmds.go 10 97.57%
wire/msgtx.go 22 95.66%
mining/mining.go 64 8.58%
rpcserver.go 754 4.15%
Totals Coverage Status
Change from base Build 8441510314: -0.003%
Covered Lines: 29430
Relevant Lines: 51738

💛 - Coveralls

defaultMaxFeeRate was set to 1e8 / 10(sat/kb) as a parameter.
But BTC/kvB is the expected value, so the units was wrong.
This commit updates defaultMaxFeeRate to BTC/kvB and sets it to 0.1,
which is the default value of Bitcoin Core.
This commit also updates the comment to reflect the change.

Because maxFeeRate sanity check has been added in
bitcoin core v27.0 or later,
sendrawtransaction cannot be executed without this change.
Added type alias BTC/kvB to explicitly indicate that
it represents the fee in BTC for a transaction size of 1 kB.
Because bitcoind uses its own fee rate type
(BTC/kvB instead of sat/kWU we use in lnd),
define the type in btcjson package,
as it's the only place where we actually use BTC/kvB.
@YusukeShimizu
Copy link
Contributor Author

I have squashed it.

@guggero guggero requested a review from Roasbeef April 2, 2024 06:39
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 💸

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.

[bug]: sendcoins fails in bitcoind after v27
4 participants