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(store/v2): RootStore Implementation #17577

Merged
merged 54 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
089280f
updates
alexanderbez Aug 29, 2023
6f868c3
updates
alexanderbez Aug 29, 2023
54dd27a
updates
alexanderbez Aug 29, 2023
466d06f
updates
alexanderbez Aug 29, 2023
ee79932
updates
alexanderbez Aug 30, 2023
92e7767
updates
alexanderbez Sep 3, 2023
57b675f
updates
alexanderbez Sep 3, 2023
63e167b
updates
alexanderbez Sep 3, 2023
f8e9543
updates
alexanderbez Sep 3, 2023
61259cd
updates
alexanderbez Sep 5, 2023
b1c4d42
updates
alexanderbez Sep 5, 2023
e0d188d
updates
alexanderbez Sep 5, 2023
849413c
updates
alexanderbez Sep 5, 2023
cfc1c5f
updates
alexanderbez Sep 5, 2023
45da8a0
updates
alexanderbez Sep 6, 2023
71fd8b2
updates
alexanderbez Sep 6, 2023
a8c1bef
updates
alexanderbez Sep 6, 2023
1e9c0bd
updates
alexanderbez Sep 6, 2023
9869523
updates
alexanderbez Sep 6, 2023
499de87
updates
alexanderbez Sep 6, 2023
2601546
updates
alexanderbez Sep 6, 2023
4dd4c02
updates
alexanderbez Sep 6, 2023
e690be3
updates
alexanderbez Sep 7, 2023
b0b740b
updates
alexanderbez Sep 7, 2023
026c5e5
updates
alexanderbez Sep 7, 2023
73c48dd
updates
alexanderbez Sep 7, 2023
60b3f62
updates
alexanderbez Sep 7, 2023
6882953
updates
alexanderbez Sep 7, 2023
c5d8d27
updates
alexanderbez Sep 7, 2023
860c4a9
Merge branch 'feature/store-v2' into bez/multi-store-poc
alexanderbez Sep 8, 2023
d6a9ef8
updates
alexanderbez Sep 8, 2023
940e062
updates
alexanderbez Sep 10, 2023
d148d71
updates
alexanderbez Sep 10, 2023
a1a1105
updates
alexanderbez Sep 10, 2023
d1bf221
updates
alexanderbez Sep 10, 2023
e292c87
updates
alexanderbez Sep 10, 2023
c64d3f3
updates
alexanderbez Sep 11, 2023
6225e3e
updates
alexanderbez Sep 11, 2023
5588971
updates
alexanderbez Sep 11, 2023
000dca8
updates
alexanderbez Sep 11, 2023
5b65da5
updates
alexanderbez Sep 12, 2023
403f009
lint
alexanderbez Sep 12, 2023
d459bb1
updates
alexanderbez Sep 12, 2023
05a3170
updates
alexanderbez Sep 14, 2023
b830c93
updates
alexanderbez Sep 14, 2023
6b3fc00
updates
alexanderbez Sep 14, 2023
ecb5e91
updates
alexanderbez Sep 14, 2023
e0c423b
Merge branch 'feature/store-v2' into bez/multi-store-poc
alexanderbez Sep 27, 2023
aa335e7
updates
alexanderbez Sep 27, 2023
5e8d7ee
Merge branch 'feature/store-v2' into bez/multi-store-poc
alexanderbez Sep 27, 2023
01320e2
lint++
alexanderbez Sep 27, 2023
b6ab2fb
updates
alexanderbez Sep 27, 2023
451d994
refactor WorkingHash + Commit()
alexanderbez Sep 27, 2023
86efa09
updates
alexanderbez Sep 28, 2023
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
3 changes: 3 additions & 0 deletions store/commitment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# State Commitment (SC)

TODO
37 changes: 19 additions & 18 deletions store/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,66 @@ go 1.20
require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.0
cosmossdk.io/math v1.1.2
github.com/cockroachdb/errors v1.11.1
github.com/cockroachdb/pebble v0.0.0-20230819001538-1798fbf5956c
github.com/cometbft/cometbft v0.38.0-rc3
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/iavl v1.0.0-beta.2
github.com/cosmos/iavl v1.0.0-rc.1
github.com/cosmos/ics23/go v0.10.0
github.com/linxGnu/grocksdb v1.8.0
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
modernc.org/sqlite v1.25.0
)

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.8.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
github.com/cockroachdb/redact v1.0.8 // indirect
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/dot v1.4.2 // indirect
github.com/getsentry/sentry-go v0.21.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/petermattis/goid v0.0.0-20221215004737-a150e88a970d // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
306 changes: 77 additions & 229 deletions store/go.sum

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions store/internal/conv/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package conv

