forked from evmos/evmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.go
60 lines (50 loc) · 1.85 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
//go:build rocksdb
// +build rocksdb
package app
import (
"os"
"path/filepath"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/crypto-org-chain/cronos/versiondb/tsrocksdb"
)
// versionDB constant for 'versiondb'
// is same constant as in 'app/db_placeholder.go' but need to include it here too
// cause only one of these files ('db.go' or 'db_placeholder.go') will be
// included in the compiled binary depending on the build type (with or without rocksdb)
const versionDB = "versiondb"
// setupVersionDB sets up versionDB and
// returns the corresponding QueryMultiStore
// NOTE: this code is only included in a build with rocksdb.
// Otherwise, the setupVersionDB code on 'app/db_placeholder.go' will be included
// in the compiled binary
func (app *Evmos) setupVersionDB(
homePath string,
keys map[string]*storetypes.KVStoreKey,
tkeys map[string]*storetypes.TransientStoreKey,
memKeys map[string]*storetypes.MemoryStoreKey,
) (sdk.MultiStore, error) {
dataDir := filepath.Join(homePath, "data", versionDB)
if err := os.MkdirAll(dataDir, 0o750); err != nil {
return nil, err
}
store, err := tsrocksdb.NewStore(dataDir)
if err != nil {
return nil, err
}
// default to exposing all
exposeStoreKeys := make([]storetypes.StoreKey, 0, len(keys))
for _, storeKey := range keys {
exposeStoreKeys = append(exposeStoreKeys, storeKey)
}
service := versiondb.NewStreamingService(store, exposeStoreKeys)
app.SetStreamingService(service)
verDB := versiondb.NewMultiStore(app.CommitMultiStore(), store, exposeStoreKeys)
verDB.MountTransientStores(tkeys)
verDB.MountMemoryStores(memKeys)
app.SetQueryMultiStore(verDB)
return verDB, nil
}