diff --git a/CHANGELOG.md b/CHANGELOG.md index d26e8e3a60c4..ce410e404a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -117,9 +117,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command. * (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls. * (rosetta) [\#10001](https://github.com/cosmos/cosmos-sdk/issues/10001) Add documentation for rosetta-cli dockerfile and rename folder for the rosetta-ci dockerfile +* [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression. ### Bug Fixes +* (store) [#10218](https://github.com/cosmos/cosmos-sdk/pull/10218) Charge gas even when there are no entries while seeking. * (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly. * [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter. * [\#9639](https://github.com/cosmos/cosmos-sdk/pull/9639) Check store keys length before accessing them by making sure that `key` is of length `m+1` (for `key[n:m]`) diff --git a/go.mod b/go.mod index d063a3a05d63..795f06af2e3b 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,7 @@ require ( google.golang.org/grpc v1.40.0 google.golang.org/protobuf v1.27.1 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect - sigs.k8s.io/yaml v1.2.0 + sigs.k8s.io/yaml v1.3.0 ) require ( diff --git a/go.sum b/go.sum index 12c0ac0f3067..59abe0442087 100644 --- a/go.sum +++ b/go.sum @@ -1303,6 +1303,6 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= -sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/store/gaskv/store.go b/store/gaskv/store.go index aa9a29b7c153..6fbc43fcf050 100644 --- a/store/gaskv/store.go +++ b/store/gaskv/store.go @@ -108,9 +108,7 @@ func (gs *Store) iterator(start, end []byte, ascending bool) types.Iterator { } gi := newGasIterator(gs.gasMeter, gs.gasConfig, parent) - if gi.Valid() { - gi.(*gasIterator).consumeSeekGas() - } + gi.(*gasIterator).consumeSeekGas() return gi } @@ -143,10 +141,7 @@ func (gi *gasIterator) Valid() bool { // in the iterator. It incurs a flat gas cost for seeking and a variable gas // cost based on the current value's length if the iterator is valid. func (gi *gasIterator) Next() { - if gi.Valid() { - gi.consumeSeekGas() - } - + gi.consumeSeekGas() gi.parent.Next() } @@ -177,8 +172,10 @@ func (gi *gasIterator) Error() error { // consumeSeekGas consumes on each iteration step a flat gas cost and a variable gas cost // based on the current value's length. func (gi *gasIterator) consumeSeekGas() { - value := gi.Value() + if gi.Valid() { + value := gi.Value() - gi.gasMeter.ConsumeGas(gi.gasConfig.ReadCostPerByte*types.Gas(len(value)), types.GasValuePerByteDesc) + gi.gasMeter.ConsumeGas(gi.gasConfig.ReadCostPerByte*types.Gas(len(value)), types.GasValuePerByteDesc) + } gi.gasMeter.ConsumeGas(gi.gasConfig.IterNextCostFlat, types.GasIterNextCostFlatDesc) } diff --git a/store/gaskv/store_test.go b/store/gaskv/store_test.go index e111a72329a7..f926c7b7250e 100644 --- a/store/gaskv/store_test.go +++ b/store/gaskv/store_test.go @@ -4,13 +4,12 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/store/dbadapter" "github.com/cosmos/cosmos-sdk/store/gaskv" "github.com/cosmos/cosmos-sdk/store/types" - - "github.com/stretchr/testify/require" ) func bz(s string) []byte { return []byte(s) } @@ -41,14 +40,18 @@ func TestGasKVStoreBasic(t *testing.T) { func TestGasKVStoreIterator(t *testing.T) { mem := dbadapter.Store{DB: dbm.NewMemDB()} - meter := types.NewGasMeter(10000) + meter := types.NewGasMeter(100000) st := gaskv.NewStore(mem, meter, types.KVGasConfig()) require.False(t, st.Has(keyFmt(1))) require.Empty(t, st.Get(keyFmt(1)), "Expected `key1` to be empty") require.Empty(t, st.Get(keyFmt(2)), "Expected `key2` to be empty") + require.Empty(t, st.Get(keyFmt(3)), "Expected `key3` to be empty") + st.Set(keyFmt(1), valFmt(1)) require.True(t, st.Has(keyFmt(1))) st.Set(keyFmt(2), valFmt(2)) + require.True(t, st.Has(keyFmt(2))) + st.Set(keyFmt(3), valFmt(0)) iterator := st.Iterator(nil, nil) start, end := iterator.Domain() @@ -71,8 +74,16 @@ func TestGasKVStoreIterator(t *testing.T) { vb := iterator.Value() require.Equal(t, vb, valFmt(2)) iterator.Next() + require.Equal(t, types.Gas(13377), meter.GasConsumed()) + kc := iterator.Key() + require.Equal(t, kc, keyFmt(3)) + vc := iterator.Value() + require.Equal(t, vc, valFmt(0)) + iterator.Next() + require.Equal(t, types.Gas(13446), meter.GasConsumed()) require.False(t, iterator.Valid()) require.Panics(t, iterator.Next) + require.Equal(t, types.Gas(13476), meter.GasConsumed()) require.NoError(t, iterator.Error()) reverseIterator := st.ReverseIterator(nil, nil) @@ -81,6 +92,8 @@ func TestGasKVStoreIterator(t *testing.T) { t.Fatal(err) } }) + require.Equal(t, reverseIterator.Key(), keyFmt(3)) + reverseIterator.Next() require.Equal(t, reverseIterator.Key(), keyFmt(2)) reverseIterator.Next() require.Equal(t, reverseIterator.Key(), keyFmt(1)) @@ -88,7 +101,7 @@ func TestGasKVStoreIterator(t *testing.T) { require.False(t, reverseIterator.Valid()) require.Panics(t, reverseIterator.Next) - require.Equal(t, types.Gas(9194), meter.GasConsumed()) + require.Equal(t, types.Gas(13782), meter.GasConsumed()) } func TestGasKVStoreOutOfGasSet(t *testing.T) { diff --git a/types/coin.go b/types/coin.go index 0546d5c63d1b..68cd7062505f 100644 --- a/types/coin.go +++ b/types/coin.go @@ -644,8 +644,8 @@ func (coins Coins) Sort() Coins { var ( // Denominations can be 3 ~ 128 characters long and support letters, followed by either - // a letter, a number or a separator ('/'). - reDnmString = `[a-zA-Z][a-zA-Z0-9/-]{2,127}` + // a letter, a number or a separator ('/', ':', '.', '_' or '-'). + reDnmString = `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}` reDecAmt = `[[:digit:]]+(?:\.[[:digit:]]+)?|\.[[:digit:]]+` reSpc = `[[:space:]]*` reDnm *regexp.Regexp diff --git a/types/coin_test.go b/types/coin_test.go index 9a5d83fea9c3..9ee493aaa0b9 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -96,6 +96,7 @@ func (s *coinTestSuite) TestCoinIsValid() { {sdk.Coin{loremIpsum, sdk.OneInt()}, false}, {sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, true}, {sdk.Coin{"atOm", sdk.OneInt()}, true}, + {sdk.Coin{"x:y-z.1_2", sdk.OneInt()}, true}, {sdk.Coin{" ", sdk.OneInt()}, false}, } @@ -706,7 +707,7 @@ func (s *coinTestSuite) TestParseCoins() { {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name {"11me coin, 12you coin", false, nil}, // no spaces in coin names {"1.2btc", true, sdk.Coins{{"btc", sdk.NewInt(1)}}}, // amount can be decimal, will get truncated - {"5foo:bar", false, nil}, // invalid separator + {"5foo:bar", true, sdk.Coins{{"foo:bar", sdk.NewInt(5)}}}, {"10atom10", true, sdk.Coins{{"atom10", sdk.NewInt(10)}}}, {"200transfer/channelToA/uatom", true, sdk.Coins{{"transfer/channelToA/uatom", sdk.NewInt(200)}}}, {"50ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true, sdk.Coins{{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(50)}}},