Noticed during my audit, the code for cache.CommitKVStoreCacheManager.Reset()
discarded the prior on every invocation i.e.
m = make(map[T(key)]T(value))
However, this can be made fast and conserve memory by using the map clearing idiom
that the Go compiler recognizes i.e.
for key := range m {
delete(m, key)
}
and turns into very fast code, instead of the extraneous map discarding.
The speed up generated is:
```shell
$ benchstat before after
name old time/op new time/op delta
Reset-8 204ns ± 2% 66ns ± 9% -67.86% (p=0.000 n=20+20)
name old alloc/op new alloc/op delta
Reset-8 384B ± 0% 0B -100.00% (p=0.000 n=20+20)
name old allocs/op new allocs/op delta
Reset-8 3.00 ± 0% 0.00 -100.00% (p=0.000 n=20+20)
```
Fixes#6681
Use big.Int.Cmp() and compare against zeroInt instead
of checking Bytes() against a 0-length byte slice.
Closes: #6680
Thanks: @odeke-em for the patch.
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Noticed during an audit, we've got duplicated code that's unused.
There were 2 type definitions:
* type kvPair types.Pair
* type KVPair types.Pair
and each had a .bytes() and .Bytes() method respectively that
then used some extra code.
This change deletes the duplicated/unnecessary code but also
while here improves the performance by removing the use of a
bytes.Buffer which is unnecessary given that we are only
length prefixed the key, length prefixing the value hence
the various helpers are unnecessary.
The added benchmarks shows the performance boost
```shell
$ benchstat before after
name old time/op new time/op delta
KVPairBytes-8 146µs ± 1% 142µs ± 2% -3.05% (p=0.000 n=18+17)
name old speed new speed delta
KVPairBytes-8 6.84GB/s ± 1% 7.06GB/s ± 2% +3.15% (p=0.000 n=18+17)
name old alloc/op new alloc/op delta
KVPairBytes-8 1.01MB ± 0% 1.01MB ± 0% -0.04% (p=0.000 n=17+20)
name old allocs/op new allocs/op delta
KVPairBytes-8 6.00 ± 0% 1.00 ± 0% -83.33% (p=0.000 n=20+20)
```
Closes: #6688
* Add basic grpc query service for x/evidence
* Add grpc query test for AllEvidences query
* linting
* Add AnyUnpacker to query test helper and some var renaming
* Add test to check Evidence query result
* Update proto/cosmos/evidence/query.proto
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
* Use table tests
* Use NewQueryEvidenceRequest in place of QueryEvidenceParams
* Remove ConvertEvidence
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
As part of an audit, adds as much visible coverage from
73.4% to about 84.2%, but after #6668 is merged, we'll
have it about 88.X% and the coverage report seems to show
only missing cases of not common scenarios, e.g. a case that'll
make jsonpb.Marshaling to fail, and which will return an error
anyways.
Fixes an invalid int->string conversion that will become
a vet error for Go1.15. The correct conversion was to use
fmt.Sprintf("COINZ_%d", i)
instead of
"COINZ_" + string(i)
Noticed during a coverage audit.
Prepare migrating testing auxiliary functions from tests
to testutil.
Remove local duplicates on testutil.WriteToNewTempFile().
Always favor testutil.NewTestCaseDir() over ioutil.TempDir().
Add test cases for the testing auxiliary functions.
* initial implementation of per denom sendenabled
* Fix for accidentally removed keyword
* Validate individual param in param array
* Lint fix
* Refactor bank params to use protobuf
Modified SendEnabled property to be part of generic Params object
Updated genesis functions to use default params structure
* Refactor simulation genesis for clarity
* update changelog for bank sendenable per denom
* fix NoOpMsg type in multisend test
* Add a coin denom send check utility function
* Additional godoc comments and clarification
* Add default send enabled parameter to bank.
Remove empty denom capability from SendEnabled parameters
Update simulation to exercise both configuration options independently
* Minor suggested improvements.
* simulation fix
* bank proto sendenabled package name removed
* Remove extra gogo proto yaml tags
* Params rename IsSendEnabled to SendEnabledDenom
* Refactor to SendEnabledCoin(s)
* update slashing test to use bank params
* Clean up change log entry for feature.
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>