Skip to content

Commit

Permalink
Merge pull request #173 from MDrollette/linting-nits
Browse files Browse the repository at this point in the history
Various linting and spelling nits
  • Loading branch information
adiabat authored Jul 23, 2020
2 parents d1f772d + 7f6f829 commit 7f5d091
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Get dependencies
run: |
cd $GOPATH/src/github.com/${{ github.repository }}
go get -v -d ./csn ./bridgenode ./cmd/utreexoserver ./cmd/utreexoclient
go get -v -d ./...
- name: Build
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions accumulator/batchproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (bp *BatchProof) ToString() string {
for _, p := range bp.Proof {
s += fmt.Sprintf("%04x\t", p[:4])
}
s += fmt.Sprintf("\n")
s += "\n"
return s
}

Expand All @@ -91,7 +91,7 @@ func FromBytesBatchProof(b []byte) (BatchProof, error) {
return bp, err
}
bp.Targets = make([]uint64, numTargets)
for i := range bp.Targets {
for i, _ := range bp.Targets {
err := binary.Read(buf, binary.BigEndian, &bp.Targets[i])
if err != nil {
return bp, err
Expand All @@ -104,7 +104,7 @@ func FromBytesBatchProof(b []byte) (BatchProof, error) {
}
bp.Proof = make([]Hash, remaining/32)

for i := range bp.Proof {
for i, _ := range bp.Proof {
copy(bp.Proof[i][:], buf.Next(32))
}
return bp, nil
Expand Down
4 changes: 2 additions & 2 deletions accumulator/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In parts of the forest code you'll see these terminology being used.
more than 1 top unlike a Merkle tree.
Parent - The hash of two leaves concatenated.
Sibling - The other leaf that shares the same parent.
Aunt - The silbing of the parent leaf.
Aunt - The sibling of the parent leaf.
Cousin - The children of the parent leaf's sibling.
Forest is a representation of a "full" Utreexo tree. The Forest implementation
Expand All @@ -51,7 +51,7 @@ is stored.
This is done as either:
1) byte slice
2) contingous data in a file
2) contiguous data in a file
The ordering of the Utreexo tree is done in a similar fashion to that of a 2x2
array in row-major order. A Utreexo tree with 8 leaves would look like:
Expand Down
28 changes: 12 additions & 16 deletions accumulator/forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func updateDirt(hashDirt []uint64, swapRow []arrow, numLeaves uint64, rows uint8
}
if !inForest(hashDest, numLeaves, rows) ||
hashDest == 0 || // TODO would be great to use nextNumLeaves... but tricky
hashDest == prevHash { // TODO this doesn't cover eveything
hashDest == prevHash { // TODO this doesn't cover everything
continue
}
prevHash = hashDest
Expand All @@ -215,11 +215,11 @@ func makeDestInRow(maybeArrow []arrow, hashDirt []uint64, rows uint8) (bool, uin
// re-descending here which isn't great
hashDest := parent(hashDirt[0], rows)
return false, hashDest
} else {
// swapping
hashDest := parent(maybeArrow[0].to, rows)
return true, hashDest
}

// swapping
hashDest := parent(maybeArrow[0].to, rows)
return true, hashDest
}

func (f *Forest) swapNodes(s arrow, row uint8) {
Expand Down Expand Up @@ -254,9 +254,6 @@ func (f *Forest) swapNodes(s arrow, row uint8) {
b = parent(b, f.rows)
run >>= 1
}

// for
return
}

// reHash hashes new data in the forest based on dirty positions.
Expand Down Expand Up @@ -307,7 +304,7 @@ func (f *Forest) reHash(dirt []uint64) error {
}

// merge nextRow and the dirtySlice. They're both sorted so this
// should be quick. Seems like a CS class kindof algo but who knows.
// should be quick. Seems like a CS class kind of algo but who knows.
// Should be O(n) anyway.

currentRow = mergeSortedSlices(currentRow, dirty2d[r])
Expand Down Expand Up @@ -395,7 +392,6 @@ func (f *Forest) addv2(adds []Leaf) {
}
f.numLeaves++
}
return
}

