Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store: Remove Amino #6984

Merged
merged 9 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion proto/cosmos/kv/kv.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
syntax = "proto3";
package cosmos.kv;

import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types/kv";

// Key-Value Pair
// Pairs defines a repeated slice of Pair objects.
message Pairs {
repeated Pair pairs = 1 [(gogoproto.nullable) = false];
}

// Pair defines a key/value bytes tuple.
message Pair {
bytes key = 1;
bytes value = 2;
Expand Down
29 changes: 29 additions & 0 deletions proto/cosmos/store/commit_info.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package cosmos.store;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this not be a top-level cosmos package. Isn't this really something internal to the SDK that clients or even people trying to re-implement the SDK in say rust would never use? We should have something like cosmos_sdk.internal for stuff like this. Or am I wrong and is this an essential part of consensus state and the app hash?

Copy link
Contributor

@amaury1093 amaury1093 Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that after #6905, we'll have a cosmos.base parent, so this can go as cosmos.base.store.v1beta1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @aaronc, it's used to compute the AppHash. I don't really care where this goes. If you have a preference on location, just let me know and I'll move it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put it where @amaurymartiny suggested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK


import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/store/types";

// CommitInfo defines commit information used by the multi-store when committing
// a version/height.
message CommitInfo {
int64 version = 1;
repeated StoreInfo store_infos = 2 [(gogoproto.nullable) = false];
}

// StoreInfo defines store-specific commit information. It contains a reference
// between a store name and the commit ID.
message StoreInfo {
string name = 1;
CommitID commit_id = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "CommitID"];
}

// CommitID defines the committment information when a specific store is
// committed.
message CommitID {
option (gogoproto.goproto_stringer) = false;

int64 version = 1;
bytes hash = 2;
}
15 changes: 11 additions & 4 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,25 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
res.Proof = getProofFromTree(mtree, req.Data, res.Value != nil)

case "/subspace":
var KVs []types.KVPair
pairs := kv.Pairs{
Pairs: make([]kv.Pair, 0),
}

subspace := req.Data
res.Key = subspace

iterator := types.KVStorePrefixIterator(st, subspace)
for ; iterator.Valid(); iterator.Next() {
KVs = append(KVs, types.KVPair{Key: iterator.Key(), Value: iterator.Value()})
pairs.Pairs = append(pairs.Pairs, kv.Pair{Key: iterator.Key(), Value: iterator.Value()})
}

iterator.Close()
res.Value = cdc.MustMarshalBinaryBare(KVs)

bz, err := pairs.Marshal()
if err != nil {
panic(fmt.Errorf("failed to marshal KV pairs: %w", err))
}

res.Value = bz

default:
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected query path: %v", req.Path))
Expand Down
31 changes: 21 additions & 10 deletions store/iavl/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/kv"
)

