Avoids a bleed out attack in which a node can be made to allocate
memory slowly or very fast in small strides, by sending bad data
to code that invokes NewAnyWithCustomTypeURL, in which we
unconditionally returned a new Any object. On a 64-bit machine,
this would waste 96 bytes per invocation even on error.
Added a test to ensure zero allocations with a fixed error returned.
Also added a benchmark which shows reduction in wasted allocations and
wasted CPU time:
```shell
$ benchstat before.txt after.txt
name old time/op new time/op delta
NewAnyWithCustomTypeURLWithErrorReturned-8 142ns ± 6% 55ns ±12% -61.65% (p=0.000 n=9+10)
name old alloc/op new alloc/op delta
NewAnyWithCustomTypeURLWithErrorReturned-8 96.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
NewAnyWithCustomTypeURLWithErrorReturned-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10)
```
Fixes#8537
* remove any.ClearCachedValue method
This method is in a public interface but used only for tests.
It shouldn't be used - `Any` values shouldn't be manipulated. This could lead to bugs.
* rename any_test.go
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
* Clean Any interface
+ removed Any.Pack method. This method is not needed, because we have specialized
functions for createing new Any values. It could be used inappropriately with existing
Any objects.
* removed deprecated PackAny function
* fix linter issue
* update nil handling
* NewAnyWithValue returns error on nil instead of panic
* NewMsgCreateValidator: handle nil pubkey
* Remove AsAny and tx builder workarounds
* fix linter issue
* Add AsAny methods to TxBuilder and StdTxConfig, but keep intoAny interface private
* remove tx.PubKeyToAny
* cosmetic updates
* fix method interface
* move ProtoTxProvider to x/auth/tx
* testing: refactore Validation and Delegation handling of x/staking
This Changeset introduces set of improvements for writing tests.
The idea is to create a testing subpackage which will provide functions
to make tests more dev-friendly and wrap higher level use-cases.
Here is a show-up of of creating a service for staking module
for tests.
This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string
to types.Any. This change motivated the other change to show the pattern I'm describing here.
* add validator checks
* type change fixes
* use deprecated
* adding test slashing
* new network comment update
* working on tests
* Fix TestMsgPkDecode test
* Add UnpackInterfaces to MsgCreateValidator
* Fix tests
* Convert bech32 pubkey to proto
* Fix test
* fix v039/migrate_test/TestMigrate
* fix tests
* testslashing: rename Service to Helper
* file rename
* update TestMsgDecode
Co-authored-by: blushi <marie.gauthier63@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
* refactor auths broadcast cmd in alignment with #6216
* add TxResponse proto definition, and related refactoring
* re-run make proto-gen, updating staking.pb.go
* cleanup TxResponse tests to handle nil return values
* properly handle nil Tx value in TxResponse's implementation of UnpackInterfaces
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>