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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions btcjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"github.com/btcsuite/btcd/wire"
)

// BTCPerkvB is the units used to represent Bitcoin transaction fees.
// This unit represents the fee in BTC for a transaction size of 1 kB.
type BTCPerkvB = float64

// AddNodeSubCmd defines the type used in the addnode JSON-RPC command for the
// sub command field.
type AddNodeSubCmd string
Expand Down Expand Up @@ -142,7 +146,7 @@ type FundRawTransactionOpts struct {
ChangeType *ChangeType `json:"change_type,omitempty"`
IncludeWatching *bool `json:"includeWatching,omitempty"`
LockUnspents *bool `json:"lockUnspents,omitempty"`
FeeRate *float64 `json:"feeRate,omitempty"` // BTC/kB
FeeRate *BTCPerkvB `json:"feeRate,omitempty"` // BTC/kB
SubtractFeeFromOutputs []int `json:"subtractFeeFromOutputs,omitempty"`
Replaceable *bool `json:"replaceable,omitempty"`
ConfTarget *int `json:"conf_target,omitempty"`
Expand Down Expand Up @@ -822,7 +826,7 @@ func NewSearchRawTransactionsCmd(address string, verbose, skip, count *int, vinE
}

// AllowHighFeesOrMaxFeeRate defines a type that can either be the legacy
// allowhighfees boolean field or the new maxfeerate int field.
// allowhighfees boolean field or the new maxfeerate float64 field.
type AllowHighFeesOrMaxFeeRate struct {
Value interface{}
}
Expand Down Expand Up @@ -862,7 +866,7 @@ func (a *AllowHighFeesOrMaxFeeRate) UnmarshalJSON(data []byte) error {
case bool:
a.Value = Bool(v)
case float64:
a.Value = Int32(int32(v))
a.Value = Float64(v)
default:
return fmt.Errorf("invalid allowhighfees or maxfeerate value: "+
"%v", unmarshalled)
Expand Down Expand Up @@ -893,9 +897,10 @@ func NewSendRawTransactionCmd(hexTx string, allowHighFees *bool) *SendRawTransac

// NewSendRawTransactionCmd returns a new instance which can be used to issue a
// sendrawtransaction JSON-RPC command to a bitcoind node.
// maxFeeRate is the maximum fee rate for the transaction in BTC/kvB.
//
// 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 BTCPerkvB) *SendRawTransactionCmd {
return &SendRawTransactionCmd{
HexTx: hexTx,
FeeSetting: &AllowHighFeesOrMaxFeeRate{
Expand Down Expand Up @@ -1050,13 +1055,13 @@ type TestMempoolAcceptCmd struct {

// Reject transactions whose fee rate is higher than the specified
// value, expressed in BTC/kvB, optional, default="0.10".
MaxFeeRate float64 `json:"omitempty"`
MaxFeeRate BTCPerkvB `json:"omitempty"`
}

// NewTestMempoolAcceptCmd returns a new instance which can be used to issue a
// testmempoolaccept JSON-RPC command.
func NewTestMempoolAcceptCmd(rawTxns []string,
maxFeeRate float64) *TestMempoolAcceptCmd {
maxFeeRate BTCPerkvB) *TestMempoolAcceptCmd {

return &TestMempoolAcceptCmd{
RawTxns: rawTxns,
Expand Down
8 changes: 4 additions & 4 deletions btcjson/chainsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,16 +1257,16 @@ func TestChainSvrCmds(t *testing.T) {
{
name: "sendrawtransaction optional, bitcoind >= 0.19.0",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("sendrawtransaction", "1122", &btcjson.AllowHighFeesOrMaxFeeRate{Value: btcjson.Int32(1234)})
return btcjson.NewCmd("sendrawtransaction", "1122", &btcjson.AllowHighFeesOrMaxFeeRate{Value: btcjson.Float64(0.1234)})
},
staticCmd: func() interface{} {
return btcjson.NewBitcoindSendRawTransactionCmd("1122", 1234)
return btcjson.NewBitcoindSendRawTransactionCmd("1122", 0.1234)
},
marshalled: `{"jsonrpc":"1.0","method":"sendrawtransaction","params":["1122",1234],"id":1}`,
marshalled: `{"jsonrpc":"1.0","method":"sendrawtransaction","params":["1122",0.1234],"id":1}`,
unmarshalled: &btcjson.SendRawTransactionCmd{
HexTx: "1122",
FeeSetting: &btcjson.AllowHighFeesOrMaxFeeRate{
Value: btcjson.Int32(1234),
Value: btcjson.Float64(0.1234),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions rpcclient/rawtransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
)

const (
// defaultMaxFeeRate is the default maximum fee rate in sat/KB enforced
// defaultMaxFeeRate is the default maximum fee rate in BTC/kvB enforced
// by bitcoind v0.19.0 or after for transaction broadcast.
defaultMaxFeeRate = btcutil.SatoshiPerBitcoin / 10
defaultMaxFeeRate btcjson.BTCPerkvB = 0.1
)

// SigHashType enumerates the available signature hashing types that the
Expand Down Expand Up @@ -365,7 +365,7 @@ func (c *Client) SendRawTransactionAsync(tx *wire.MsgTx, allowHighFees bool) Fut
if version.SupportUnifiedSoftForks() {
// Using a 0 MaxFeeRate is interpreted as a maximum fee rate not
// being enforced by bitcoind.
var maxFeeRate int32
var maxFeeRate btcjson.BTCPerkvB
if !allowHighFees {
maxFeeRate = defaultMaxFeeRate
}
Expand Down Expand Up @@ -915,7 +915,7 @@ func (r FutureTestMempoolAcceptResult) Receive() (
//
// See TestMempoolAccept for the blocking version and more details.
func (c *Client) TestMempoolAcceptAsync(txns []*wire.MsgTx,
maxFeeRate float64) FutureTestMempoolAcceptResult {
maxFeeRate btcjson.BTCPerkvB) FutureTestMempoolAcceptResult {

// Due to differences in the testmempoolaccept API for different
// backends, we'll need to inspect our version and construct the
Expand Down Expand Up @@ -1010,7 +1010,7 @@ func (c *Client) TestMempoolAcceptAsync(txns []*wire.MsgTx,
//
// The maximum number of transactions allowed is 25.
func (c *Client) TestMempoolAccept(txns []*wire.MsgTx,
maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) {
maxFeeRate btcjson.BTCPerkvB) ([]*btcjson.TestMempoolAcceptResult, error) {

return c.TestMempoolAcceptAsync(txns, maxFeeRate).Receive()
}
Expand Down
Loading