Go to file
Matt Kocubinski 4db99fc1a5
fix(math): Dec marshal shouldn't have side effects (#15506)
## Description

Ref: https://github.com/cosmos/cosmos-sdk/issues/15170
Included in: #15515 

Required to resolve a discrepancy between the sign mode being implemented in #15170 and the existing legacy one.

When calling tx builder [SetMsgs](4a6a1e3cb8/x/auth/tx/builder.go (L208)) messages are coerced to an any type in [NewAnyWithValue](4a6a1e3cb8/codec/types/any.go (L61)). This marshals a message as proto bytes. If a message has cosmos.Dec typed fields, and they are set to nil, the will be set to 0 during seriazliation in the [Dec.Marshal](88909d6f2b/math/dec.go (L801)) implementation.

This side effect *changes* the output of a JSON marshal before and after the call to Dec.Marshal, as shown below.

```go
rates := &stakingtypes.CommissionRates{}
MarshalJson(rates)
// {"rate":"0","max_rate":"0","max_change_rate":"0"}

MarshalProto(rates)

MarshalJson(rates)
//{"rate":"0.000000000000000000","max_rate":"0.000000000000000000","max_change_rate":"0.000000000000000000"}
```

An integration is test is also committed asserting the (now fixed) behavior above.  Its asserts should be changed once a release of math is made and `/tests/go.mod` is updated.



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

