diff --git a/orm/encoding/ormfield/duration.go b/orm/encoding/ormfield/duration.go index 572b6e21e612..7d7f25b5c7e6 100644 --- a/orm/encoding/ormfield/duration.go +++ b/orm/encoding/ormfield/duration.go @@ -16,12 +16,12 @@ const ( // DurationCodec encodes google.protobuf.Duration values with the following // encoding: -// - nil is encoded as []byte{0xFF} -// - seconds (which can range from -315,576,000,000 to +315,576,000,000) is encoded as 5 fixed bytes -// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such -// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, -// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is -// preserved when comparing the encoded values of two Durations: +// - nil is encoded as []byte{0xFF} +// - seconds (which can range from -315,576,000,000 to +315,576,000,000) is encoded as 5 fixed bytes +// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such +// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, +// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is +// preserved when comparing the encoded values of two Durations: // - []byte{0xBB, 0x9A, 0xC9, 0xFF} for zero nanos // - 4 fixed bytes with the bit mask 0x80 applied to the first byte, with negative nanos scaled so that -999,999,999 // is encoded as 0 and -1 is encoded as 999,999,998 diff --git a/orm/encoding/ormfield/timestamp.go b/orm/encoding/ormfield/timestamp.go index 4788f390848a..d643a1c1d026 100644 --- a/orm/encoding/ormfield/timestamp.go +++ b/orm/encoding/ormfield/timestamp.go @@ -9,12 +9,12 @@ import ( // TimestampCodec encodes google.protobuf.Timestamp values with the following // encoding: -// - nil is encoded as []byte{0xFF} -// - seconds (which can range from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z) is encoded as 5 fixed bytes -// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such -// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, -// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is -// preserved when comparing the encoded values of two Timestamps. +// - nil is encoded as []byte{0xFF} +// - seconds (which can range from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z) is encoded as 5 fixed bytes +// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such +// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, +// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is +// preserved when comparing the encoded values of two Timestamps. // // When iterating over timestamp indexes, nil values will always be ordered last. // diff --git a/x/mint/README.md b/x/mint/README.md index ff2467d7542a..65a28a7088fa 100644 --- a/x/mint/README.md +++ b/x/mint/README.md @@ -96,7 +96,7 @@ The target annual inflation rate is recalculated each block. The inflation is also subject to a rate change (positive or negative) depending on the distance from the desired ratio (67%). The maximum rate change possible is defined to be 13% per year, however, the annual inflation is capped -as between 7% and 20%. +as between 0% and 5%. ```go NextInflationRate(params Params, bondedRatio math.LegacyDec) (inflation math.LegacyDec) { diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go index dbfdf4cd2a94..02a0165230f4 100644 --- a/x/mint/types/minter_test.go +++ b/x/mint/types/minter_test.go @@ -23,31 +23,31 @@ func TestNextInflation(t *testing.T) { bondedRatio, setInflation, expChange math.LegacyDec }{ // with 0% bonded atom supply the inflation should increase by InflationRateChange - {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(7, 2), params.InflationRateChange.Quo(blocksPerYr)}, + {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(0, 2), params.InflationRateChange.Quo(blocksPerYr)}, // 100% bonded, starting at 20% inflation and being reduced // (1 - (1/0.67))*(0.13/8667) { - math.LegacyOneDec(), math.LegacyNewDecWithPrec(20, 2), + math.LegacyOneDec(), math.LegacyNewDecWithPrec(5, 2), math.LegacyOneDec().Sub(math.LegacyOneDec().Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr), }, // 50% bonded, starting at 10% inflation and being increased { - math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(10, 2), + math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(2, 2), math.LegacyOneDec().Sub(math.LegacyNewDecWithPrec(5, 1).Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr), }, - // test 7% minimum stop (testing with 100% bonded) - {math.LegacyOneDec(), math.LegacyNewDecWithPrec(7, 2), math.LegacyZeroDec()}, - {math.LegacyOneDec(), math.LegacyNewDecWithPrec(700000001, 10), math.LegacyNewDecWithPrec(-1, 10)}, + // test 0% minimum stop (testing with 100% bonded) + {math.LegacyOneDec(), math.LegacyNewDecWithPrec(0, 2), math.LegacyZeroDec()}, + {math.LegacyOneDec(), math.LegacyNewDecWithPrec(0o00000001, 10), math.LegacyNewDecWithPrec(-1, 10)}, - // test 20% maximum stop (testing with 0% bonded) - {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(20, 2), math.LegacyZeroDec()}, - {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(1999999999, 10), math.LegacyNewDecWithPrec(1, 10)}, + // test 5% maximum stop (testing with 0% bonded) + {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(5, 2), math.LegacyZeroDec()}, + {math.LegacyZeroDec(), math.LegacyNewDecWithPrec(499999999, 10), math.LegacyNewDecWithPrec(1, 10)}, // perfect balance shouldn't change inflation - {math.LegacyNewDecWithPrec(67, 2), math.LegacyNewDecWithPrec(15, 2), math.LegacyZeroDec()}, + {math.LegacyNewDecWithPrec(67, 2), math.LegacyNewDecWithPrec(5, 2), math.LegacyZeroDec()}, } for i, tc := range tests { minter.Inflation = tc.setInflation diff --git a/x/mint/types/params.go b/x/mint/types/params.go index 9c5c483671d6..370eeea9106e 100644 --- a/x/mint/types/params.go +++ b/x/mint/types/params.go @@ -28,8 +28,8 @@ func DefaultParams() Params { return Params{ MintDenom: sdk.DefaultBondDenom, InflationRateChange: math.LegacyNewDecWithPrec(13, 2), - InflationMax: math.LegacyNewDecWithPrec(20, 2), - InflationMin: math.LegacyNewDecWithPrec(7, 2), + InflationMax: math.LegacyNewDecWithPrec(5, 2), + InflationMin: math.LegacyNewDecWithPrec(0, 2), GoalBonded: math.LegacyNewDecWithPrec(67, 2), BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times MaxSupply: math.ZeroInt(), // assuming zero is infinite