var (
Expand Down Expand Up @@ -408,18 +409,28 @@ func TestIAVLStoreQuery(t *testing.T) {
v3 := []byte("val3")

ksub := []byte("key")
KVs0 := []types.KVPair{}
KVs1 := []types.KVPair{
{Key: k1, Value: v1},
{Key: k2, Value: v2},
KVs0 := kv.Pairs{}
KVs1 := kv.Pairs{
Pairs: []kv.Pair{
{Key: k1, Value: v1},
{Key: k2, Value: v2},
},
}
KVs2 := []types.KVPair{
{Key: k1, Value: v3},
{Key: k2, Value: v2},
KVs2 := kv.Pairs{
Pairs: []kv.Pair{
{Key: k1, Value: v3},
{Key: k2, Value: v2},
},
}
valExpSubEmpty := cdc.MustMarshalBinaryBare(KVs0)
valExpSub1 := cdc.MustMarshalBinaryBare(KVs1)
valExpSub2 := cdc.MustMarshalBinaryBare(KVs2)

valExpSubEmpty, err := KVs0.Marshal()
require.NoError(t, err)

valExpSub1, err := KVs1.Marshal()
require.NoError(t, err)

valExpSub2, err := KVs2.Marshal()
require.NoError(t, err)

cid := iavlStore.Commit()
ver := cid.Version
Expand Down
7 changes: 0 additions & 7 deletions store/iavl/wire.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"

"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/kv"
)

Expand All @@ -19,7 +18,7 @@ type merkleMap struct {

func newMerkleMap() *merkleMap {
return &merkleMap{
kvs: nil,
kvs: kv.Pairs{},
sorted: false,
}
}
Expand All @@ -29,15 +28,15 @@ func newMerkleMap() *merkleMap {
// of kv.Pairs. Whenever called, the MerkleMap must be resorted.
func (sm *merkleMap) set(key string, value []byte) {
byteKey := []byte(key)
types.AssertValidKey(byteKey)
assertValidKey(byteKey)

sm.sorted = false

// The value is hashed, so you can check for equality with a cached value (say)
// and make a determination to fetch or not.
vhash := tmhash.Sum(value)

sm.kvs = append(sm.kvs, kv.Pair{
sm.kvs.Pairs = append(sm.kvs.Pairs, kv.Pair{
Key: byteKey,
Value: vhash,
})
Expand All @@ -61,8 +60,8 @@ func (sm *merkleMap) sort() {
// hashKVPairs hashes a kvPair and creates a merkle tree where the leaves are
// byte slices.
func hashKVPairs(kvs kv.Pairs) []byte {
kvsH := make([][]byte, len(kvs))
for i, kvp := range kvs {
kvsH := make([][]byte, len(kvs.Pairs))
for i, kvp := range kvs.Pairs {
kvsH[i] = KVPair(kvp).Bytes()
}

Expand All @@ -81,7 +80,7 @@ type simpleMap struct {

func newSimpleMap() *simpleMap {
return &simpleMap{
Kvs: nil,
Kvs: kv.Pairs{},
sorted: false,
}
}
Expand All @@ -90,15 +89,15 @@ func newSimpleMap() *simpleMap {
// and then appends it to SimpleMap's kv pairs.
func (sm *simpleMap) Set(key string, value []byte) {
byteKey := []byte(key)
types.AssertValidKey(byteKey)
assertValidKey(byteKey)
sm.sorted = false

// The value is hashed, so you can
// check for equality with a cached value (say)
// and make a determination to fetch or not.
vhash := tmhash.Sum(value)

sm.Kvs = append(sm.Kvs, kv.Pair{
sm.Kvs.Pairs = append(sm.Kvs.Pairs, kv.Pair{
Key: byteKey,
Value: vhash,
})
Expand All @@ -123,8 +122,11 @@ func (sm *simpleMap) Sort() {
// NOTE these contain the hashed key and value.
func (sm *simpleMap) KVPairs() kv.Pairs {
sm.Sort()
kvs := make(kv.Pairs, len(sm.Kvs))
copy(kvs, sm.Kvs)
kvs := kv.Pairs{
Pairs: make([]kv.Pair, len(sm.Kvs.Pairs)),
}

copy(kvs.Pairs, sm.Kvs.Pairs)
return kvs
}

Expand Down Expand Up @@ -188,18 +190,25 @@ func SimpleProofsFromMap(m map[string][]byte) ([]byte, map[string]*merkle.Simple

sm.Sort()
kvs := sm.Kvs
kvsBytes := make([][]byte, len(kvs))
for i, kvp := range kvs {
kvsBytes := make([][]byte, len(kvs.Pairs))
for i, kvp := range kvs.Pairs {
kvsBytes[i] = KVPair(kvp).Bytes()
}

rootHash, proofList := merkle.SimpleProofsFromByteSlices(kvsBytes)
proofs := make(map[string]*merkle.SimpleProof)
keys := make([]string, len(proofList))
for i, kvp := range kvs {

for i, kvp := range kvs.Pairs {
proofs[string(kvp.Key)] = proofList[i]
keys[i] = string(kvp.Key)
}

return rootHash, proofs, keys
}

func assertValidKey(key []byte) {
if len(key) == 0 {
panic("key is nil")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

ics23 "github.com/confio/ics23/go"

sdkmaps "github.com/cosmos/cosmos-sdk/store/rootmulti/internal/maps"
sdkmaps "github.com/cosmos/cosmos-sdk/store/internal/maps"
)

// TendermintSpec constrains the format from ics23-tendermint (crypto/merkle SimpleProof)
Expand Down
Loading