Skip to content

Commit

Permalink
Merge pull request #5 from crypto-org-chain/objstore
Browse files Browse the repository at this point in the history
support object store
  • Loading branch information
yihuang committed Apr 8, 2024
2 parents 8581dfb + 6e5220a commit 9f11af1
Show file tree
Hide file tree
Showing 19 changed files with 770 additions and 584 deletions.
6 changes: 5 additions & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
)

func BenchmarkBlockSTM(b *testing.B) {
stores := []storetypes.StoreKey{StoreKeyAuth, StoreKeyBank}
stores := map[storetypes.StoreKey]int{StoreKeyAuth: 0, StoreKeyBank: 1}
for i := 0; i < 26; i++ {
key := storetypes.NewKVStoreKey(strconv.FormatInt(int64(i), 10))
stores[key] = i + 2
}
storage := NewMultiMemDB(stores)
testCases := []struct {
name string
Expand Down
21 changes: 9 additions & 12 deletions btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,20 @@ func (bt *BTree[T]) Scan(iter func(item T) bool) {
bt.Load().Scan(iter)
}

func (bt *BTree[T]) Min() (T, bool) {
return bt.Load().Min()
func (bt *BTree[T]) Max() (T, bool) {
return bt.Load().Max()
}

func (bt *BTree[T]) Iter() btree.IterG[T] {
return bt.Load().Iter()
}

func (bt *BTree[T]) Seek(item T) (result T, ok bool) {
iter := bt.Iter()
if !iter.Seek(item) {
iter.Release()
return
}

result = iter.Item()
ok = true
iter.Release()
// ReverseSeek returns the first item that is less than or equal to the pivot
func (bt *BTree[T]) ReverseSeek(pivot T) (result T, ok bool) {
bt.Load().Descend(pivot, func(item T) bool {
result = item
ok = true
return false
})
return
}
27 changes: 11 additions & 16 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package block_stm

import (
"context"

storetypes "cosmossdk.io/store/types"
)

// Executor fields are not mutated during execution.
type Executor struct {
ctx context.Context // context for cancellation
blockSize int // total number of transactions to execute
stores []storetypes.StoreKey // store names
scheduler *Scheduler // scheduler for task management
storage MultiStore // storage for the executor
txExecutor TxExecutor // callback to actually execute a transaction
mvMemory *MVMemory // multi-version memory for the executor
ctx context.Context // context for cancellation
blockSize int // total number of transactions to execute
scheduler *Scheduler // scheduler for task management
storage MultiStore // storage for the executor
txExecutor TxExecutor // callback to actually execute a transaction
mvMemory *MVMemory // multi-version memory for the executor

// index of the executor, used for debugging output
i int
Expand All @@ -23,7 +20,6 @@ type Executor struct {
func NewExecutor(
ctx context.Context,
blockSize int,
stores []storetypes.StoreKey,
scheduler *Scheduler,
storage MultiStore,
txExecutor TxExecutor,
Expand All @@ -33,7 +29,6 @@ func NewExecutor(
return &Executor{
ctx: ctx,
blockSize: blockSize,
stores: stores,
scheduler: scheduler,
storage: storage,
txExecutor: txExecutor,
Expand Down Expand Up @@ -73,8 +68,8 @@ func (e *Executor) Run() {

func (e *Executor) TryExecute(version TxnVersion) (TxnVersion, TaskKind) {
e.scheduler.executedTxns.Add(1)
readSet, writeSet := e.execute(version.Index)
wroteNewLocation := e.mvMemory.Record(version, readSet, writeSet)
view := e.execute(version.Index)
wroteNewLocation := e.mvMemory.Record(version, view)
return e.scheduler.FinishExecution(version, wroteNewLocation)
}

Expand All @@ -88,8 +83,8 @@ func (e *Executor) NeedsReexecution(version TxnVersion) (TxnVersion, TaskKind) {
return e.scheduler.FinishValidation(version.Index, aborted)
}

func (e *Executor) execute(txn TxnIndex) (MultiReadSet, MultiWriteSet) {
view := NewMultiMVMemoryView(e.stores, e.storage, e.mvMemory, e.scheduler, txn)
func (e *Executor) execute(txn TxnIndex) *MultiMVMemoryView {
view := e.mvMemory.View(txn, e.storage, e.scheduler)
e.txExecutor(txn, view)
return view.Result()
return view
}
41 changes: 21 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,64 @@ require (

require (
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.0 // indirect
cosmossdk.io/math v1.2.0 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0 // 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.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20231101195458-481da04154d6 // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/emicklei/dot v1.6.0 // indirect
github.com/getsentry/sentry-go v0.25.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.1 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.6 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/onsi/gomega v1.20.0 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/tidwall/btree => github.com/yihuang/btree v0.0.0-20240318010431-d365682df9a7
replace (
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240402064432-829c54275894
github.com/tidwall/btree => github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c
)
Loading

0 comments on commit 9f11af1

Please sign in to comment.