Skip to content

Commit

Permalink
btcclient+btcjson: feeRate to BTC/kvB
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YusukeShimizu committed Mar 21, 2024
1 parent 8b2f43e commit c85b1e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions btcjson/chainsvrcmds.go
Expand Up @@ -862,7 +862,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 @@ -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 {
return &SendRawTransactionCmd{
HexTx: hexTx,
FeeSetting: &AllowHighFeesOrMaxFeeRate{
Expand Down
8 changes: 4 additions & 4 deletions btcjson/chainsvrcmds_test.go
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
6 changes: 3 additions & 3 deletions rpcclient/rawtransactions.go
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 float64 = 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 float64
if !allowHighFees {
maxFeeRate = defaultMaxFeeRate
}
Expand Down

0 comments on commit c85b1e4

Please sign in to comment.