Skip to content

Commit

Permalink
census: remove unused Publish function
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Oct 31, 2023
1 parent cc29993 commit 4436efc
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 47 deletions.
6 changes: 0 additions & 6 deletions api/censusdb/censusdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ func (c *CensusDB) New(censusID []byte, censusType models.Census_Type,
return nil, err
}
ref.tree = tree
if uri != "" {
ref.tree.Publish()
}
return ref, nil
}

Expand Down Expand Up @@ -150,9 +147,6 @@ func (c *CensusDB) Load(censusID []byte, authToken *uuid.UUID) (*CensusRef, erro
if err != nil {
return nil, err
}
if ref.URI != "" {
ref.tree.Publish()
}
root, err := ref.Tree().Root()
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ func (a *API) censusPublishHandler(msg *apirest.APIdata, ctx *httprouter.HTTPCon
if err := newRef.Tree().ImportDump(dump); err != nil {
return err
}
newRef.Tree().Publish()

var data []byte
if data, err = json.Marshal(&Census{
Expand Down
12 changes: 0 additions & 12 deletions censustree/censustree.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"math/big"
"sync"
"sync/atomic"

"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/db/prefixeddb"
Expand All @@ -24,7 +23,6 @@ var censusWeightKey = []byte("censusWeight")
// updates it.
type Tree struct {
tree *tree.Tree
public atomic.Bool
censusType models.Census_Type
hashFunc func(...[]byte) ([]byte, error)
hashLen int
Expand Down Expand Up @@ -146,16 +144,6 @@ func (t *Tree) FromRoot(root []byte) (*Tree, error) {
return &Tree{tree: treeFromRoot, censusType: t.Type()}, nil
}

// Publish makes a merkle tree available for queries. Application layer should
// call Publish() before considering the Tree available.
func (t *Tree) Publish() { t.public.Store(true) }

// Unpublish makes a merkle tree not available for queries.
func (t *Tree) Unpublish() { t.public.Store(false) }

// IsPublic returns true if the tree is available.
func (t *Tree) IsPublic() bool { return t.public.Load() }

// Root wraps tree.Tree.Root.
func (t *Tree) Root() ([]byte, error) {
return t.tree.Root(nil)
Expand Down
24 changes: 0 additions & 24 deletions censustree/censustree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@ import (
// The proper tests are in tree package, here there are tests that check the
// added code in the CensusTree wrapper.

func TestPublish(t *testing.T) {
db := metadb.NewTest(t)
censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
CensusType: models.Census_ARBO_BLAKE2B})
qt.Assert(t, err, qt.IsNil)
rnd := testutil.NewRandom(0)
key, value := rnd.RandomBytes(DefaultMaxKeyLen), rnd.RandomBytes(32)
qt.Assert(t, censusTree.Add(key, value), qt.IsNil)

qt.Assert(t, censusTree.IsPublic(), qt.IsFalse)

censusTree.Publish()
qt.Assert(t, censusTree.IsPublic(), qt.IsTrue)

recValue, _, err := censusTree.GenProof(key)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, value, qt.DeepEquals, recValue)

censusTree.Unpublish()
qt.Assert(t, censusTree.IsPublic(), qt.IsFalse)
}

func TestImportWeighted(t *testing.T) {
db := metadb.NewTest(t)
censusTree, err := New(Options{Name: "test", ParentDB: db, MaxLevels: DefaultMaxLevels,
Expand Down Expand Up @@ -118,8 +96,6 @@ func TestWeightedProof(t *testing.T) {
err = censusTree.Add(userKey, userWeight)
qt.Assert(t, err, qt.IsNil)

censusTree.Publish()

// generate and test the proof
value, siblings, err := censusTree.GenProof(userKey)
qt.Assert(t, err, qt.IsNil)
Expand Down
1 change: 0 additions & 1 deletion test/testcommon/testvoteproof/voteproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func CreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys, []b
hashedKeys = append(hashedKeys, c)
}

tr.Publish()
var proofs [][]byte
for i := range keys {
_, proof, err := tr.GenProof(hashedKeys[i])
Expand Down
3 changes: 0 additions & 3 deletions vochain/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func testCreateKeysAndBuildWeightedZkCensus(t *testing.T, size int, weight *big.
qt.Check(t, err, qt.IsNil)
}

tr.Publish()

root, err := tr.Root()
qt.Check(t, err, qt.IsNil)
var proofs [][]byte
Expand Down Expand Up @@ -74,7 +72,6 @@ func testCreateKeysAndBuildCensus(t *testing.T, size int) ([]*ethereum.SignKeys,
hashedKeys = append(hashedKeys, c)
}

tr.Publish()
var proofs [][]byte
for i := range keys {
_, proof, err := tr.GenProof(hashedKeys[i])
Expand Down

0 comments on commit 4436efc

Please sign in to comment.