-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mempool: Reduce minimum replace fee from 1.25x to 1.1x (#10416)
However, we're leaving the default at 1.25x for backwards compatibility, for now. Also: 1. Actually use the configured replace fee ratio. 2. Store said ratios as percentages instead of floats. 1.25, or 1+1/(2^2), can be represented as a float. 1.1, or 1 + 1/(2 * 5), cannot. fixes #10415
- Loading branch information
Showing
12 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"strconv" | ||
|
||
"golang.org/x/xerrors" | ||
) | ||
|
||
// Percent stores a signed percentage as an int64. When converted to a string (or json), it's stored | ||
// as a decimal with two places (e.g., 100% -> 1.00). | ||
type Percent int64 | ||
|
||
func (p Percent) String() string { | ||
abs := p | ||
sign := "" | ||
if abs < 0 { | ||
abs = -abs | ||
sign = "-" | ||
} | ||
return fmt.Sprintf(`%s%d.%d`, sign, abs/100, abs%100) | ||
} | ||
|
||
func (p Percent) MarshalJSON() ([]byte, error) { | ||
return []byte(p.String()), nil | ||
} | ||
|
||
func (p *Percent) UnmarshalJSON(b []byte) error { | ||
flt, err := strconv.ParseFloat(string(b)+"e2", 64) | ||
if err != nil { | ||
return xerrors.Errorf("unable to parse ratio %s: %w", string(b), err) | ||
} | ||
if math.Trunc(flt) != flt { | ||
return xerrors.Errorf("ratio may only have two decimals: %s", string(b)) | ||
} | ||
*p = Percent(flt) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPercent(t *testing.T) { | ||
for _, tc := range []struct { | ||
p Percent | ||
s string | ||
}{ | ||
{100, "1.0"}, | ||
{111, "1.11"}, | ||
{12, "0.12"}, | ||
{-12, "-0.12"}, | ||
{1012, "10.12"}, | ||
{-1012, "-10.12"}, | ||
{0, "0.0"}, | ||
} { | ||
tc := tc | ||
t.Run(fmt.Sprintf("%d <> %s", tc.p, tc.s), func(t *testing.T) { | ||
m, err := tc.p.MarshalJSON() | ||
require.NoError(t, err) | ||
require.Equal(t, tc.s, string(m)) | ||
var p Percent | ||
require.NoError(t, p.UnmarshalJSON([]byte(tc.s))) | ||
require.Equal(t, tc.p, p) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters