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

feat: Remove the store/internal module #18944

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
39 changes: 29 additions & 10 deletions store/commit_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package store

import (
"fmt"
"sort"
"time"

"cosmossdk.io/store/v2/internal/maps"
)

type (
Expand All @@ -14,6 +13,7 @@ type (
Version uint64
StoreInfos []StoreInfo
Timestamp time.Time
CommitHash []byte
}

// StoreInfo defines store-specific commit information. It contains a reference
Expand All @@ -37,25 +37,44 @@ func (si StoreInfo) GetHash() []byte {

// Hash returns the root hash of all committed stores represented by CommitInfo,
// sorted by store name/key.
func (ci CommitInfo) Hash() []byte {
func (ci *CommitInfo) Hash() []byte {
if len(ci.StoreInfos) == 0 {
return nil
}

rootHash, _, _ := maps.ProofsFromMap(ci.toMap())
if len(ci.CommitHash) != 0 {
return ci.CommitHash
}

rootHash, _, _ := ci.GetStoreProof("")
return rootHash
}

func (ci CommitInfo) toMap() map[string][]byte {
m := make(map[string][]byte, len(ci.StoreInfos))
for _, storeInfo := range ci.StoreInfos {
m[storeInfo.Name] = storeInfo.GetHash()
func (ci *CommitInfo) GetStoreProof(storeKey string) ([]byte, *CommitmentOp, error) {
sort.Slice(ci.StoreInfos, func(i, j int) bool {
return ci.StoreInfos[i].Name < ci.StoreInfos[j].Name
})

index := 0
leaves := make([][]byte, len(ci.StoreInfos))
for i, si := range ci.StoreInfos {
var err error
leaves[i], err = LeafHash([]byte(si.Name), si.GetHash())
if err != nil {
return nil, nil, err
}
if si.Name == storeKey {
index = i
}
}

return m
rootHash, inners := ProofFromByteSlices(leaves, index)
commitmentOp := ConvertCommitmentOp(inners, []byte(storeKey), ci.StoreInfos[index].GetHash())

return rootHash, &commitmentOp, nil
}

func (ci CommitInfo) CommitID() CommitID {
func (ci *CommitInfo) CommitID() CommitID {
return CommitID{
Version: ci.Version,
Hash: ci.Hash(),
Expand Down
1 change: 0 additions & 1 deletion store/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
cosmossdk.io/core v0.12.0
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.2.0
github.com/cockroachdb/errors v1.11.1
github.com/cockroachdb/pebble v1.0.0
github.com/cometbft/cometbft v0.38.2
Expand Down
2 changes: 0 additions & 2 deletions store/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04=
cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0=
cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down
17 changes: 0 additions & 17 deletions store/internal/kv/helpers.go

This file was deleted.

39 changes: 0 additions & 39 deletions store/internal/kv/kv.go

This file was deleted.

13 changes: 0 additions & 13 deletions store/internal/maps/bench_test.go

This file was deleted.

216 changes: 0 additions & 216 deletions store/internal/maps/maps.go

This file was deleted.

Loading