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

Use tendermint/tm-db #446

Merged
merged 1 commit into from
Jul 27, 2022
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ up-to-date.
When updating dependencies, please only update the particular dependencies you
need. Instead of running `go get -u=patch`, which will update anything,
specify exactly the dependency you want to update, eg.
`GO111MODULE=on go get -u github.com/line/tm-db@main`.
`GO111MODULE=on go get -u github.com/tendermint/tm-db@master`.

## Protobuf

Expand Down
5 changes: 2 additions & 3 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"encoding/json"
"fmt"

dbm "github.com/line/tm-db/v2"
"github.com/line/tm-db/v2/memdb"
dbm "github.com/tendermint/tm-db"

"github.com/line/ostracon/abci/example/code"
"github.com/line/ostracon/abci/types"
Expand Down Expand Up @@ -72,7 +71,7 @@ type Application struct {
}

func NewApplication() *Application {
state := loadState(memdb.NewDB())
state := loadState(dbm.NewMemDB())
return &Application{state: state}
}

Expand Down
5 changes: 3 additions & 2 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"strconv"
"strings"

dbm "github.com/tendermint/tm-db"

"github.com/line/ostracon/abci/example/code"
"github.com/line/ostracon/abci/types"
cryptoenc "github.com/line/ostracon/crypto/encoding"
"github.com/line/ostracon/libs/log"
pc "github.com/line/ostracon/proto/ostracon/crypto"
"github.com/line/tm-db/v2/goleveldb"
)