import (
"reflect"
"unsafe"
)

// UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes
// must not be altered after this function is called as it will cause a segmentation fault.
func UnsafeStrToBytes(s string) []byte {
var buf []byte
sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
Fixed Show fixed Hide fixed
bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
Fixed Show fixed Hide fixed
bufHdr.Data = sHdr.Data
bufHdr.Cap = sHdr.Len
bufHdr.Len = sHdr.Len
return buf
}

// UnsafeBytesToStr is meant to make a zero allocation conversion
// from []byte -> string to speed up operations, it is not meant
// to be used generally, but for a specific pattern to delete keys
// from a map.
func UnsafeBytesToStr(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
Fixed Show fixed Hide fixed
}
54 changes: 54 additions & 0 deletions store/internal/conv/string_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package conv

import (
"runtime"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/suite"
)

func TestStringSuite(t *testing.T) {
suite.Run(t, new(StringSuite))
}

type StringSuite struct{ suite.Suite }

func unsafeConvertStr() []byte {
return UnsafeStrToBytes("abc")
}

func (s *StringSuite) TestUnsafeStrToBytes() {
// we convert in other function to trigger GC. We want to check that
// the underlying array in []bytes is accessible after GC will finish swapping.
for i := 0; i < 5; i++ {
b := unsafeConvertStr()
runtime.GC()
<-time.NewTimer(2 * time.Millisecond).C
b2 := append(b, 'd')
s.Equal("abc", string(b))
s.Equal("abcd", string(b2))
}
}

func unsafeConvertBytes() string {
return UnsafeBytesToStr([]byte("abc"))
}

func (s *StringSuite) TestUnsafeBytesToStr() {
// we convert in other function to trigger GC. We want to check that
// the underlying array in []bytes is accessible after GC will finish swapping.
for i := 0; i < 5; i++ {
str := unsafeConvertBytes()
runtime.GC()
<-time.NewTimer(2 * time.Millisecond).C
s.Equal("abc", str)
}
}

func BenchmarkUnsafeStrToBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
UnsafeStrToBytes(strconv.Itoa(i))
}
}
17 changes: 17 additions & 0 deletions store/internal/kv/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kv

import "fmt"

// AssertKeyAtLeastLength panics when store key length is less than the given length.
func AssertKeyAtLeastLength(bz []byte, length int) {
if len(bz) < length {
panic(fmt.Sprintf("expected key of length at least %d, got %d", length, len(bz)))
}
}

// AssertKeyLength panics when store key length is not equal to the given length.
func AssertKeyLength(bz []byte, length int) {
if len(bz) != length {
panic(fmt.Sprintf("unexpected key length; got: %d, expected: %d", len(bz), length))
}
}
39 changes: 39 additions & 0 deletions store/internal/kv/kv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package kv

import (
"bytes"
"sort"
)

type (
Pair struct {
Key []byte
Value []byte
}

Pairs struct {
Pairs []Pair
}
)

func (kvs Pairs) Len() int { return len(kvs.Pairs) }
func (kvs Pairs) Less(i, j int) bool {
switch bytes.Compare(kvs.Pairs[i].Key, kvs.Pairs[j].Key) {
case -1:
return true

case 0:
return bytes.Compare(kvs.Pairs[i].Value, kvs.Pairs[j].Value) < 0

case 1:
return false

default:
panic("invalid comparison result")
}
}

func (kvs Pairs) Swap(i, j int) { kvs.Pairs[i], kvs.Pairs[j] = kvs.Pairs[j], kvs.Pairs[i] }

// Sort invokes sort.Sort on kvs.
func (kvs Pairs) Sort() { sort.Sort(kvs) }
13 changes: 13 additions & 0 deletions store/internal/maps/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package maps

import "testing"

func BenchmarkKVPairBytes(b *testing.B) {
kvp := NewKVPair(make([]byte, 128), make([]byte, 1e6))
b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
b.SetBytes(int64(len(kvp.Bytes())))
}
}
Loading
Loading