Skip to content

Commit

Permalink
accumulator/forest: Export getroots function
Browse files Browse the repository at this point in the history
Function getroots is exported so that bridge nodes are able to query
the accumulator roots.
  • Loading branch information
kcalvinalvin committed Jan 10, 2022
1 parent e89de3f commit d927ced
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions accumulator/forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ func (f *Forest) WriteForestToDisk(dumpFile *os.File, ram, cow bool) error {
return nil
}

// getRoots returns all the roots of the trees
func (f *Forest) getRoots() []Hash {
// GetRoots returns all the roots of all the trees in the accumulator.
func (f *Forest) GetRoots() []Hash {
positionList := NewPositionList()
defer positionList.Free()

Expand Down Expand Up @@ -712,7 +712,7 @@ func (f *Forest) ToString() string {
// tree rows should be 6 or less
if fh > 6 {
s := fmt.Sprintf("can't print %d leaves. roots:\n", f.numLeaves)
roots := f.getRoots()
roots := f.GetRoots()
for i, r := range roots {
s += fmt.Sprintf("\t%d %x\n", i, r.Mini())
}
Expand Down
2 changes: 1 addition & 1 deletion accumulator/forest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func addDelFullBatchProof(nAdds, nDels int) error {
return err
}
// check block proof. Note this doesn't delete anything, just proves inclusion
_, _, err = verifyBatchProof(leavesToProve, bp, f.getRoots(), f.numLeaves, nil)
_, _, err = verifyBatchProof(leavesToProve, bp, f.GetRoots(), f.numLeaves, nil)
if err != nil {
return fmt.Errorf("VerifyBatchProof failed. Error: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion accumulator/forestproofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,6 @@ func (f *Forest) ProveBatch(hs []Hash) (BatchProof, error) {

// VerifyBatchProof is just a wrapper around verifyBatchProof
func (f *Forest) VerifyBatchProof(toProve []Hash, bp BatchProof) error {
_, _, err := verifyBatchProof(toProve, bp, f.getRoots(), f.numLeaves, nil)
_, _, err := verifyBatchProof(toProve, bp, f.GetRoots(), f.numLeaves, nil)
return err
}
4 changes: 2 additions & 2 deletions accumulator/pollard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func pollardRandomRemember(blocks int32) error {
return fmt.Errorf("pollard and forest leaves differ")
}

fullTops := f.getRoots()
fullTops := f.GetRoots()
polTops := p.rootHashesForward()

// check that tops match
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestPollardIngestMultiBlockProof(t *testing.T) {
t.Fatal(fmt.Errorf("Pollard and forest leaves differ"))
}

forestRoots := f.getRoots()
forestRoots := f.GetRoots()
pollardRoots := p.rootHashesForward()

// Check that roots match.
Expand Down
10 changes: 5 additions & 5 deletions accumulator/undo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func undoOnceRandom(blocks int32) error {
if err != nil {
return err
}
beforeRoot := f.getRoots()
beforeRoot := f.GetRoots()
ub, err := f.Modify(adds, bp.Targets)
if err != nil {
return err
Expand Down Expand Up @@ -193,7 +193,7 @@ func undoOnceRandom(blocks int32) error {
}
}
sc.BackOne(adds, durations, delHashes)
afterRoot := f.getRoots()
afterRoot := f.GetRoots()
if !reflect.DeepEqual(beforeRoot, afterRoot) {
return fmt.Errorf("undo mismatch")
}
Expand All @@ -219,7 +219,7 @@ func undoAddDelOnce(numStart, numAdds, numDels uint32) error {
return err
}
fmt.Printf(f.ToString())
beforeTops := f.getRoots()
beforeTops := f.GetRoots()
for i, h := range beforeTops {
fmt.Printf("beforeTops %d %x\n", i, h)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func undoAddDelOnce(numStart, numAdds, numDels uint32) error {
}
fmt.Print(f.ToString())
fmt.Print(ub.ToString())
afterTops := f.getRoots()
afterTops := f.GetRoots()
for i, h := range afterTops {
fmt.Printf("afterTops %d %x\n", i, h)
}
Expand All @@ -257,7 +257,7 @@ func undoAddDelOnce(numStart, numAdds, numDels uint32) error {
return err
}

undoneTops := f.getRoots()
undoneTops := f.GetRoots()
for i, h := range undoneTops {
fmt.Printf("undoneTops %d %x\n", i, h)
}
Expand Down

0 comments on commit d927ced

Please sign in to comment.