const (
Expand All @@ -36,7 +37,7 @@ type PersistentKVStoreApplication struct {

func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication {
name := "kvstore"
db, err := goleveldb.NewDB(name, dbDir)
db, err := dbm.NewGoLevelDB(name, dbDir)
if err != nil {
panic(err)
}
Expand Down
9 changes: 5 additions & 4 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"testing"
"time"

"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abci "github.com/line/ostracon/abci/types"
cfg "github.com/line/ostracon/config"
"github.com/line/ostracon/libs/log"
Expand Down Expand Up @@ -69,8 +70,8 @@ func newBlockchainReactor(
panic(fmt.Errorf("error start app: %w", err))
}

blockDB := memdb.NewDB()
stateDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
blockStore := store.NewBlockStore(blockDB)

Expand All @@ -83,7 +84,7 @@ func newBlockchainReactor(
// NOTE we have to create and commit the blocks first because
// pool.height is determined from the store.
fastSync := true
db := memdb.NewDB()
db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
Expand Down
9 changes: 5 additions & 4 deletions blockchain/v1/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"
"time"

"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abci "github.com/line/ostracon/abci/types"
cfg "github.com/line/ostracon/config"
"github.com/line/ostracon/libs/log"
Expand Down Expand Up @@ -99,8 +100,8 @@ func newBlockchainReactor(
panic(fmt.Errorf("error start app: %w", err))
}

blockDB := memdb.NewDB()
stateDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
blockStore := store.NewBlockStore(blockDB)

Expand All @@ -113,7 +114,7 @@ func newBlockchainReactor(
// NOTE we have to create and commit the blocks first because
// pool.height is determined from the store.
fastSync := true
db := memdb.NewDB()
db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
Expand Down
10 changes: 5 additions & 5 deletions blockchain/v2/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/line/ostracon/store"
"github.com/line/ostracon/types"
tmtime "github.com/line/ostracon/types/time"
"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
)

type mockPeer struct {
Expand Down Expand Up @@ -159,7 +159,7 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
if err != nil {
panic(fmt.Errorf("error start app: %w", err))
}
db := memdb.NewDB()
db := dbm.NewMemDB()
stateStore := sm.NewStore(db)
appl = sm.NewBlockExecutor(stateStore, p.logger, proxyApp.Consensus(), mock.Mempool{}, sm.EmptyEvidencePool{})
if err = stateStore.Save(state); err != nil {
Expand Down Expand Up @@ -505,15 +505,15 @@ func newReactorStore(
panic(fmt.Errorf("error start app: %w", err))
}

stateDB := memdb.NewDB()
blockStore := store.NewBlockStore(memdb.NewDB())
stateDB := dbm.NewMemDB()
blockStore := store.NewBlockStore(dbm.NewMemDB())
stateStore := sm.NewStore(stateDB)
state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
if err != nil {
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
}

db := memdb.NewDB()
db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
Expand Down
5 changes: 2 additions & 3 deletions cmd/ostracon/commands/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (

rpchttp "github.com/line/ostracon/rpc/client/http"

"github.com/line/tm-db/v2/goleveldb"
"github.com/spf13/cobra"

dbm "github.com/line/tm-db/v2"
dbm "github.com/tendermint/tm-db"

"github.com/line/ostracon/libs/log"
tmmath "github.com/line/ostracon/libs/math"
Expand Down Expand Up @@ -122,7 +121,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
witnessesAddrs = strings.Split(witnessAddrsJoined, ",")
}

db, err := goleveldb.NewDB("light-client-db", home)
db, err := dbm.NewGoLevelDB("light-client-db", home)
if err != nil {
return fmt.Errorf("can't create a db: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/ostracon/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/line/tm-db/v2/metadb"
dbm "github.com/tendermint/tm-db"

cfg "github.com/line/ostracon/config"
"github.com/line/ostracon/state"
Expand Down Expand Up @@ -53,17 +53,17 @@ func RollbackState(config *cfg.Config) (int64, []byte, error) {
}

func loadStateAndBlockStore(config *cfg.Config) (*store.BlockStore, state.Store, error) {
dbType := metadb.BackendType(config.DBBackend)
dbType := dbm.BackendType(config.DBBackend)

// Get BlockStore
blockStoreDB, err := metadb.NewDB("blockstore", dbType, config.DBDir())
blockStoreDB, err := dbm.NewDB("blockstore", dbType, config.DBDir())
if err != nil {
return nil, nil, err
}
blockStore := store.NewBlockStore(blockStoreDB)

// Get StateStore
stateDB, err := metadb.NewDB("state", dbType, config.DBDir())
stateDB, err := dbm.NewDB("state", dbType, config.DBDir())
if err != nil {
return nil, nil, err
}
Expand Down
11 changes: 1 addition & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/line/ostracon/privval"
"github.com/line/tm-db/v2/metadb"
)

const (
Expand Down Expand Up @@ -231,14 +230,6 @@ type BaseConfig struct { //nolint: maligned

// DefaultBaseConfig returns a default base configuration for an Ostracon node
func DefaultBaseConfig() BaseConfig {
dbs := metadb.AvailableDBBackends()
tnasu marked this conversation as resolved.
Show resolved Hide resolved
defaultDBBackend := DefaultDBBackend
for _, b := range dbs {
defaultDBBackend = string(b)
if defaultDBBackend == DefaultDBBackend {
break
}
}
return BaseConfig{
Genesis: defaultGenesisJSONPath,
PrivValidatorKey: defaultPrivValKeyPath,
Expand All @@ -251,7 +242,7 @@ func DefaultBaseConfig() BaseConfig {
LogFormat: LogFormatPlain,
FastSyncMode: true,
FilterPeers: false,
DBBackend: defaultDBBackend,
DBBackend: DefaultDBBackend,
DBPath: "data",
PrivKeyType: privval.PrivKeyTypeEd25519,
}
Expand Down
9 changes: 5 additions & 4 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"testing"
"time"

"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

config2 "github.com/line/ostracon/config"

abcicli "github.com/line/ostracon/abci/client"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {

for i := 0; i < nValidators; i++ {
logger := consensusLogger().With("test", "byzantine", "validator", i)
stateDB := memdb.NewDB() // each state needs its own db
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
Expand All @@ -60,7 +61,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
vals := types.OC2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})

blockDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
Expand All @@ -76,7 +77,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
}

// Make a full instance of the evidence pool
evidenceDB := memdb.NewDB()
evidenceDB := dbm.NewMemDB()
evpool, err := evidence.NewPool(evidenceDB, stateStore, blockStore)
require.NoError(t, err)
evpool.SetLogger(logger.With("module", "evidence"))
Expand Down
10 changes: 4 additions & 6 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import (
"time"

"github.com/go-kit/log/term"
"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/require"

dbm "github.com/line/tm-db/v2"
dbm "github.com/tendermint/tm-db"

abcicli "github.com/line/ostracon/abci/client"

"github.com/line/ostracon/abci/example/counter"
"github.com/line/ostracon/abci/example/kvstore"
abci "github.com/line/ostracon/abci/types"
Expand Down Expand Up @@ -409,7 +407,7 @@ func newStateWithConfig(
pv types.PrivValidator,
app abci.Application,
) *State {
blockDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
}

Expand Down Expand Up @@ -841,7 +839,7 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
logger := consensusLogger()
configRootDirs := make([]string, 0, nValidators)
for i := 0; i < nValidators; i++ {
stateDB := memdb.NewDB() // each state needs its own db
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
if err != nil {
Expand Down Expand Up @@ -919,7 +917,7 @@ func createPeersAndValidators(nValidators, nPeers int, testName string,
var peer0Config *cfg.Config
configRootDirs := make([]string, 0, nPeers)
for i := 0; i < nPeers; i++ {
stateDB := memdb.NewDB() // each state needs its own db
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
Expand Down
7 changes: 4 additions & 3 deletions consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"
"time"

"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

"github.com/line/ostracon/abci/example/code"
abci "github.com/line/ostracon/abci/types"
mempl "github.com/line/ostracon/mempool"
Expand Down Expand Up @@ -112,7 +113,7 @@ func deliverTxsRange(cs *State, start, end int) {

func TestMempoolTxConcurrentWithCommit(t *testing.T) {
state, privVals := randGenesisState(1, false, 10, nil)
blockDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
stateStore := sm.NewStore(blockDB)
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB)
err := stateStore.Save(state)
Expand All @@ -137,7 +138,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) {
func TestMempoolRmBadTx(t *testing.T) {
state, privVals := randGenesisState(1, false, 10, nil)
app := NewCounterApplication()
blockDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
stateStore := sm.NewStore(blockDB)
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB)
err := stateStore.Save(state)
Expand Down
7 changes: 4 additions & 3 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"testing"
"time"

"github.com/line/tm-db/v2/memdb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abcicli "github.com/line/ostracon/abci/client"
"github.com/line/ostracon/abci/example/kvstore"
abci "github.com/line/ostracon/abci/types"
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestReactorWithEvidence(t *testing.T) {
css := make([]*State, nValidators)
logger := consensusLogger()
for i := 0; i < nValidators; i++ {
stateDB := memdb.NewDB() // each state needs its own db
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
Expand All @@ -148,7 +149,7 @@ func TestReactorWithEvidence(t *testing.T) {
// duplicate code from:
// css[i] = newStateWithConfig(thisConfig, state, privVals[i], app)

blockDB := memdb.NewDB()
blockDB := dbm.NewMemDB()
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
Expand Down
Loading