* [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] added `!` to the type prefix if API or client breaking change
* [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
* [ ] provided a link to the relevant issue or specification
* [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
* [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
* [ ] added a changelog entry to `CHANGELOG.md`
* [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
* [ ] updated the relevant documentation or specification
* [ ] reviewed "Files changed" and left comments if necessary
* [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

* [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] confirmed all author checklist items have been addressed 
* [ ] reviewed state machine logic
* [ ] reviewed API design and naming
* [ ] reviewed documentation is accurate
* [ ] reviewed tests and test coverage
* [ ] manually tested (if applicable)
2023-03-22 19:48:36 +00:00
.github refactor: use app config configurator for removing boilerplate (#15499) 2023-03-22 07:29:33 +01:00
.vscode feat: add vscode e2e config (#13851) 2022-11-14 11:26:28 +01:00
api build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
baseapp fix: always reset the state for Prepare and Process Proposal (#15487) 2023-03-21 19:42:19 +00:00
client build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
codec refactor!: remove some legacy amino stuff needed for #11275 (#15299) 2023-03-15 20:10:23 +00:00
collections build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
contrib ci: add changelog reminder (#15459) 2023-03-21 14:44:24 +01:00
core build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
crypto fix(crypto/keyring): disallow non-owner reads of keyhash (#15258) 2023-03-03 16:25:22 +00:00
depinject chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
docs docs: add adr/rfc section to contributing (#15385) 2023-03-21 12:11:56 +00:00
errors build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
fuzz chore: use sdkmath in misc packages (#14606) 2023-01-16 12:48:32 +00:00
internal refactor: create go.mod for store (#14746) 2023-01-25 13:31:56 +00:00
log build(deps): Bump github.com/mattn/go-isatty from 0.0.17 to 0.0.18 (#15509) 2023-03-22 17:42:29 +00:00
math fix(math): Dec marshal shouldn't have side effects (#15506) 2023-03-22 19:48:36 +00:00
orm build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
proto docs: improve proto vesting docs about time attributes (#15474) 2023-03-20 16:40:19 +00:00
runtime feat: Validate Msg proto annotations (#13793) 2023-03-20 16:27:36 +01:00
scripts ci: add changelog reminder (#15459) 2023-03-21 14:44:24 +01:00
server docs: replace Tendermint references in docs with CometBFT (#15339) 2023-03-14 20:41:35 +01:00
simapp build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
std fix: register evidence regression (#10595) 2021-12-14 14:25:31 +00:00
store build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
telemetry fix: all: fix resource leaks found by staticmajor (#13394) 2022-10-06 20:11:40 +00:00
tests fix(math): Dec marshal shouldn't have side effects (#15506) 2023-03-22 19:48:36 +00:00
testutil refactor: use app config configurator for removing boilerplate (#15499) 2023-03-22 07:29:33 +01:00
tools build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
types docs: update mempool Select godoc (#15486) 2023-03-20 21:09:14 +00:00
version test: add cmdtest package (#15251) 2023-03-06 19:40:24 +00:00
x build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
.clang-format chore: improve proto formatting (#12656) 2022-07-21 10:56:31 +00:00
.dockerignore Add basic Dockerfile to build all binaries and export gaiad 2018-04-10 12:39:47 +02:00
.gitattributes Merge PR #6426: Migrate API Server 2020-06-15 13:39:09 -04:00
.gitignore refactor!: ADR-038 go-plugin system (#14207) 2023-03-14 18:09:30 +00:00
.gitpod.yml Create .gitpod.yml (#12662) 2022-08-15 15:18:30 +02:00
.golangci.yml fix: correct path required proto testdata (#14991) 2023-02-11 16:59:16 +00:00
.goreleaser.yml ci: fix release notes not populated by goreleaser 2022-08-13 20:41:27 +02:00
.markdownlint.json docs: Code blocks in SDK docs are broken (#11189) 2022-02-14 23:39:35 +01:00
.markdownlintignore docs: Improve markdownlint configuration (#11104) 2022-02-10 12:07:01 +00:00
.mergify.yml chore: update .mergify.yml #13841 2022-11-11 18:49:36 +00:00
buf.work.yaml refactor: migrate to cosmos/gogoproto (#13070) 2022-09-08 17:27:48 +00:00
CHANGELOG.md fix: always reset the state for Prepare and Process Proposal (#15487) 2023-03-21 19:42:19 +00:00
cliff.toml ci: add changelog reminder (#15459) 2023-03-21 14:44:24 +01:00
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT.md (#7381) 2020-09-28 11:28:30 +02:00
CODING_GUIDELINES.md feat: migrate to docusaurus (#13471) 2022-10-10 14:01:53 +00:00
CONTRIBUTING.md docs: add adr/rfc section to contributing (#15385) 2023-03-21 12:11:56 +00:00
docker-compose.yml build: add remote debugging with delve (#10587) 2021-12-01 12:44:54 +00:00
Dockerfile build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
go.mod build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
go.sum build(deps): Bump google.golang.org/grpc from 1.53.0 to 1.54.0 (#15511) 2023-03-22 19:01:51 +00:00
go.work.example build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
LICENSE chore: update license copyright (#12542) 2022-07-13 10:19:10 +00:00
Makefile ci: add changelog reminder (#15459) 2023-03-21 14:44:24 +01:00
README.md build(deps): bump Go to v1.20 on SDK, simapp and standalone modules (#14979) 2023-02-09 11:56:07 -05:00
RELEASE_PROCESS.md docs: sync release process (#15505) 2023-03-22 16:17:13 +01:00
ROADMAP.md docs: update roadmap (#15493) 2023-03-21 12:47:31 +01:00
SECURITY.md docs: replace Tendermint references in docs with CometBFT (#15339) 2023-03-14 20:41:35 +01:00
sonar-project.properties ci: make sonarcloud more quiet (#14585) 2023-01-12 10:24:56 +00:00
UPGRADING.md chore: clarify some part in UPGRADING.md (#15345) 2023-03-10 17:25:03 +01:00

Cosmos SDK

banner

The Cosmos SDK is a framework for building blockchain applications. CometBFT (BFT Consensus) and the Cosmos SDK are written in the Go programming language. Cosmos SDK is used to build Gaia, the implementation of the Cosmos Hub.

WARNING: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes.

Note: Requires Go 1.20+

Quick Start

To learn how the Cosmos SDK works from a high-level perspective, see the Cosmos SDK High-Level Intro.

If you want to get started quickly and learn how to build on top of Cosmos SDK, visit Cosmos SDK Tutorials. You can also fork the tutorial's repository to get started building your own Cosmos SDK application.

For more information, see the Cosmos SDK Documentation.

Contributing

See CONTRIBUTING.md for details on how to contribute and participate in our dev calls. If you want to follow the updates or learn more about the latest design then join our Discord.

Tools and Frameworks

The Cosmos ecosystem is vast. Awesome Cosmos is a community-curated list of notable frameworks, modules and tools.

Cosmos Hub Mainnet

The Cosmos Hub application, gaia, has its own cosmos/gaia repository. Go there to join the Cosmos Hub mainnet and more.

Inter-Blockchain Communication (IBC)

The IBC module for the Cosmos SDK has its own cosmos/ibc-go repository. Go there to build and integrate with the IBC module.

Ignite CLI

Ignite CLI is the all-in-one platform to build, launch, and maintain any crypto application on a sovereign and secured blockchain. If you are building a new app or a new module, use Ignite CLI to get started and speed up development.

Disambiguation

This Cosmos SDK project is not related to the React-Cosmos project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.