Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/v0.52.x' into check_header
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jan 9, 2025
2 parents aa0d57e + 6b943b2 commit 92761bd
Show file tree
Hide file tree
Showing 17 changed files with 631 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ We change the storage layout of the state machine, a storage hard fork and netwo

## Alternative designs

Most of the alternative designs were evaluated in [state commitments and storage report](https://paper.dropbox.com/published/State-commitments-and-storage-review--BDvA1MLwRtOx55KRihJ5xxLbBw-KeEB7eOd11pNrZvVtqUgL3h).

Ethereum research published [Verkle Trie](https://dankradfeist.de/ethereum/2021/06/18/verkle-trie-for-eth1.html) - an idea of combining polynomial commitments with merkle tree in order to reduce the tree height. This concept has a very good potential, but we think it's too early to implement it. The current, SMT based design could be easily updated to the Verkle Trie once other research implement all necessary libraries. The main advantage of the design described in this ADR is the separation of state commitments from the data storage and designing a more powerful interface.

## Further Discussions
Expand All @@ -280,7 +278,6 @@ We were discussing use case where modules can use a support database, which is n

* [IAVL What's Next?](https://github.com/cosmos/cosmos-sdk/issues/7100)
* [IAVL overview](https://docs.google.com/document/d/16Z_hW2rSAmoyMENO-RlAhQjAG3mSNKsQueMnKpmcBv0/edit#heading=h.yd2th7x3o1iv) of its state v0.15
* [State commitments and storage report](https://paper.dropbox.com/published/State-commitments-and-storage-review--BDvA1MLwRtOx55KRihJ5xxLbBw-KeEB7eOd11pNrZvVtqUgL3h)
* [Celestia (LazyLedger) SMT](https://github.com/lazyledger/smt)
* Facebook Diem (Libra) SMT [design](https://developers.diem.com/papers/jellyfish-merkle-tree/2021-01-14.pdf)
* [Trillian Revocation Transparency](https://github.com/google/trillian/blob/master/docs/papers/RevocationTransparency.pdf), [Trillian Verifiable Data Structures](https://github.com/google/trillian/blob/master/docs/papers/VerifiableDataStructures.pdf).
Expand Down
4 changes: 2 additions & 2 deletions docs/build/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ sidebar_position: 0

# Build

* [Building Apps](./building-apps/00-app-go.md) - The documentation in this section will guide you through the process of developing your dApp using the Cosmos SDK framework.
* [Modules](./modules/README.md) - Information about the various modules available in the Cosmos SDK: Auth, Authz, Bank, Crisis, Distribution, Evidence, Feegrant, Governance, Mint, Params, Slashing, Staking, Upgrade, NFT, Consensus, Circuit, Genutil.
* [Building Apps](./building-apps/00-runtime.md) - The documentation in this section will guide you through the process of developing your dApp using the Cosmos SDK framework.
* [Modules](./modules/README.md) - Information about the various modules available in the Cosmos SDK: Accounts, Auth, Authz, Bank, Circuit, Consensus, Distribution, Epochs, Evidence, Feegrant, Genutil, Governance, Group, Mint, NFT, Protocolpool, Slashing, Staking, Tx, Upgrade, Validate.
* [Migrations](./migrations/01-intro.md) - See what has been updated in each release the process of the transition between versions.
* [Packages](./packages/README.md) - Explore a curated collection of pre-built modules and functionalities, streamlining the development process.
* [Tooling](./tooling/README.md) - A suite of utilities designed to enhance the development workflow, optimizing the efficiency of Cosmos SDK-based projects.
Expand Down
2 changes: 1 addition & 1 deletion docs/build/building-apps/00-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ An application only needs to call `AppBuilder.Build` to create a fully configure
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/runtime/builder.go#L36-L80
```

More information on building applications can be found in the [next section](./02-app-building.md).
More information on building applications can be found in the [next section](./02-app-go-di.md).

## Best Practices

Expand Down
554 changes: 554 additions & 0 deletions docs/build/building-apps/upgrades/0.52.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/build/building-apps/upgrades/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"label": "Upgrade Tutorials",
"position": 0,
"link": null
}
2 changes: 1 addition & 1 deletion docs/build/building-modules/06-keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/keeper/keeper

Let us go through the different parameters:

* Environment is a struct that holds the necessary references to services available to the modules. This includes the [store services](../../advanced/04-store.md#store-services), the [event manager](../../learn/advanced/06-events.md) and more.
* Environment is a struct that holds the necessary references to services available to the modules. This includes the [kvstore services](../../learn/advanced/02-core.md#kvstore-service), the [event manager](../../learn/advanced/02-core.md#event-service) and more.
* An expected `keeper` is a `keeper` external to a module that is required by the internal `keeper` of said module. External `keeper`s are listed in the internal `keeper`'s type definition as interfaces. These interfaces are themselves defined in an `expected_keepers.go` file in the root of the module's folder. In this context, interfaces are used to reduce the number of dependencies, as well as to facilitate the maintenance of the module itself.
* `cdc` is the [codec](../../learn/advanced/05-encoding.md) used to marshal and unmarshal structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces.
* The authority listed is a module account or user account that has the right to change module level parameters. Previously this was handled by the param module, which has been deprecated.
Expand Down
2 changes: 1 addition & 1 deletion docs/build/building-modules/16-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The goal of these integration tests is to test how a component interacts with ot

Integration tests interact with the tested module via the defined `Msg` and `Query` services. The result of the test can be verified by checking the state of the application, by checking the emitted events or the response. It is advised to combine two of these methods to verify the result of the test.

The SDK provides small helpers for quickly setting up an integration tests. These helpers can be found at <https://github.com/cosmos/cosmos-sdk/blob/main/testutil/integration>.
The SDK provides small helpers for quickly setting up an integration tests. These helpers can be found at <https://github.com/cosmos/cosmos-sdk/blob/main/testutil>.

### Example

Expand Down
2 changes: 1 addition & 1 deletion docs/learn/advanced/00-baseapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Unconfirmed transactions are relayed to peers only if they pass `CheckTx`.
`CheckTx()` can perform both _stateful_ and _stateless_ checks, but developers should strive to
make the checks **lightweight** because gas fees are not charged for the resources (CPU, data load...) used during the `CheckTx`.

The [`Context`](../advanced/02-context.md), which includes a `GasMeter` that tracks how much gas is used during the execution of `Tx`, is initialized at the beginning of `CheckTx`. The user-provided amount of gas for `Tx` is referred to as `GasWanted`. If `GasConsumed`, the amount of gas used during execution, exceeds `GasWanted`, the execution is halted and the changes made to the cached copy of the state are not committed. Otherwise, `CheckTx` sets `GasUsed` equal to `GasConsumed` and returns it in the result. After calculating the gas and fee values, validator-nodes ensure that the user-specified `gas-prices` exceed their locally defined `min-gas-prices`.
The [`Core pkg`](../advanced/02-core.md), which includes a `GasService` that tracks how much gas is used during the execution of `Tx`, is initialized at the beginning of `CheckTx`. The user-provided amount of gas for `Tx` is referred to as `GasWanted`. If `GasConsumed`, the amount of gas used during execution, exceeds `GasWanted`, the execution is halted and the changes made to the cached copy of the state are not committed. Otherwise, `CheckTx` sets `GasUsed` equal to `GasConsumed` and returns it in the result. After calculating the gas and fee values, validator-nodes ensure that the user-specified `gas-prices` exceed their locally defined `min-gas-prices`.

In the Cosmos SDK, after [decoding transactions](./05-encoding.md), `CheckTx()` is implemented
to do the following checks:
Expand Down
6 changes: 0 additions & 6 deletions docs/learn/advanced/04-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ When methods of the parent `KVStore` are called, `GasKv.Store` automatically con
https://github.com/cosmos/cosmos-sdk/blob/store/v1.1.1/store/types/gas.go#L220-L229
```

By default, all `KVStores` are wrapped in `GasKv.Stores` when retrieved. This is done in the `KVStore()` method of the [`context`](./02-context.md):

```go reference
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/types/context.go#L339-L342
```

`KVStores` can be accessed in their corresponding modules by using the [`kvStoreService` and `memStoreService`](./02-core.md#kvstore-service).

### `TraceKv` Store
Expand Down
2 changes: 1 addition & 1 deletion docs/user/run-node/06-run-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ In the past, validators [have had issues](https://github.com/cosmos/cosmos-sdk/i

### Firewall

Nodes should not have all ports open to the public, this is a simple way to get DDOS'd. Secondly it is recommended by [CometBFT](github.com/cometbft/cometbft) to never expose ports that are not required to operate a node.
Nodes should not have all ports open to the public, this is a simple way to get DDOS'd. Secondly it is recommended by [CometBFT](https://github.com/cometbft/cometbft) to never expose ports that are not required to operate a node.

When setting up a firewall there are a few ports that can be open when operating a Cosmos SDK node. There is the CometBFT json-RPC, prometheus, p2p, remote signer and Cosmos SDK GRPC and REST. If the node is being operated as a node that does not offer endpoints to be used for submission or querying then a max of three endpoints are needed.

Expand Down
2 changes: 0 additions & 2 deletions scripts/build/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER := $(shell which docker)
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)

rocksdb_version=v9.6.1

ifeq ($(findstring .,$(VERSION)),)
VERSION := 0.0.0
endif
Expand Down
7 changes: 2 additions & 5 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

set -e

REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
export REPO_ROOT

LINT_TAGS="e2e,ledger,test_ledger_mock"
if [[ ! -z "${ROCKSDB:-}" ]]; then
LINT_TAGS+=",rocksdb"
fi
export LINT_TAGS

lint_module() {
Expand Down Expand Up @@ -58,4 +55,4 @@ else
echo "linting github.com/cosmos/cosmos-sdk [$(date -Iseconds -u)]"
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS}
fi
fi
fi
4 changes: 3 additions & 1 deletion x/bank/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances
func(key collections.Pair[sdk.AccAddress, string], value math.Int) (sdk.Coin, error) {
if req.ResolveDenom {
if metadata, ok := k.GetDenomMetaData(ctx, key.K2()); ok {
return sdk.NewCoin(metadata.Display, value), nil
if err := sdk.ValidateDenom(metadata.Display); err == nil {
return sdk.NewCoin(metadata.Display, value), nil
}
}
}
return sdk.NewCoin(key.K2(), value), nil
Expand Down
49 changes: 35 additions & 14 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ func (suite *KeeperTestSuite) TestQueryAllBalances() {
suite.Require().NotNil(res)
suite.True(res.Balances.IsZero())

fooCoins := newFooCoin(50)
barCoins := newBarCoin(30)
incompleteCoin := newIncompleteMetadataCoin(40)
fooCoins := newFooCoin(50)
ibcCoins := newIbcCoin(20)

origCoins := sdk.NewCoins(fooCoins, barCoins, ibcCoins)
// NewCoins will sort the Coins, so we prepare in alphabetical order to avoid confusion
origCoins := sdk.NewCoins(barCoins, incompleteCoin, fooCoins, ibcCoins)

suite.mockFundAccount(addr)
suite.Require().NoError(testutil.FundAccount(ctx, suite.bankKeeper, addr, origCoins))
Expand All @@ -133,10 +135,28 @@ func (suite *KeeperTestSuite) TestQueryAllBalances() {
res, err = queryClient.AllBalances(gocontext.Background(), req)
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Equal(res.Balances.Len(), 1)
suite.Equal(1, res.Balances.Len())
suite.Equal(barCoins.Denom, res.Balances[0].Denom)
suite.NotNil(res.Pagination.NextKey)

addIncompleteMetadata(ctx, suite.bankKeeper)
suite.T().Log("query second page with nextkey and resolve denom with incomplete metadata")
pageReq = &query.PageRequest{
Key: res.Pagination.NextKey,
Limit: 1,
CountTotal: true,
}
req = types.NewQueryAllBalancesRequest(addrStr, pageReq, true)
testFunc := func() {
res, err = queryClient.AllBalances(gocontext.Background(), req)
}
suite.Require().NotPanics(testFunc, "AllBalances with resolve denom + incomplete metadata")
suite.Require().NoError(err)
suite.Equal(1, res.Balances.Len())
suite.Equal(incompleteCoin.Denom, res.Balances[0].Denom)
suite.NotNil(res.Pagination.NextKey)

suite.T().Log("query second page with nextkey")
suite.T().Log("query third page with nextkey")
pageReq = &query.PageRequest{
Key: res.Pagination.NextKey,
Limit: 1,
Expand All @@ -145,34 +165,35 @@ func (suite *KeeperTestSuite) TestQueryAllBalances() {
req = types.NewQueryAllBalancesRequest(addrStr, pageReq, false)
res, err = queryClient.AllBalances(gocontext.Background(), req)
suite.Require().NoError(err)
suite.Equal(res.Balances.Len(), 1)
suite.Equal(1, res.Balances.Len())
suite.Equal(fooCoins.Denom, res.Balances[0].Denom)
suite.NotNil(res.Pagination.NextKey)

pageThree := res.Pagination.NextKey
pageFour := res.Pagination.NextKey

suite.T().Log("query third page with nextkey")
suite.T().Log("query fourth page with nextkey")
pageReq = &query.PageRequest{
Key: pageThree,
Key: pageFour,
Limit: 1,
CountTotal: true,
}
req = types.NewQueryAllBalancesRequest(addrStr, pageReq, false)
res, err = queryClient.AllBalances(gocontext.Background(), req)
suite.Require().NoError(err)
suite.Equal(res.Balances.Len(), 1)
suite.Equal(res.Balances[0].Denom, ibcCoins.Denom)
suite.Equal(1, res.Balances.Len())
suite.Equal(ibcCoins.Denom, res.Balances[0].Denom)

suite.T().Log("query third page with nextkey and resolve ibc denom")
suite.T().Log("query fourth page with nextkey and resolve ibc denom")
pageReq = &query.PageRequest{
Key: pageThree,
Key: pageFour,
Limit: 1,
CountTotal: true,
}
req = types.NewQueryAllBalancesRequest(addrStr, pageReq, true)
res, err = queryClient.AllBalances(gocontext.Background(), req)
suite.Require().NoError(err)
suite.Equal(res.Balances.Len(), 1)
suite.Equal(res.Balances[0].Denom, ibcPath+"/"+ibcBaseDenom)
suite.Equal(1, res.Balances.Len())
suite.Equal(ibcPath+"/"+ibcBaseDenom, res.Balances[0].Denom)
suite.Nil(res.Pagination.NextKey)
}

Expand Down
21 changes: 21 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
barDenom = "bar"
ibcPath = "transfer/channel-0"
ibcBaseDenom = "farboo"
incompleteBaseDenom = "incomplete"
incompletePath = "factory/someaddr"
metaDataDescription = "IBC Token from %s"
initialPower = int64(100)
holder = "holder"
Expand Down Expand Up @@ -83,6 +85,10 @@ func newIbcCoin(amt int64) sdk.Coin {
return sdk.NewInt64Coin(getIBCDenom(ibcPath, ibcBaseDenom), amt)
}

func newIncompleteMetadataCoin(amt int64) sdk.Coin {
return sdk.NewInt64Coin(incompletePath+"/"+incompleteBaseDenom, amt)
}

func getIBCDenom(path, baseDenom string) string {
return fmt.Sprintf("%s/%s", "ibc", hex.EncodeToString(getIBCHash(path, baseDenom)))
}
Expand All @@ -109,6 +115,21 @@ func addIBCMetadata(ctx context.Context, k keeper.BaseKeeper) {
k.SetDenomMetaData(ctx, metadata)
}

func addIncompleteMetadata(ctx context.Context, k keeper.BaseKeeper) {
metadata := banktypes.Metadata{
Description: "Incomplete metadata without display field",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: incompleteBaseDenom,
Exponent: 0,
},
},
Base: incompletePath + "/" + incompleteBaseDenom,
// Not setting any Display value
}
k.SetDenomMetaData(ctx, metadata)
}

type KeeperTestSuite struct {
suite.Suite

Expand Down
2 changes: 1 addition & 1 deletion x/staking/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getHistEntries(r *rand.Rand) uint32 {

// getKeyRotationFee returns randomized keyRotationFee between 10000-1000000.
func getKeyRotationFee(r *rand.Rand) sdk.Coin {
return sdk.NewInt64Coin(sdk.DefaultBondDenom, r.Int63n(types.DefaultKeyRotationFee.Amount.Int64()-10000)+10000)
return sdk.NewInt64Coin(sdk.DefaultBondDenom, r.Int63n(990000)+10000)
}

// RandomizedGenState generates a random GenesisState for staking
Expand Down
11 changes: 3 additions & 8 deletions x/staking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ const (
DefaultMaxEntries uint32 = 7
)

var (
// DefaultMinCommissionRate is set to 0%
DefaultMinCommissionRate = math.LegacyZeroDec()

// DefaultKeyRotationFee is fees used to rotate the ConsPubkey or Operator key
DefaultKeyRotationFee = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000)
)
// DefaultMinCommissionRate is set to 0%
var DefaultMinCommissionRate = math.LegacyZeroDec()

// NewParams creates a new Params instance
func NewParams(unbondingTime time.Duration,
Expand All @@ -60,7 +55,7 @@ func DefaultParams() Params {
DefaultMaxEntries,
sdk.DefaultBondDenom,
DefaultMinCommissionRate,
DefaultKeyRotationFee,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000), // fees used to rotate the ConsPubkey or Operator key
)
}

Expand Down

0 comments on commit 92761bd

Please sign in to comment.