From fe6e09abd31d69ae1746673cadb93fa3217163e9 Mon Sep 17 00:00:00 2001 From: p4u Date: Tue, 5 Sep 2023 17:18:46 +0200 Subject: [PATCH] add mongodb implementation for the db package The db interface has now an implementation for mongodb. So instead of pebble a user or consumer of the vocdoni-node API can choose to use mongodb. Its not faster than local KV, but useful when the host runing the database has no persistent storage available, so a remote storage is required. The mongodb url must be set on a env var, such as: MONGODB_URL="mongodb://root:vocdoni@localhost:27017/" go run ./cmd/node -t mongodb -c dev Signed-off-by: p4u --- api/api.go | 9 +- api/census_test.go | 6 +- benchmark/zk_census_benchmark_test.go | 2 +- cmd/node/main.go | 8 +- config/config.go | 12 -- db/interface.go | 1 + db/internal/dbtest/dbtest.go | 2 + db/metadb/metadb.go | 9 +- db/mongodb/docker-compose-mongo.yml | 22 +++ db/mongodb/mongodb.go | 225 ++++++++++++++++++++++++++ db/mongodb/mongodb_test.go | 112 +++++++++++++ go.mod | 6 + go.sum | 15 ++ test/testcommon/api.go | 2 +- vocone/vocone.go | 2 +- 15 files changed, 406 insertions(+), 27 deletions(-) create mode 100644 db/mongodb/docker-compose-mongo.yml create mode 100644 db/mongodb/mongodb.go create mode 100644 db/mongodb/mongodb_test.go diff --git a/api/api.go b/api/api.go index 8c2f2892b..26659f279 100644 --- a/api/api.go +++ b/api/api.go @@ -15,6 +15,7 @@ import ( "go.vocdoni.io/dvote/data" "go.vocdoni.io/dvote/db" "go.vocdoni.io/dvote/db/metadb" + "go.vocdoni.io/dvote/db/prefixeddb" "go.vocdoni.io/dvote/httprouter" "go.vocdoni.io/dvote/httprouter/apirest" "go.vocdoni.io/dvote/vochain" @@ -75,10 +76,13 @@ type API struct { } // NewAPI creates a new instance of the API. Attach must be called next. -func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir string) (*API, error) { +func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir, dbType string) (*API, error) { if router == nil { return nil, ErrHTTPRouterIsNil } + if dbType == "" { + dbType = db.TypePebble + } if len(baseRoute) == 0 || baseRoute[0] != '/' { return nil, fmt.Errorf("%w (invalid given: %s)", ErrBaseRouteInvalid, baseRoute) } @@ -95,10 +99,11 @@ func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir string) (*API, err if err != nil { return nil, err } - api.db, err = metadb.New(db.TypePebble, filepath.Join(dataDir, "db")) + mdb, err := metadb.New(dbType, filepath.Join(dataDir, "db")) if err != nil { return nil, err } + api.db = prefixeddb.NewPrefixedDatabase(mdb, []byte("api/")) return &api, nil } diff --git a/api/census_test.go b/api/census_test.go index 5fbc02055..891ee2a13 100644 --- a/api/census_test.go +++ b/api/census_test.go @@ -32,7 +32,7 @@ func TestCensus(t *testing.T) { addr, err := url.Parse("http://" + path.Join(router.Address().String(), "censuses")) qt.Assert(t, err, qt.IsNil) - api, err := NewAPI(&router, "/", t.TempDir()) + api, err := NewAPI(&router, "/", t.TempDir(), db.TypePebble) qt.Assert(t, err, qt.IsNil) // Create local key value database @@ -162,7 +162,7 @@ func TestCensusProof(t *testing.T) { addr, err := url.Parse("http://" + path.Join(router.Address().String(), "censuses")) qt.Assert(t, err, qt.IsNil) - api, err := NewAPI(&router, "/", t.TempDir()) + api, err := NewAPI(&router, "/", t.TempDir(), db.TypePebble) qt.Assert(t, err, qt.IsNil) // Create local key value database db, err := metadb.New(db.TypePebble, t.TempDir()) @@ -248,7 +248,7 @@ func TestCensusZk(t *testing.T) { addr, err := url.Parse("http://" + path.Join(router.Address().String(), "censuses")) c.Assert(err, qt.IsNil) - testApi, err := NewAPI(&router, "/", t.TempDir()) + testApi, err := NewAPI(&router, "/", t.TempDir(), db.TypePebble) c.Assert(err, qt.IsNil) // Create local key value database diff --git a/benchmark/zk_census_benchmark_test.go b/benchmark/zk_census_benchmark_test.go index 81b94cdaa..f79c92c01 100644 --- a/benchmark/zk_census_benchmark_test.go +++ b/benchmark/zk_census_benchmark_test.go @@ -35,7 +35,7 @@ func BenchmarkZkCensus(b *testing.B) { router := httprouter.HTTProuter{} router.Init("127.0.0.1", 0) - vocApi, err := api.NewAPI(&router, "/", b.TempDir()) + vocApi, err := api.NewAPI(&router, "/", b.TempDir(), db.TypePebble) qt.Assert(b, err, qt.IsNil) // Create local key value database diff --git a/cmd/node/main.go b/cmd/node/main.go index 1136216c9..2c2c68f19 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -75,7 +75,7 @@ func newConfig() (*config.Config, config.Error) { flag.StringVarP(&globalCfg.DataDir, "dataDir", "d", home+"/.vocdoni", "directory where data is stored") flag.StringVarP(&globalCfg.Vochain.DBType, "dbType", "t", db.TypePebble, - fmt.Sprintf("key-value db type (%s)", db.TypePebble)) + fmt.Sprintf("key-value db type [%s,%s,%s]", db.TypePebble, db.TypeLevelDB, db.TypeMongo)) flag.StringVarP(&globalCfg.Vochain.Chain, "chain", "c", "dev", fmt.Sprintf("vocdoni blockchain to connect with: %q", genesis.AvailableChains())) flag.BoolVar(&globalCfg.Dev, "dev", false, @@ -361,10 +361,6 @@ func main() { if !globalCfg.ValidMode() { log.Fatalf("mode %s is invalid", globalCfg.Mode) } - // Check the dbType is valid - if !globalCfg.Vochain.ValidDBType() { - log.Fatalf("dbType %s is invalid. Valid ones: %s", globalCfg.Vochain.DBType, db.TypePebble) - } // If dev enabled, expose debugging profiles under an http server // If PprofPort is not set, a random port between 61000 and 61100 is choosed. @@ -531,7 +527,7 @@ func main() { // HTTP API REST service if globalCfg.EnableAPI { log.Info("enabling API") - uAPI, err := urlapi.NewAPI(srv.Router, "/v2", globalCfg.DataDir) + uAPI, err := urlapi.NewAPI(srv.Router, "/v2", globalCfg.DataDir, globalCfg.Vochain.DBType) if err != nil { log.Fatal(err) } diff --git a/config/config.go b/config/config.go index 7b6543349..5d2c5ad54 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,6 @@ package config import ( - "go.vocdoni.io/dvote/db" "go.vocdoni.io/dvote/types" ) @@ -61,17 +60,6 @@ func (c *Config) ValidMode() bool { return true } -// ValidDBType checks if the configured dbType is valid -func (c *VochainCfg) ValidDBType() bool { - switch c.DBType { - case db.TypePebble: - - default: - return false - } - return true -} - // NewConfig initializes the fields in the config stuct. func NewConfig() *Config { return &Config{ diff --git a/db/interface.go b/db/interface.go index 7aa1c37c6..c27724a92 100644 --- a/db/interface.go +++ b/db/interface.go @@ -9,6 +9,7 @@ import ( const ( TypePebble = "pebble" TypeLevelDB = "leveldb" + TypeMongo = "mongodb" ) // ErrKeyNotFound is used to indicate that a key does not exist in the db. diff --git a/db/internal/dbtest/dbtest.go b/db/internal/dbtest/dbtest.go index 182f4ed92..b60835c3c 100644 --- a/db/internal/dbtest/dbtest.go +++ b/db/internal/dbtest/dbtest.go @@ -32,6 +32,8 @@ func TestWriteTx(t *testing.T, database db.Database) { // Discard should not give any problem wTx.Discard() + qt.Assert(t, err, qt.IsNil) + // get value from a new db after the previous commit wTx = database.WriteTx() v, err = wTx.Get([]byte("a")) diff --git a/db/metadb/metadb.go b/db/metadb/metadb.go index 09f4afb71..19e96003e 100644 --- a/db/metadb/metadb.go +++ b/db/metadb/metadb.go @@ -7,6 +7,7 @@ import ( "go.vocdoni.io/dvote/db" "go.vocdoni.io/dvote/db/goleveldb" + "go.vocdoni.io/dvote/db/mongodb" "go.vocdoni.io/dvote/db/pebbledb" ) @@ -25,8 +26,14 @@ func New(typ, dir string) (db.Database, error) { if err != nil { return nil, err } + case db.TypeMongo: + database, err = mongodb.New(opts) + if err != nil { + return nil, err + } default: - return nil, fmt.Errorf("invalid dbType: %q. Available types: %q", typ, db.TypePebble) + return nil, fmt.Errorf("invalid dbType: %q. Available types: %q %q %q", + typ, db.TypePebble, db.TypeLevelDB, db.TypeMongo) } return database, nil } diff --git a/db/mongodb/docker-compose-mongo.yml b/db/mongodb/docker-compose-mongo.yml new file mode 100644 index 000000000..eb63dc273 --- /dev/null +++ b/db/mongodb/docker-compose-mongo.yml @@ -0,0 +1,22 @@ +version: '3.1' + +services: + + mongo: + image: 'bitnami/mongodb:latest' + restart: ${RESTART:-no} + ports: + - 27017:27017 + environment: + - MONGODB_USERNAME=root + - MONGODB_PASSWORD=vocdoni + - MONGODB_DATABASE=vocdoni + - MONGODB_ROOT_PASSWORD=vocdoni + volumes: + - mongodb:/bitnami/mongodb + +# MONGODB_URL=mongodb://root:vocdoni@mongo:27017/ +# MONGODB_URL=mongodb://root:vocdoni@127.0.0.1:27017/ + +volumes: + mongodb: {} diff --git a/db/mongodb/mongodb.go b/db/mongodb/mongodb.go new file mode 100644 index 000000000..ff9d438d6 --- /dev/null +++ b/db/mongodb/mongodb.go @@ -0,0 +1,225 @@ +package mongodb + +import ( + "context" + "crypto/sha256" + "fmt" + "os" + "strings" + "time" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readpref" + "go.vocdoni.io/dvote/db" + "go.vocdoni.io/dvote/log" +) + +const ( + // MongodbTimeoutConnect is the timeout for connecting to the database + MongodbTimeoutConnect = 10 * time.Second + // MongodbTimeoutCommit is the timeout for committing a batch transaction + MongodbTimeoutCommit = 12 * time.Second + // MongodbTimeoutQuery is the timeout for querying the database + MongodbTimeoutQuery = 4 * time.Second +) + +// MongoDB is a MongoDB implementation of the db.DB interface +type MongoDB struct { + db *mongo.Database + collection string +} + +type KeyVal struct { + Key string `bson:"_id" json:"key"` // needs to be an ugly string because of regex + Value []byte `bson:"value" json:"value"` +} + +func New(opts db.Options) (*MongoDB, error) { + url := os.Getenv("MONGODB_URL") + + if url == "" { + return nil, fmt.Errorf("missing MONGODB_URL env var") + } + // we use the path as the collection name (and we hash it to avoid invalid chars) + collection := fmt.Sprintf("%x", sha256.Sum256([]byte(opts.Path)))[:12] + log.Debugw("connecting to mongo database", "url", url, "collection", collection) + clientOptions := options.Client().ApplyURI(url).SetMaxConnecting(20) + ctx, cancel := context.WithTimeout(context.Background(), MongodbTimeoutConnect) + defer cancel() + client, err := mongo.Connect(ctx, clientOptions) + if err != nil { + return nil, err + } + database := client.Database(collection) + + err = client.Ping(ctx, readpref.Primary()) + if err != nil { + return nil, fmt.Errorf("cannot connect to mongodb: %w", err) + } + + return &MongoDB{db: database, collection: collection}, nil +} + +func (d *MongoDB) Close() error { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + return d.db.Client().Disconnect(ctx) +} + +func (d *MongoDB) WriteTx() db.WriteTx { + return &WriteTx{ + db: d.db, + inMem: make(map[string][]byte), + collection: d.collection, + } +} + +func (d *MongoDB) Get(key []byte) ([]byte, error) { + tx := d.WriteTx() + defer tx.Discard() + return tx.Get(key) +} + +func (d *MongoDB) Iterate(prefix []byte, callback func(key, value []byte) bool) error { + tx := d.WriteTx() + defer tx.Discard() + return tx.Iterate(prefix, callback) +} + +func (d *MongoDB) Compact() error { + // MongoDB handles compaction automatically, so this is a no-op. + return nil +} + +// check that WriteTx implements the db.WriteTx interface +var _ db.WriteTx = (*WriteTx)(nil) + +type WriteTx struct { + db *mongo.Database + batch []mongo.WriteModel + inMem map[string][]byte + collection string +} + +func (tx *WriteTx) Get(k []byte) ([]byte, error) { + if val, ok := tx.inMem[string(k)]; ok { + return val, nil + } + collection := tx.db.Collection(tx.collection) + + filter := bson.M{"_id": string(k)} // Convert to string + var result KeyVal + ctx, cancel := context.WithTimeout(context.Background(), MongodbTimeoutQuery) + defer cancel() + err := collection.FindOne(ctx, filter).Decode(&result) + if err == mongo.ErrNoDocuments { + return nil, db.ErrKeyNotFound + } + return result.Value, err +} + +func (tx *WriteTx) Iterate(prefix []byte, callback func(key, value []byte) bool) error { + // First, handle in-memory keys + for k, v := range tx.inMem { + if strings.HasPrefix(k, string(prefix)) { + if !callback([]byte(k), v) { + return nil + } + } + } + + // Now, handle database keys, but skip those already handled from in-memory map + collection := tx.db.Collection(tx.collection) + + filter := bson.M{} + if len(prefix) > 0 { + filter = bson.M{ + "_id": bson.M{ + "$regex": primitive.Regex{ + Pattern: "^" + string(prefix), + }, + }, + } + } + cursor, err := collection.Find(context.TODO(), filter) + if err != nil { + return err + } + defer cursor.Close(context.TODO()) + + for cursor.Next(context.TODO()) { + var kv KeyVal + err := cursor.Decode(&kv) + if err != nil { + return err + } + if _, exists := tx.inMem[kv.Key]; exists { + continue + } + if !callback([]byte(kv.Key), kv.Value) { + break + } + } + return nil +} + +func (tx *WriteTx) Set(k, v []byte) error { + if tx.inMem == nil { + tx.inMem = make(map[string][]byte) + } + update := bson.D{ + primitive.E{Key: "$set", Value: bson.D{ + primitive.E{Key: "value", Value: v}, + }}, + } + model := mongo.NewUpdateOneModel().SetFilter( + bson.D{ + primitive.E{ + Key: "_id", + Value: string(k), + }, + }, + ).SetUpsert(true).SetUpdate(update) + + tx.batch = append(tx.batch, model) + tx.inMem[string(k)] = v + return nil +} + +func (tx *WriteTx) Delete(k []byte) error { + model := mongo.NewDeleteOneModel().SetFilter(bson.M{"_id": string(k)}) // Convert to string + tx.batch = append(tx.batch, model) + delete(tx.inMem, string(k)) + return nil +} + +func (tx *WriteTx) Apply(other db.WriteTx) error { + var err2 error + err := other.Iterate(nil, func(k, v []byte) bool { + err2 = tx.Set(k, v) + return err2 == nil + }) + if err2 != nil { + return err2 + } + return err +} + +func (tx *WriteTx) Commit() error { + if len(tx.batch) == 0 { + return nil + } + ctx, cancel := context.WithTimeout(context.Background(), MongodbTimeoutCommit) + defer cancel() + collection := tx.db.Collection(tx.collection) + _, err := collection.BulkWrite(ctx, tx.batch) + return err +} + +func (tx *WriteTx) Discard() { + tx.batch = nil + tx.inMem = make(map[string][]byte) +} diff --git a/db/mongodb/mongodb_test.go b/db/mongodb/mongodb_test.go new file mode 100644 index 000000000..da91750d6 --- /dev/null +++ b/db/mongodb/mongodb_test.go @@ -0,0 +1,112 @@ +package mongodb + +import ( + "fmt" + "os" + "testing" + + qt "github.com/frankban/quicktest" + "go.vocdoni.io/dvote/db" + "go.vocdoni.io/dvote/db/internal/dbtest" + "go.vocdoni.io/dvote/db/prefixeddb" + "go.vocdoni.io/dvote/util" +) + +func TestWriteTx(t *testing.T) { + if os.Getenv("MONGODB_URL") == "" { + t.Skip("the mongodb driver isn't complete") + } + database, err := New(db.Options{Path: util.RandomHex(16)}) + qt.Assert(t, err, qt.IsNil) + + dbtest.TestWriteTx(t, database) +} + +func TestIterate(t *testing.T) { + if os.Getenv("MONGODB_URL") == "" { + t.Skip("the mongodb driver isn't complete") + } + database, err := New(db.Options{Path: util.RandomHex(16)}) + qt.Assert(t, err, qt.IsNil) + + dbtest.TestIterate(t, database) +} + +func TestWriteTxApply(t *testing.T) { + if os.Getenv("MONGODB_URL") == "" { + t.Skip("the mongodb driver isn't complete") + } + database, err := New(db.Options{Path: util.RandomHex(16)}) + qt.Assert(t, err, qt.IsNil) + + dbtest.TestWriteTxApply(t, database) +} + +func TestWriteTxApplyPrefixed(t *testing.T) { + if os.Getenv("MONGODB_URL") == "" { + t.Skip("the mongodb driver isn't complete") + } + database, err := New(db.Options{Path: util.RandomHex(16)}) + qt.Assert(t, err, qt.IsNil) + + prefix := []byte("one") + dbWithPrefix := prefixeddb.NewPrefixedDatabase(database, prefix) + + dbtest.TestWriteTxApplyPrefixed(t, database, dbWithPrefix) +} + +func BenchmarkWriteTx(b *testing.B) { + database, err := New(db.Options{Path: b.TempDir()}) + if err != nil { + b.Fatal(err) + } + defer database.Close() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + tx := database.WriteTx() + tx.Set([]byte("key"), []byte("value")) + tx.Commit() + } +} + +func BenchmarkIterate(b *testing.B) { + database, err := New(db.Options{Path: util.RandomHex(16)}) + if err != nil { + b.Fatal(err) + } + defer database.Close() + + tx := database.WriteTx() + for i := 0; i < 100000; i++ { + tx.Set([]byte(fmt.Sprintf("key%d", i)), []byte("value")) + } + tx.Commit() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + database.Iterate([]byte("key"), func(k, v []byte) bool { + return true + }) + } +} + +func BenchmarkWriteTxApply(b *testing.B) { + database, err := New(db.Options{Path: util.RandomHex(16)}) + if err != nil { + b.Fatal(err) + } + defer database.Close() + + tx1 := database.WriteTx() + tx1.Set([]byte("key1"), []byte("value1")) + + tx2 := database.WriteTx() + tx2.Set([]byte("key2"), []byte("value2")) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + tx1.Apply(tx2) + tx1.Commit() + } +} diff --git a/go.mod b/go.mod index 67c724cd3..6e26ee21a 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a github.com/vocdoni/go-snark v0.0.0-20210709152824-f6e4c27d7319 github.com/vocdoni/storage-proofs-eth-go v0.1.6 + go.mongodb.org/mongo-driver v1.12.1 go.vocdoni.io/proto v1.14.6-0.20230802094125-e07a41fda290 golang.org/x/crypto v0.11.0 golang.org/x/exp v0.0.0-20230420155640-133eef4313cb @@ -218,6 +219,7 @@ require ( github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect @@ -273,6 +275,10 @@ require ( github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect github.com/whyrusleeping/go-sysinfo v0.0.0-20190219211824-4a357d4b90b1 // indirect github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/go.sum b/go.sum index da0f0e643..51364b645 100644 --- a/go.sum +++ b/go.sum @@ -889,6 +889,7 @@ github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0 github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= @@ -1093,6 +1094,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= @@ -1525,6 +1528,12 @@ github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go. github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= @@ -1533,6 +1542,8 @@ github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6Ut github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= @@ -1548,6 +1559,8 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= +go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= +go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -1651,6 +1664,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1919,6 +1933,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= diff --git a/test/testcommon/api.go b/test/testcommon/api.go index efb40af53..443cfbccc 100644 --- a/test/testcommon/api.go +++ b/test/testcommon/api.go @@ -51,7 +51,7 @@ func (d *APIserver) Start(t testing.TB, apis ...string) { qt.Assert(t, err, qt.IsNil) d.ListenAddr = addr t.Logf("address: %s", addr.String()) - api, err := api.NewAPI(&router, "/", t.TempDir()) + api, err := api.NewAPI(&router, "/", t.TempDir(), db.TypePebble) qt.Assert(t, err, qt.IsNil) // create vochain application diff --git a/vocone/vocone.go b/vocone/vocone.go index 58e0b584a..568e0444f 100644 --- a/vocone/vocone.go +++ b/vocone/vocone.go @@ -146,7 +146,7 @@ func (vc *Vocone) EnableAPI(host string, port int, URLpath string) (*api.API, er if err := httpRouter.Init(host, port); err != nil { return nil, err } - uAPI, err := api.NewAPI(&httpRouter, URLpath, vc.dataDir) + uAPI, err := api.NewAPI(&httpRouter, URLpath, vc.dataDir, db.TypePebble) if err != nil { return nil, err }