Skip to content

Commit

Permalink
update dependencies, upgrade code and add a memory database
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Nov 6, 2024
1 parent 8a3b376 commit 3554342
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 2,639 deletions.
69 changes: 32 additions & 37 deletions addbatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"time"

qt "github.com/frankban/quicktest"
"github.com/vocdoni/arbo/memdb"
"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/db/badgerdb"
"go.vocdoni.io/dvote/db/pebbledb"
)

Expand All @@ -40,14 +40,12 @@ func debugTime(descr string, time1, time2 time.Duration) {
}

func testInit(c *qt.C, n int) (*Tree, *Tree) {
database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
database1 := memdb.New()
tree1, err := NewTree(Config{Database: database1, MaxLevels: 256,
HashFunction: HashFunctionPoseidon})
c.Assert(err, qt.IsNil)

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
database2 := memdb.New()
tree2, err := NewTree(Config{Database: database2, MaxLevels: 256,
HashFunction: HashFunctionPoseidon})
c.Assert(err, qt.IsNil)
Expand All @@ -73,7 +71,7 @@ func TestAddBatchTreeEmpty(t *testing.T) {

nLeafs := 1024

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand All @@ -97,7 +95,7 @@ func TestAddBatchTreeEmpty(t *testing.T) {
}
time1 := time.Since(start)

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -125,7 +123,7 @@ func TestAddBatchTreeEmptyNotPowerOf2(t *testing.T) {

nLeafs := 1027

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand All @@ -141,7 +139,7 @@ func TestAddBatchTreeEmptyNotPowerOf2(t *testing.T) {
}
}

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -174,14 +172,14 @@ func randomBytes(n int) []byte {

func TestAddBatchTestVector1(t *testing.T) {
c := qt.New(t)
database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
database1, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
c.Assert(err, qt.IsNil)
defer tree1.db.Close() //nolint:errcheck

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -216,14 +214,14 @@ func TestAddBatchTestVector1(t *testing.T) {
checkRoots(c, tree1, tree2)

// 2nd test vectors
database1, err = badgerdb.New(db.Options{Path: c.TempDir()})
database1, err = pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err = NewTree(Config{database1, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
c.Assert(err, qt.IsNil)
defer tree1.db.Close() //nolint:errcheck

database2, err = badgerdb.New(db.Options{Path: c.TempDir()})
database2, err = pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err = NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -266,14 +264,14 @@ func TestAddBatchTestVector2(t *testing.T) {
// test vector with unbalanced tree
c := qt.New(t)

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
c.Assert(err, qt.IsNil)
defer tree1.db.Close() //nolint:errcheck

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -313,14 +311,14 @@ func TestAddBatchTestVector3(t *testing.T) {
// test vector with unbalanced tree
c := qt.New(t)

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
c.Assert(err, qt.IsNil)
defer tree1.db.Close() //nolint:errcheck

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -364,14 +362,14 @@ func TestAddBatchTreeEmptyRandomKeys(t *testing.T) {

nLeafs := 8

database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
database1, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
c.Assert(err, qt.IsNil)
defer tree1.db.Close() //nolint:errcheck

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -716,7 +714,7 @@ func TestAddBatchNotEmptyUnbalanced(t *testing.T) {
}
time1 := time.Since(start)

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -775,7 +773,7 @@ func TestFlp2(t *testing.T) {

func TestAddBatchBench(t *testing.T) {
nLeafs := 50_000
printTestContext("TestAddBatchBench: ", nLeafs, "Blake2b", "badgerdb")
printTestContext("TestAddBatchBench: ", nLeafs, "Blake2b", "pebbledb")

// prepare inputs
var ks, vs [][]byte
Expand All @@ -794,7 +792,7 @@ func TestAddBatchBench(t *testing.T) {
func benchAdd(t *testing.T, ks, vs [][]byte) {
c := qt.New(t)

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand All @@ -815,7 +813,7 @@ func benchAdd(t *testing.T, ks, vs [][]byte) {
func benchAddBatch(t *testing.T, ks, vs [][]byte) {
c := qt.New(t)

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -849,7 +847,7 @@ func TestDbgStats(t *testing.T) {
}

// 1
database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
database1, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand All @@ -864,7 +862,7 @@ func TestDbgStats(t *testing.T) {
}

// 2
database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand All @@ -878,7 +876,7 @@ func TestDbgStats(t *testing.T) {
c.Assert(len(invalids), qt.Equals, 0)

// 3
database3, err := badgerdb.New(db.Options{Path: c.TempDir()})
database3, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree3, err := NewTree(Config{database3, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -914,8 +912,7 @@ func TestLoadVT(t *testing.T) {

nLeafs := 1024

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
database := memdb.New()
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
c.Assert(err, qt.IsNil)
Expand All @@ -932,9 +929,7 @@ func TestLoadVT(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Check(len(invalids), qt.Equals, 0)

rTx := tree.db.ReadTx()
defer rTx.Discard()
vt, err := tree.loadVT(rTx)
vt, err := tree.loadVT()
c.Assert(err, qt.IsNil)
_, err = vt.computeHashes()
c.Assert(err, qt.IsNil)
Expand All @@ -951,7 +946,7 @@ func TestAddKeysWithEmptyValues(t *testing.T) {

nLeafs := 1024

database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{database, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand All @@ -973,7 +968,7 @@ func TestAddKeysWithEmptyValues(t *testing.T) {
}
}

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand All @@ -988,7 +983,7 @@ func TestAddKeysWithEmptyValues(t *testing.T) {
checkRoots(c, tree, tree2)

// use tree3 to add nil value array
database3, err := badgerdb.New(db.Options{Path: c.TempDir()})
database3, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree3, err := NewTree(Config{database3, 256, DefaultThresholdNLeafs,
HashFunctionPoseidon})
Expand Down Expand Up @@ -1038,7 +1033,7 @@ func TestAddBatchThresholdInDisk(t *testing.T) {
// customize thresholdNLeafs for the test
testThresholdNLeafs := 1024

database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
database1, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database1, 256, testThresholdNLeafs,
HashFunctionBlake2b})
Expand Down Expand Up @@ -1106,13 +1101,13 @@ func TestAddBatchThresholdInDisk(t *testing.T) {
}

func initTestUpFromSubRoots(c *qt.C) (*Tree, *Tree) {
database1, err := badgerdb.New(db.Options{Path: c.TempDir()})
database1, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree1, err := NewTree(Config{database1, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
c.Assert(err, qt.IsNil)

database2, err := badgerdb.New(db.Options{Path: c.TempDir()})
database2, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree2, err := NewTree(Config{database2, 256, DefaultThresholdNLeafs,
HashFunctionBlake2b})
Expand Down
4 changes: 2 additions & 2 deletions circomproofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

qt "github.com/frankban/quicktest"
"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/db/badgerdb"
"go.vocdoni.io/dvote/db/pebbledb"
)

func TestCircomVerifierProof(t *testing.T) {
c := qt.New(t)
database, err := badgerdb.New(db.Options{Path: c.TempDir()})
database, err := pebbledb.New(db.Options{Path: c.TempDir()})
c.Assert(err, qt.IsNil)
tree, err := NewTree(Config{Database: database, MaxLevels: 4,
HashFunction: HashFunctionPoseidon})
Expand Down
42 changes: 37 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
module github.com/vocdoni/arbo

go 1.16
go 1.23.0

Check failure on line 3 in go.mod

View workflow job for this annotation

GitHub Actions / test (1.16.x, ubuntu-latest)

invalid go version '1.23.0': must match format 1.23

toolchain go1.23.1

Check failure on line 5 in go.mod

View workflow job for this annotation

GitHub Actions / test (1.16.x, ubuntu-latest)

unknown directive: toolchain

require (
github.com/frankban/quicktest v1.14.6
github.com/iden3/go-iden3-crypto v0.0.17
go.vocdoni.io/dvote v1.10.2-0.20241024102542-c1ce6d744bc5
golang.org/x/crypto v0.28.0
)

require (
github.com/frankban/quicktest v1.13.0
github.com/iden3/go-iden3-crypto v0.0.12
go.vocdoni.io/dvote v1.0.4-0.20211025120558-83c64f440044
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
github.com/DataDog/zstd v1.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit 3554342

Please sign in to comment.