// Modify changes the forest, adding and deleting leaves and updating internal nodes.
Expand Down Expand Up @@ -545,7 +541,7 @@ func (f *Forest) PosMapSanity() error {
// RestoreForest restores the forest on restart. Needed when resuming after exiting.
// miscForestFile is where numLeaves and rows is stored
func RestoreForest(
miscForestFile *os.File, forestFile *os.File, toRam, cached bool) (*Forest, error) {
miscForestFile *os.File, forestFile *os.File, toRAM, cached bool) (*Forest, error) {

// start a forest for restore
f := new(Forest)
Expand All @@ -569,7 +565,7 @@ func RestoreForest(
diskData := new(diskForestData)
diskData.file = forestFile

if toRam {
if toRAM {
// for in-ram
ramData := new(ramForestData)
fmt.Printf("%d rows resize to %d\n", f.rows, 2<<f.rows)
Expand Down Expand Up @@ -642,7 +638,7 @@ func (f *Forest) PrintPositionMap() string {
return s
}

// WriteForest writes the numLeaves and rows to miscForestFile
// WriteMiscData writes the numLeaves and rows to miscForestFile
func (f *Forest) WriteMiscData(miscForestFile *os.File) error {
fmt.Println("numLeaves=", f.numLeaves)
fmt.Println("f.rows=", f.rows)
Expand All @@ -662,7 +658,7 @@ func (f *Forest) WriteMiscData(miscForestFile *os.File) error {
return nil
}

// WriteForest writes the whole forest to disk
// WriteForestToDisk writes the whole forest to disk
// this only makes sense to do if the forest is in ram. So it'll return
// an error if it's not a ramForestData
func (f *Forest) WriteForestToDisk(dumpFile *os.File) error {
Expand Down Expand Up @@ -690,7 +686,7 @@ func (f *Forest) getRoots() []Hash {
rootPositions, _ := getRootsReverse(f.numLeaves, f.rows)
roots := make([]Hash, len(rootPositions))

for i := range roots {
for i, _ := range roots {
roots[i] = f.data.read(rootPositions[i])
}

Expand Down Expand Up @@ -735,7 +731,7 @@ func (f *Forest) ToString() string {
if valstring != "" {
output[h*2] += fmt.Sprintf("%02d:%s ", pos, valstring)
} else {
output[h*2] += fmt.Sprintf(" ")
output[h*2] += " "
}
if h > 0 {
// if x%2 == 0 {
Expand Down
17 changes: 8 additions & 9 deletions accumulator/forest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func TestForestFixed(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fmt.Printf(f.ToString())
fmt.Printf(f.PrintPositionMap())
fmt.Print(f.ToString())
fmt.Print(f.PrintPositionMap())
_, err = f.Modify(nil, dels)
if err != nil {
t.Fatal(err)
}
fmt.Printf(f.ToString())
fmt.Printf(f.PrintPositionMap())
fmt.Print(f.ToString())
fmt.Print(f.PrintPositionMap())
}

// Add 2. delete 1. Repeat.
Expand All @@ -89,7 +89,7 @@ func Test2Fwd1Back(t *testing.T) {

for i := 0; i < 100; i++ {

for j := range adds {
for j, _ := range adds {
adds[j].Hash[0] = uint8(absidx>>8) | 0xa0
adds[j].Hash[1] = uint8(absidx)
adds[j].Hash[3] = 0xaa
Expand Down Expand Up @@ -165,7 +165,7 @@ func addDelFullBatchProof(nAdds, nDels int) error {
f := NewForest(nil, false)
adds := make([]Leaf, nAdds)

for j := range adds {
for j, _ := range adds {
adds[j].Hash[0] = uint8(j>>8) | 0xa0
adds[j].Hash[1] = uint8(j)
adds[j].Hash[3] = 0xaa
Expand Down Expand Up @@ -264,10 +264,9 @@ func TestSmallRandomForests(t *testing.T) {
// can sort it.
// Modify requires a sorted list of leaves to delete.
// We use int because we can't sort uint64's.
var deletions []int
deletions = make([]int, len(leavesToDeleteSet))
deletions := make([]int, len(leavesToDeleteSet))
i = 0
for leafTxo := range leavesToDeleteSet {
for leafTxo, _ := range leavesToDeleteSet {
deletions[i] = int(f.positionMap[leafTxo.Mini()])
i++
}
Expand Down
2 changes: 1 addition & 1 deletion accumulator/forestdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// Length is always 32.
const leafSize = 32

// A forestData is the thing that holds all the hashes in the forest. Could
// ForestData is the thing that holds all the hashes in the forest. Could
// be in a file, or in ram, or maybe something else.
type ForestData interface {
read(pos uint64) Hash
Expand Down
6 changes: 3 additions & 3 deletions accumulator/forestproofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (f *Forest) Prove(wanted Hash) (Proof, error) {
// fmt.Printf("nl %d proof for %d len %d\n", f.numLeaves, pos, len(pr.Siblings))
// fmt.Printf("\tprove pos %d %x:\n", pos, pr.Payload[:4])
// go up and populate the siblings
for h := range pr.Siblings {
for h, _ := range pr.Siblings {

pr.Siblings[h] = f.data.read(pos ^ 1)
if pr.Siblings[h] == empty {
fmt.Printf(f.ToString())
fmt.Print(f.ToString())
return pr, fmt.Errorf(
"prove: got empty hash proving leaf %d row %d pos %d nl %d",
pr.Position, h, pos^1, f.numLeaves)
Expand Down Expand Up @@ -154,7 +154,7 @@ func (f *Forest) ProveBatch(hs []Hash) (BatchProof, error) {

pos, ok := f.positionMap[wanted.Mini()]
if !ok {
fmt.Printf(f.ToString())
fmt.Print(f.ToString())
return bp, fmt.Errorf("hash %x not found", wanted)
}

Expand Down
23 changes: 11 additions & 12 deletions accumulator/pollard.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func (p *Pollard) ReconstructStats() (uint64, uint8) {
func (p *Pollard) add(adds []Leaf) error {

// General algo goes:
// 1 make a new node & assign data (no neices; at bottom)
// 1 make a new node & assign data (no nieces; at bottom)
// 2 if this node is on a row where there's already a root,
// then swap neices with that root, hash the two datas, and build a new
// then swap nieces with that root, hash the two datas, and build a new
// node 1 higher pointing to them.
// goto 2.

Expand Down Expand Up @@ -86,10 +86,10 @@ in numLeaves. As soon as we hit a 0 (no root), we're done.
grab: Grab the lowest root.
pop: pop off the lowest root.
swap: swap the neices of the node we grabbed and our new node
swap: swap the nieces of the node we grabbed and our new node
hash: calculate the hashes of the old root and new node
new: create a new parent node, with the hash as data, and the old root / prev new node
as neices (not neices though, children)
as nieces (not nieces though, children)
*/

// add a single leaf to a pollard
Expand Down Expand Up @@ -207,7 +207,7 @@ func (p *Pollard) rem2(dels []uint64) error {
}
if hn.position == prevHash { // we just did this
// fmt.Printf("just did %d\n", prevHash)
continue // TODO this doesn't cover eveything
continue // TODO this doesn't cover everything
}
hnslice = append(hnslice, hn)
prevHash = hn.position
Expand All @@ -227,7 +227,7 @@ func (p *Pollard) rem2(dels []uint64) error {
// TODO when is hn nil? is this OK?
// it'd be better to avoid this and not create hns that aren't
// supposed to exist.
fmt.Printf("hn %d nil or uncomputable\n", hn.position)
fmt.Printf("hn %d nil or incomputable\n", hn.position)
continue
}
// fmt.Printf("giving hasher %d %x %x\n",
Expand All @@ -241,7 +241,7 @@ func (p *Pollard) rem2(dels []uint64) error {
// set new roots
nextRootPositions, _ := getRootsReverse(nextNumLeaves, ph)
nextRoots := make([]polNode, len(nextRootPositions))
for i := range nextRoots {
for i, _ := range nextRoots {
nt, ntsib, _, err := p.grabPos(nextRootPositions[i])
if err != nil {
return err
Expand Down Expand Up @@ -410,12 +410,12 @@ func (p *Pollard) descendToPos(pos uint64) ([]*polNode, []*polNode, error) {

if n == nil && r != 0 {
return nil, nil, fmt.Errorf(
"descend pos %d nil neice at row %d", pos, r)
"descend pos %d nil niece at row %d", pos, r)
}

if n != nil {
// fmt.Printf("target %d h %d d %04x\n", pos, h, n.data[:4])
}
// if n != nil {
// fmt.Printf("target %d h %d d %04x\n", pos, h, n.data[:4])
// }

proofs[r], sibs[r] = n, sib

Expand Down Expand Up @@ -456,7 +456,6 @@ func (p *Pollard) toFull() (*Forest, error) {
return ff, nil
}

//func (p *Pollard) ToString() string {
func (p *Pollard) ToString() string {
f, err := p.toFull()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions accumulator/pollard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func pollardRandomRemember(blocks int32) error {
}
err = f.PosMapSanity()
if err != nil {
fmt.Printf(f.ToString())
fmt.Print(f.ToString())
return err
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func fixedPollard(leaves int32) error {
fmt.Printf("pollard post del %s", p.ToString())

if !p.equalToForest(f) {
return fmt.Errorf("p != f (leaves)\n")
return fmt.Errorf("p != f (leaves)")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion accumulator/pollardfull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func pollardFullRandomRemember(blocks int32) error {

err = fp.PosMapSanity()
if err != nil {
fmt.Printf(fp.ToString())
fmt.Print(fp.ToString())
return err
}

Expand Down
2 changes: 1 addition & 1 deletion accumulator/pollardproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

// IngestBlockProof populates the Pollard with all needed data to delete the
// IngestBatchProof populates the Pollard with all needed data to delete the
// targets in the block proof
func (p *Pollard) IngestBatchProof(bp BatchProof) error {
var empty Hash
Expand Down
7 changes: 3 additions & 4 deletions accumulator/pollardutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type polNode struct {
niece [2]*polNode
}

// auntOp returns the hash of a nodes neices. crashes if you call on nil neices.
// auntOp returns the hash of a nodes nieces. crashes if you call on nil nieces.
func (n *polNode) auntOp() Hash {
return parentHash(n.niece[0].data, n.niece[1].data)
}
Expand All @@ -46,7 +46,7 @@ func (n *polNode) auntable() bool {
return n.niece[0] != nil && n.niece[1] != nil
}

// deadEnd returns true if both neices are nill
// deadEnd returns true if both nieces are nill
// could also return true if n itself is nil! (maybe a bad idea?)
func (n *polNode) deadEnd() bool {
// if n == nil {
Expand Down Expand Up @@ -79,7 +79,6 @@ func (n *polNode) printout() {
} else {
fmt.Printf("r %x\n", n.niece[1].data[:4])
}
return
}

// prune prunes deadend children.
Expand All @@ -94,7 +93,7 @@ func (n *polNode) prune() {
}

// polSwap swaps the contents of two polNodes & leaves pointers to them intact
// need their siblings so that the siblings' neices can swap.
// need their siblings so that the siblings' nieces can swap.
// for a root, just say the root's sibling is itself and it should work.
func polSwap(a, asib, b, bsib *polNode) error {
if a == nil || asib == nil || b == nil || bsib == nil {
Expand Down
Loading

0 comments on commit 7f5d091

Please sign in to comment.