Skip to content

Commit

Permalink
Merge branch 'main' into marko/accounts_replaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 2, 2024
2 parents d230c79 + 496cd0d commit e8c8447
Show file tree
Hide file tree
Showing 180 changed files with 1,353 additions and 856 deletions.
10 changes: 9 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
/store/ @cool-develope @kocubinski @cosmos/sdk-core-dev
/store/v2/ @cool-develope @kocubinski @cosmos/sdk-core-dev
/types/mempool/ @kocubinski @cosmos/sdk-core-dev
/tools/hubl @julienrbrt @JulianToledano @cosmos/sdk-core-dev
/tools/cosmovisor @julienrbrt @facundomedica @cosmos/sdk-core-dev
/tools/confix @julienrbrt @akhilkumarpilli @cosmos/sdk-core-dev

# x modules

Expand All @@ -60,7 +63,12 @@
/x/tx/ @kocubinski @testinginprod @aaronc @cosmos/sdk-core-dev
/x/upgrade/ @facundomedica @cool-develope @akhilkumarpilli @lucaslopezf @cosmos/sdk-core-dev

# CODEOWNERS for docs configuration
# go mods

**/go.mod @cosmos/sdk-core-dev
**/go.sum @cosmos/sdk-core-dev

# docs configuration

/docs/ @cosmos/sdk-core-dev
/docs/docusaurus.config.js @julienrbrt @tac0turtle
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.
* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.
* (x/group) [#17937](https://github.com/cosmos/cosmos-sdk/pull/17937) Groups module was moved to its own go.mod `cosmossdk.io/x/group`
* (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress`
* (x/gov) [#18197](https://github.com/cosmos/cosmos-sdk/pull/18197) Gov module was moved to its own go.mod `cosmossdk.io/x/gov`
* (x/distribution) [#18199](https://github.com/cosmos/cosmos-sdk/pull/18199) Distribution module was moved to its own go.mod `cosmossdk.io/x/distribution`
* (x/slashing) [#18201](https://github.com/cosmos/cosmos-sdk/pull/18201) Slashing module was moved to its own go.mod `cosmossdk.io/x/slashing`
Expand Down
6 changes: 3 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/tmhash"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/core/header"
corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/store"
Expand Down Expand Up @@ -65,7 +65,7 @@ type BaseApp struct {
mu sync.Mutex // mu protects the fields below.
logger log.Logger
name string // application name from abci.BlockInfo
db dbm.DB // common DB backend
db corestore.KVStoreWithBatch // common DB backend
cms storetypes.CommitMultiStore // Main (uncached) state
qms storetypes.MultiStore // Optional alternative multistore for querying only.
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
Expand Down Expand Up @@ -194,7 +194,7 @@ type BaseApp struct {
// variadic number of option functions, which act on the BaseApp to set
// configuration choices.
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
name string, logger log.Logger, db corestore.KVStoreWithBatch, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
) *BaseApp {
app := &BaseApp{
logger: logger.With(log.ModuleKey, "baseapp"),
Expand Down
5 changes: 3 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/require"

corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/store/metrics"
Expand Down Expand Up @@ -296,7 +297,7 @@ func TestSetLoader(t *testing.T) {
app.SetStoreLoader(baseapp.DefaultStoreLoader)
}

initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
initStore := func(t *testing.T, db corestore.KVStoreWithBatch, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
Expand All @@ -317,7 +318,7 @@ func TestSetLoader(t *testing.T) {
require.Equal(t, int64(1), commitID.Version)
}

checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
checkStore := func(t *testing.T, db corestore.KVStoreWithBatch, ver int64, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))
Expand Down
5 changes: 2 additions & 3 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"io"
"math"

dbm "github.com/cosmos/cosmos-db"

corestore "cosmossdk.io/core/store"
"cosmossdk.io/store/metrics"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/snapshots"
Expand Down Expand Up @@ -178,7 +177,7 @@ func (app *BaseApp) SetAppVersion(ctx context.Context, v uint64) error {
return nil
}

func (app *BaseApp) SetDB(db dbm.DB) {
func (app *BaseApp) SetDB(db corestore.KVStoreWithBatch) {
if app.sealed {
panic("SetDB() on sealed BaseApp")
}
Expand Down
24 changes: 16 additions & 8 deletions baseapp/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ func (p listenerWrapper) ListenFinalizeBlock(_ context.Context, req abci.Finaliz

func (p listenerWrapper) ListenCommit(ctx context.Context, res abci.CommitResponse, changeSet []*storetypes.StoreKVPair) error {
if cb := p.listener.OnKVPair; cb != nil {
updates := make([]appdata.ModuleKVPairUpdate, len(changeSet))
updates := make([]appdata.ActorKVPairUpdate, len(changeSet))
for i, pair := range changeSet {
updates[i] = appdata.ModuleKVPairUpdate{
ModuleName: pair.StoreKey,
Update: schema.KVPairUpdate{
Key: pair.Key,
Value: pair.Value,
Delete: pair.Delete,
updates[i] = appdata.ActorKVPairUpdate{
Actor: []byte(pair.StoreKey),
StateChanges: []schema.KVPairUpdate{
{
Key: pair.Key,
Value: pair.Value,
Remove: pair.Delete,
},
},
}
}
Expand All @@ -181,10 +183,16 @@ func (p listenerWrapper) ListenCommit(ctx context.Context, res abci.CommitRespon
}

if p.listener.Commit != nil {
err := p.listener.Commit(appdata.CommitData{})
commitCb, err := p.listener.Commit(appdata.CommitData{})
if err != nil {
return err
}
if commitCb != nil {
err := commitCb()
if err != nil {
return err
}
}
}

return nil
Expand Down
22 changes: 18 additions & 4 deletions client/grpc/cmtservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
qtypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
)
Expand Down Expand Up @@ -73,10 +72,15 @@ func (s queryServer) GetLatestBlock(ctx context.Context, _ *GetLatestBlockReques
return nil, err
}

sdkBlock, err := convertBlock(protoBlock, s.clientCtx.ConsensusAddressCodec)
if err != nil {
return nil, err
}

return &GetLatestBlockResponse{
BlockId: &protoBlockID,
Block: protoBlock,
SdkBlock: convertBlock(protoBlock),
SdkBlock: sdkBlock,
}, nil
}

Expand All @@ -96,10 +100,15 @@ func (s queryServer) GetBlockByHeight(ctx context.Context, req *GetBlockByHeight
return nil, err
}

sdkBlock, err := convertBlock(protoBlock, s.clientCtx.ConsensusAddressCodec)
if err != nil {
return nil, err
}

return &GetBlockByHeightResponse{
BlockId: &protoBlockID,
Block: protoBlock,
SdkBlock: convertBlock(protoBlock),
SdkBlock: sdkBlock,
}, nil
}

Expand Down Expand Up @@ -177,8 +186,13 @@ func ValidatorsOutput(ctx context.Context, clientCtx client.Context, height *int
return nil, err
}

addr, err := clientCtx.ConsensusAddressCodec.BytesToString(v.Address)
if err != nil {
return nil, err
}

resp.Validators[i] = &Validator{
Address: sdk.ConsAddress(v.Address).String(),
Address: addr,
ProposerPriority: v.ProposerPriority,
PubKey: anyPub,
VotingPower: v.VotingPower,
Expand Down
24 changes: 16 additions & 8 deletions client/grpc/cmtservice/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package cmtservice
import (
cmtprototypes "github.com/cometbft/cometbft/api/cometbft/types/v1"

sdk "github.com/cosmos/cosmos-sdk/types"
"cosmossdk.io/core/address"
)

// convertHeader converts CometBFT header to sdk header
func convertHeader(h cmtprototypes.Header) Header {
func convertHeader(h cmtprototypes.Header, ac address.Codec) (Header, error) {
proposerAddr, err := ac.BytesToString(h.ProposerAddress)
if err != nil {
return Header{}, err
}

return Header{
Version: h.Version,
ChainID: h.ChainID,
Expand All @@ -22,18 +27,21 @@ func convertHeader(h cmtprototypes.Header) Header {
EvidenceHash: h.EvidenceHash,
LastResultsHash: h.LastResultsHash,
LastCommitHash: h.LastCommitHash,
ProposerAddress: sdk.ConsAddress(h.ProposerAddress).String(),
}
ProposerAddress: proposerAddr,
}, nil
}

// convertBlock converts CometBFT block to sdk block
func convertBlock(cmtblock *cmtprototypes.Block) *Block {
func convertBlock(cmtblock *cmtprototypes.Block, ac address.Codec) (*Block, error) {
b := new(Block)

b.Header = convertHeader(cmtblock.Header)
var err error
b.Header, err = convertHeader(cmtblock.Header, ac)
if err != nil {
return nil, err
}
b.LastCommit = cmtblock.LastCommit
b.Data = cmtblock.Data
b.Evidence = cmtblock.Evidence

return b
return b, nil
}
4 changes: 3 additions & 1 deletion client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func Test_runShowCmd(t *testing.T) {
require.NoError(t, err)
addr, err := k.GetAddress()
require.NoError(t, err)
addrStr, err := clientCtx.AddressCodec.BytesToString(addr)
require.NoError(t, err)
cmd.SetArgs([]string{
addr.String(),
addrStr,
fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome),
fmt.Sprintf("--%s=%s", FlagBechPrefix, sdk.PrefixAccount),
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
Expand Down
3 changes: 2 additions & 1 deletion client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

corestore "cosmossdk.io/core/store"
"cosmossdk.io/log"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/rootmulti"
Expand Down Expand Up @@ -107,7 +108,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
return cmd
}

func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) {
func openDB(rootDir string, backendType dbm.BackendType) (corestore.KVStoreWithBatch, error) {
dataDir := filepath.Join(rootDir, "data")
return dbm.NewDB("application", backendType, dataDir)
}
3 changes: 2 additions & 1 deletion client/snapshot/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"

corestore "cosmossdk.io/core/store"
"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -49,7 +50,7 @@ func RestoreSnapshotCmd[T servertypes.Application](appCreator servertypes.AppCre
return cmd
}

func openDB(rootDir string, backendType dbm.BackendType) (dbm.DB, error) {
func openDB(rootDir string, backendType dbm.BackendType) (corestore.KVStoreWithBatch, error) {
dataDir := filepath.Join(rootDir, "data")
return dbm.NewDB("application", backendType, dataDir)
}
28 changes: 15 additions & 13 deletions client/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ type TestAccountRetriever struct {
}

// GetAccount implements AccountRetriever.GetAccount
func (t TestAccountRetriever) GetAccount(_ Context, addr sdk.AccAddress) (Account, error) {
acc, ok := t.Accounts[addr.String()]
func (t TestAccountRetriever) GetAccount(clientCtx Context, addr sdk.AccAddress) (Account, error) {
addrStr, err := clientCtx.AddressCodec.BytesToString(addr)
if err != nil {
return nil, err
}

acc, ok := t.Accounts[addrStr]
if !ok {
return nil, fmt.Errorf("account: account %s not found", addr)
}
Expand All @@ -65,19 +70,16 @@ func (t TestAccountRetriever) GetAccountWithHeight(clientCtx Context, addr sdk.A
}

// EnsureExists implements AccountRetriever.EnsureExists
func (t TestAccountRetriever) EnsureExists(_ Context, addr sdk.AccAddress) error {
_, ok := t.Accounts[addr.String()]
if !ok {
return fmt.Errorf("ensureExists: account %s not found", addr)
}
return nil
func (t TestAccountRetriever) EnsureExists(clientCtx Context, addr sdk.AccAddress) error {
_, err := t.GetAccount(clientCtx, addr)
return err
}

// GetAccountNumberSequence implements AccountRetriever.GetAccountNumberSequence
func (t TestAccountRetriever) GetAccountNumberSequence(_ Context, addr sdk.AccAddress) (accNum, accSeq uint64, err error) {
acc, ok := t.Accounts[addr.String()]
if !ok {
return 0, 0, fmt.Errorf("accountNumberSequence: account %s not found", addr)
func (t TestAccountRetriever) GetAccountNumberSequence(clientCtx Context, addr sdk.AccAddress) (accNum, accSeq uint64, err error) {
acc, err := t.GetAccount(clientCtx, addr)
if err != nil {
return 0, 0, err
}
return acc.Num, acc.Seq, nil
return acc.GetAccountNumber(), acc.GetSequence(), nil
}
11 changes: 6 additions & 5 deletions client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const (

var (
_, pub1, addr1 = testdata.KeyTestPubAddr()
addr1Str, _ = testutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
rawSig = []byte("dummy")
msg1 = &countertypes.MsgIncreaseCounter{Signer: addr1.String(), Count: 1}
msg1 = &countertypes.MsgIncreaseCounter{Signer: addr1Str, Count: 1}

chainID = "test-chain"
)
Expand Down Expand Up @@ -131,7 +132,7 @@ func TestAuxTxBuilder(t *testing.T) {
func() error {
require.NoError(t, b.SetMsgs(msg1))
require.NoError(t, b.SetPubKey(pub1))
b.SetAddress(addr1.String())
b.SetAddress(addr1Str)
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))

_, err := b.GetSignBytes()
Expand All @@ -152,7 +153,7 @@ func TestAuxTxBuilder(t *testing.T) {
b.SetChainID(chainID)
require.NoError(t, b.SetMsgs(msg1))
require.NoError(t, b.SetPubKey(pub1))
b.SetAddress(addr1.String())
b.SetAddress(addr1Str)
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
require.NoError(t, err)

Expand All @@ -174,7 +175,7 @@ func TestAuxTxBuilder(t *testing.T) {
func() error {
require.NoError(t, b.SetMsgs(msg1))
require.NoError(t, b.SetPubKey(pub1))
b.SetAddress(addr1.String())
b.SetAddress(addr1Str)
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
require.NoError(t, err)

Expand All @@ -193,7 +194,7 @@ func TestAuxTxBuilder(t *testing.T) {
b.SetChainID(chainID)
require.NoError(t, b.SetMsgs(msg1))
require.NoError(t, b.SetPubKey(pub1))
b.SetAddress(addr1.String())
b.SetAddress(addr1Str)
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
require.NoError(t, err)

Expand Down
Loading

0 comments on commit e8c8447

Please sign in to comment.