diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 349985dd..8af98147 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/accumulator/batchproof.go b/accumulator/batchproof.go index 642c2795..0ebce04a 100644 --- a/accumulator/batchproof.go +++ b/accumulator/batchproof.go @@ -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 } @@ -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 @@ -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 diff --git a/accumulator/doc.go b/accumulator/doc.go index 37b04045..8e0febfb 100644 --- a/accumulator/doc.go +++ b/accumulator/doc.go @@ -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 @@ -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: diff --git a/accumulator/forest.go b/accumulator/forest.go index 3e07d03a..e352306a 100644 --- a/accumulator/forest.go +++ b/accumulator/forest.go @@ -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 @@ -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) { @@ -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. @@ -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]) @@ -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. @@ -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) @@ -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< 0 { // if x%2 == 0 { diff --git a/accumulator/forest_test.go b/accumulator/forest_test.go index 0f589a3e..a1595c3d 100644 --- a/accumulator/forest_test.go +++ b/accumulator/forest_test.go @@ -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. @@ -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 @@ -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 @@ -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++ } diff --git a/accumulator/forestdata.go b/accumulator/forestdata.go index 0242f6e6..3d20015a 100644 --- a/accumulator/forestdata.go +++ b/accumulator/forestdata.go @@ -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 diff --git a/accumulator/forestproofs.go b/accumulator/forestproofs.go index 82c2fba3..d89b8ec7 100644 --- a/accumulator/forestproofs.go +++ b/accumulator/forestproofs.go @@ -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) @@ -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) } diff --git a/accumulator/pollard.go b/accumulator/pollard.go index 41741ea5..61e1bf3b 100644 --- a/accumulator/pollard.go +++ b/accumulator/pollard.go @@ -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. @@ -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 @@ -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 @@ -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", @@ -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 @@ -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 @@ -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 { diff --git a/accumulator/pollard_test.go b/accumulator/pollard_test.go index c02fc38a..42043001 100644 --- a/accumulator/pollard_test.go +++ b/accumulator/pollard_test.go @@ -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 } @@ -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 diff --git a/accumulator/pollardfull_test.go b/accumulator/pollardfull_test.go index 253f7207..c6761108 100644 --- a/accumulator/pollardfull_test.go +++ b/accumulator/pollardfull_test.go @@ -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 } diff --git a/accumulator/pollardproof.go b/accumulator/pollardproof.go index 0dcb8e4d..8f9b8ecb 100644 --- a/accumulator/pollardproof.go +++ b/accumulator/pollardproof.go @@ -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 diff --git a/accumulator/pollardutil.go b/accumulator/pollardutil.go index 51a65401..7d32c0d0 100644 --- a/accumulator/pollardutil.go +++ b/accumulator/pollardutil.go @@ -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) } @@ -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 { @@ -79,7 +79,6 @@ func (n *polNode) printout() { } else { fmt.Printf("r %x\n", n.niece[1].data[:4]) } - return } // prune prunes deadend children. @@ -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 { diff --git a/accumulator/pollarfull.go b/accumulator/pollarfull.go index debfd2ba..aad49f62 100644 --- a/accumulator/pollarfull.go +++ b/accumulator/pollarfull.go @@ -37,9 +37,9 @@ func (p *Pollard) PosMapSanity() error { // TODO make interface to reduce code dupe -// ProveBatch, but for pollard. +// ProveBatch but for pollard. // Now getting really obvious that forest and pollard should both satisfy some -// kind of utreexoy interface. And maybe forest shouldn't be called forest. +// kind of utreexo-like interface. And maybe forest shouldn't be called forest. // Anyway do that after this. func (p *Pollard) ProveBatch(hs []Hash) (BatchProof, error) { var bp BatchProof @@ -64,7 +64,7 @@ func (p *Pollard) ProveBatch(hs []Hash) (BatchProof, error) { pos, ok := p.positionMap[wanted.Mini()] if !ok { - fmt.Printf(p.ToString()) + fmt.Print(p.ToString()) return bp, fmt.Errorf("hash %x not found", wanted) } diff --git a/accumulator/transform.go b/accumulator/transform.go index 8783ef1d..7954731f 100644 --- a/accumulator/transform.go +++ b/accumulator/transform.go @@ -72,12 +72,12 @@ func makeCollapse(dels []uint64, delRemains, rootPresent bool, r uint8, numLeave // on the collapses with later rows of swaps case !delRemains && rootPresent: rootSrc := rootPosition(numLeaves, r, forestRows) - return []arrow{arrow{from: rootSrc, to: rootDest}} + return []arrow{{from: rootSrc, to: rootDest}} case delRemains && !rootPresent: // no root but 1 del: sibling becomes root & collapses // in this case, mark as deleted rootSrc := dels[len(dels)-1] ^ 1 - return []arrow{arrow{from: rootSrc, to: rootDest}} + return []arrow{{from: rootSrc, to: rootDest}} default: return nil } @@ -194,9 +194,7 @@ func floorTransform( // removeTransform output? } leaves := a.toLeaves(uint8(r), forestRows) - for _, l := range leaves { - floor = append(floor, l) - } + floor = append(floor, leaves...) } } return floor diff --git a/accumulator/types.go b/accumulator/types.go index 4158a164..c645ce57 100644 --- a/accumulator/types.go +++ b/accumulator/types.go @@ -9,7 +9,7 @@ import ( // Hash : type Hash [32]byte -// Prefix, for printfs +// Prefix for printfs func (h Hash) Prefix() []byte { return h[:4] } @@ -28,7 +28,7 @@ func HashFromString(s string) Hash { return sha256.Sum256([]byte(s)) } -// an arror describes the movement of a node from one position to another +// arrow describes the movement of a node from one position to another type arrow struct { from, to uint64 } @@ -39,11 +39,10 @@ type node struct { Val Hash } -// LeafTXOs have a hash and a expiry date (block when that utxo gets used) +// Leaf contains a hash and a hint about whether it should be saved to +// memory or not during ibdsim. type Leaf struct { Hash - // During ibdsim, this will dictate whether it is saved to - // the memory or not. Remember bool // this leaf will be deleted soon, remember it } @@ -106,7 +105,6 @@ func (s *SimChain) BackOne(leaves []Leaf, durations []int32, dels []Hash) { } s.blockHeight-- - return } func (s *SimChain) ttlString() string { @@ -116,7 +114,7 @@ func (s *SimChain) ttlString() string { for _, h := range d { x += fmt.Sprintf(" %x ", h[:4]) } - x += fmt.Sprintf("\n") + x += "\n" } return x @@ -140,7 +138,7 @@ func (s *SimChain) NextBlock(numAdds uint32) ([]Leaf, []int32, []Hash) { // make a bunch of unique adds & make an expiry time and add em to // the TTL map - for j := range adds { + for j, _ := range adds { adds[j].Hash[0] = uint8(s.leafCounter) adds[j].Hash[1] = uint8(s.leafCounter >> 8) adds[j].Hash[2] = uint8(s.leafCounter >> 16) diff --git a/accumulator/undo_test.go b/accumulator/undo_test.go index a260ee2a..15ba5bbf 100644 --- a/accumulator/undo_test.go +++ b/accumulator/undo_test.go @@ -58,8 +58,8 @@ func undoOnceRandom(blocks int32) error { if err != nil { return err } - fmt.Printf(f.ToString()) - fmt.Printf(sc.ttlString()) + fmt.Print(f.ToString()) + fmt.Print(sc.ttlString()) for h, p := range f.positionMap { fmt.Printf("%x@%d ", h[:4], p) } @@ -70,12 +70,12 @@ func undoOnceRandom(blocks int32) error { //undo every 3rd block if b%3 == 2 { - fmt.Printf(ub.ToString()) + fmt.Print(ub.ToString()) err := f.Undo(*ub) if err != nil { return err } - fmt.Printf("\n post undo map: ") + fmt.Print("\n post undo map: ") for h, p := range f.positionMap { fmt.Printf("%x@%d ", h[:4], p) } @@ -125,8 +125,8 @@ func undoAddDelOnce(numStart, numAdds, numDels uint32) error { if err != nil { return err } - fmt.Printf(f.ToString()) - fmt.Printf(ub.ToString()) + fmt.Print(f.ToString()) + fmt.Print(ub.ToString()) afterTops := f.getRoots() for i, h := range afterTops { fmt.Printf("afterTops %d %x\n", i, h) diff --git a/accumulator/utils.go b/accumulator/utils.go index cd18f5dc..f2b1c52c 100644 --- a/accumulator/utils.go +++ b/accumulator/utils.go @@ -5,7 +5,7 @@ import ( "sort" ) -// "verbose" is a global const to get lots of printfs for debugging +// verbose is a global const to get lots of printfs for debugging var verbose = false // takes a slice of dels, removes the twins (in place) and returns a slice @@ -333,7 +333,7 @@ func reversePolNodeSlice(a []polNode) { } // mergeSortedSlices takes two slices (of uint64s; though this seems -// genericizable in that it's just < and > operators) and merges them into +// generalizable in that it's just < and > operators) and merges them into // a single sorted slice, discarding duplicates. (but not detecting or discarding // duplicates within a single slice) // (eg [1, 5, 8, 9], [2, 3, 4, 5, 6] -> [1, 2, 3, 4, 5, 6, 8, 9] @@ -384,8 +384,8 @@ func mergeSortedSlices(a []uint64, b []uint64) (c []uint64) { return } -// kindof like mergeSortedSlices. Takes 2 sorted slices a, b and removes -// all elements of b from a and returns a. +// dedupeSwapDirt is kind of like mergeSortedSlices. Takes 2 sorted slices +// a, b and removes all elements of b from a and returns a. // in this case b is arrow.to func dedupeSwapDirt(a []uint64, b []arrow) []uint64 { maxa := len(a) diff --git a/bridgenode/chain.go b/bridgenode/chain.go index 09f2ebb5..749035cb 100644 --- a/bridgenode/chain.go +++ b/bridgenode/chain.go @@ -30,7 +30,7 @@ func initBridgeNodeState( knownTipHeight, err = restoreLastIndexOffsetHeight( offsetFinished) if err != nil { - err = fmt.Errorf("restoreLastIndexOffsetHeight error: %s\n", err.Error()) + err = fmt.Errorf("restoreLastIndexOffsetHeight error: %s", err.Error()) return } } else { @@ -38,7 +38,7 @@ func initBridgeNodeState( "Indexing offset for blocks blk*.dat files...") knownTipHeight, err = createOffsetData(p, dataDir, offsetFinished) if err != nil { - err = fmt.Errorf("createOffsetData error: %s\n", err.Error()) + err = fmt.Errorf("createOffsetData error: %s", err.Error()) return } fmt.Printf("tip height %d\n", knownTipHeight) @@ -50,12 +50,12 @@ func initBridgeNodeState( forest, err = restoreForest( util.ForestFilePath, util.MiscForestFilePath, forestInRam, forestCached) if err != nil { - err = fmt.Errorf("restoreForest error: %s\n", err.Error()) + err = fmt.Errorf("restoreForest error: %s", err.Error()) return } height, err = restoreHeight() if err != nil { - err = fmt.Errorf("restoreHeight error: %s\n", err.Error()) + err = fmt.Errorf("restoreHeight error: %s", err.Error()) return } } else { @@ -63,7 +63,7 @@ func initBridgeNodeState( forest, err = createForest(forestInRam, forestCached) height = 1 // note that blocks start at 1, block 0 doesn't go into set if err != nil { - err = fmt.Errorf("createForest error: %s\n", err.Error()) + err = fmt.Errorf("createForest error: %s", err.Error()) return } } diff --git a/bridgenode/genproofs.go b/bridgenode/genproofs.go index e8133af2..82a092be 100644 --- a/bridgenode/genproofs.go +++ b/bridgenode/genproofs.go @@ -81,7 +81,7 @@ func BuildProofs( var stop bool // bool for stopping the main loop - for ; height != knownTipHeight && stop != true; height++ { + for ; height != knownTipHeight && !stop; height++ { // Receive txs from the asynchronous blk*.dat reader bnr := <-blockAndRevReadQueue @@ -290,14 +290,14 @@ func blockNRevToDelLeaves(bnr BlockAndRev, skiplist []uint32) ( return } -// stopBuildProofs listens for the signal from the OS and initiates an exit squence +// stopBuildProofs listens for the signal from the OS and initiates an exit sequence func stopBuildProofs( sig, offsetfinished, haltRequest, haltAccept chan bool) { // Listen for SIGINT, SIGQUIT, SIGTERM <-sig - // Sometimes there are bugs that make the program run forver. + // Sometimes there are bugs that make the program run forever. // Utreexo binary should never take more than 10 seconds to exit go func() { time.Sleep(60 * time.Second) @@ -311,24 +311,18 @@ func stopBuildProofs( select { // If offsetfile is there or was built, don't remove it case <-offsetfinished: - select { - default: - haltRequest <- true - } + haltRequest <- true // If nothing is received, delete offsetfile and other directories // Don't wait for done channel from the main BuildProofs() for loop default: - select { - default: - fmt.Println("offsetfile incomplete, removing...") - // May not work sometimes. - err := os.RemoveAll(util.OffsetDirPath) - if err != nil { - fmt.Println("ERR. offsetdata/ directory not removed. Please manually remove it.") - } - fmt.Println("Exiting...") - os.Exit(0) + fmt.Println("offsetfile incomplete, removing...") + // May not work sometimes. + err := os.RemoveAll(util.OffsetDirPath) + if err != nil { + fmt.Println("ERR. offsetdata/ directory not removed. Please manually remove it.") } + fmt.Println("Exiting...") + os.Exit(0) } // Wait until BuildProofs() or buildOffsetFile() says it's ok to exit diff --git a/bridgenode/offsetfile.go b/bridgenode/offsetfile.go index 270f0e9a..bbf36006 100644 --- a/bridgenode/offsetfile.go +++ b/bridgenode/offsetfile.go @@ -230,7 +230,7 @@ func readRawHeadersFromFile(bufReader *bufio.Reader, fileDir string, fileNum uin panic(err) } // check if Bitcoin magic bytes were read - if util.CheckMagicByte(buf[:4]) == false { + if !util.CheckMagicByte(buf[:4]) { break } diff --git a/bridgenode/offsetfile_test.go b/bridgenode/offsetfile_test.go index 7e3e23d1..001d03f7 100644 --- a/bridgenode/offsetfile_test.go +++ b/bridgenode/offsetfile_test.go @@ -26,7 +26,10 @@ func BenchmarkBuildOffsetFile(b *testing.B) { tmpOffsetFile := filepath.Join(tmpDir, "offsetfile") tmpLastOffsetHeightFile := filepath.Join(tmpDir, "loffsetfile") - db := OpenIndexFile(testnetDataDir) + db, err := OpenIndexFile(testnetDataDir) + if err != nil { + b.Fatal(err) + } defer db.Close() hash, err := util.GenHashForNet(chaincfg.TestNet3Params) @@ -67,7 +70,10 @@ func TestBuildOffsetFile(t *testing.T) { t.Fatal(err) } - lvdb := OpenIndexFile(testnetDataDir) + lvdb, err := OpenIndexFile(testnetDataDir) + if err != nil { + t.Fatal(err) + } bnrChan := make(chan BlockAndRev, 10) fmt.Println("checking the offestfile created...") diff --git a/bridgenode/rev.go b/bridgenode/rev.go index 722b4686..efbf730e 100644 --- a/bridgenode/rev.go +++ b/bridgenode/rev.go @@ -44,7 +44,7 @@ type RawHeaderData struct { UndoPos uint32 } -// BlockReader is a wrapper around GetRawBlockFromFile so that the process +// BlockAndRevReader is a wrapper around GetRawBlockFromFile so that the process // can be made into a goroutine. As long as it's running, it keeps sending // the entire blocktxs and height to bchan with TxToWrite type. // It also puts in the proofs. This will run on the archive server, and the @@ -286,7 +286,7 @@ type BlockAndRev struct { type RevBlock struct { Magic [4]byte // Network magic bytes Size [4]byte // size of the BlockUndo record - Txs []*TxUndo // acutal undo record + Txs []*TxUndo // actual undo record Hash [32]byte // 32 byte double sha256 hash of the block } @@ -296,8 +296,8 @@ type TxUndo struct { TxIn []*TxInUndo } -// TxInUndo is the stucture of the undo transaction -// Eveything is uncompressed here +// TxInUndo is the structure of the undo transaction +// Everything is uncompressed here // see github.com/bitcoin/bitcoin/src/undo.h type TxInUndo struct { Height int32 @@ -383,7 +383,7 @@ func readTxInUndo(r io.Reader, ti *TxInUndo) error { ti.PKScript = decompressScript(r) if ti.PKScript == nil { - return fmt.Errorf("nil pkscript on h %d, pks %x\n", ti.Height, ti.PKScript) + return fmt.Errorf("nil pkscript on h %d, pks %x", ti.Height, ti.PKScript) } @@ -392,8 +392,7 @@ func readTxInUndo(r io.Reader, ti *TxInUndo) error { // OpenIndexFile returns the db with only read only option enabled func OpenIndexFile(dataDir string) (*leveldb.DB, error) { - var indexDir string - indexDir = filepath.Join(dataDir, "/index") + indexDir := filepath.Join(dataDir, "/index") // Read-only and no compression on // Bitcoin Core uses uncompressed leveldb. If that db is // opened EVEN ONCE, with compression on, the user will @@ -401,7 +400,7 @@ func OpenIndexFile(dataDir string) (*leveldb.DB, error) { o := opt.Options{ReadOnly: true, Compression: opt.NoCompression} lvdb, err := leveldb.OpenFile(indexDir, &o) if err != nil { - return nil, fmt.Errorf("can't open %s\n", indexDir) + return nil, fmt.Errorf("can't open %s", indexDir) } return lvdb, nil diff --git a/bridgenode/server.go b/bridgenode/server.go index 5d90141b..7fbc423d 100644 --- a/bridgenode/server.go +++ b/bridgenode/server.go @@ -11,7 +11,6 @@ import ( // blockServer listens on a TCP port for incoming connections, then gives // ublocks blocks over that connection func blockServer(endHeight int32, dataDir string, haltRequest, haltAccept chan bool) { - listenAdr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:8338") if err != nil { fmt.Printf(err.Error()) @@ -117,7 +116,7 @@ func serveBlocksWorker(c net.Conn, endHeight int32, blockDir string) { return } - // first send 4 byte lenght for everything + // first send 4 byte length for everything // fmt.Printf("h %d send len %d\n", curHeight, len(udb)+len(blkbytes)) err = binary.Write(c, binary.BigEndian, uint32(len(udb)+len(blkbytes))) if err != nil { diff --git a/bridgenode/ttl.go b/bridgenode/ttl.go index ae24a196..41b30176 100644 --- a/bridgenode/ttl.go +++ b/bridgenode/ttl.go @@ -9,7 +9,7 @@ import ( "github.com/syndtr/goleveldb/leveldb" ) -// DeathInfo is needed to asynchornously read from the leveldb +// DeathInfo is needed to asynchronously read from the leveldb // Insures that the TxOs are in order type DeathInfo struct { // DeathHeight is where the TxOs are spent diff --git a/cmd/utreexoserver/bridgeserver.go b/cmd/utreexoserver/bridgeserver.go index ceb4b874..7fa748d3 100644 --- a/cmd/utreexoserver/bridgeserver.go +++ b/cmd/utreexoserver/bridgeserver.go @@ -18,7 +18,7 @@ import ( var msg = ` Usage: server [OPTION] A dynamic hash based accumulator designed for the Bitcoin UTXO set -The birdgenode server generates proofs and serves to the CSN node. +The bridgenode server generates proofs and serves to the CSN node. OPTIONS: -net=mainnet configure whether to use mainnet. Optional. diff --git a/csn/ibd.go b/csn/ibd.go index bc411b7e..6079a46d 100644 --- a/csn/ibd.go +++ b/csn/ibd.go @@ -62,7 +62,7 @@ func (c *Csn) IBDThread(sig chan bool) { if c.CurrentHeight%10000 == 0 { fmt.Printf("Block %d add %d del %d %s plus %.2f total %.2f \n", c.CurrentHeight, totalTXOAdded, totalDels, c.pollard.Stats(), - plustime.Seconds(), time.Now().Sub(starttime).Seconds()) + plustime.Seconds(), time.Since(starttime).Seconds()) } // Check if stopSig is no longer false @@ -75,7 +75,7 @@ func (c *Csn) IBDThread(sig chan bool) { } fmt.Printf("Block %d add %d del %d %s plus %.2f total %.2f \n", c.CurrentHeight, totalTXOAdded, totalDels, c.pollard.Stats(), - plustime.Seconds(), time.Now().Sub(starttime).Seconds()) + plustime.Seconds(), time.Since(starttime).Seconds()) saveIBDsimData(c) diff --git a/csn/init.go b/csn/init.go index 7d301415..87b6eff8 100644 --- a/csn/init.go +++ b/csn/init.go @@ -14,7 +14,7 @@ import ( "github.com/mit-dci/utreexo/util" ) -// RunIBD calls evertyhing to run IBD +// RunIBD calls everything to run IBD func RunIBD( p *chaincfg.Params, host, watchAddr string, check bool, sig chan bool) error { @@ -50,7 +50,7 @@ func RunIBD( return err } if len(adrBytes) != 22 { - return fmt.Errorf("need a bech32 p2wpkh address, %s has %d bytes\n", + return fmt.Errorf("need a bech32 p2wpkh address, %s has %d bytes", watchAddr, len(adrBytes)) } @@ -70,8 +70,6 @@ func RunIBD( } } } - - return nil } // Start starts up a compact state node, and returns channels for txs and @@ -107,10 +105,8 @@ func (c *Csn) Start(height int32, func initCSNState() ( p accumulator.Pollard, height int32, utxos map[wire.OutPoint]util.LeafData, err error) { - var pollardInitialized bool - // bool to check if the pollarddata is present - pollardInitialized = util.HasAccess(util.PollardFilePath) + pollardInitialized := util.HasAccess(util.PollardFilePath) if pollardInitialized { fmt.Println("Has access to forestdata, resuming") @@ -138,7 +134,7 @@ func stopRunIBD(sig chan bool, stopGoing chan bool, done chan bool) { // Listen for SIGINT, SIGTERM, and SIGQUIT from the user <-sig - // Sometimes there are bugs that make the program run forver. + // Sometimes there are bugs that make the program run forever. // Utreexo binary should never take more than 10 seconds to exit go func() { time.Sleep(10 * time.Second) diff --git a/go.mod b/go.mod index 458fa18a..62c0fd93 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/btcsuite/btcutil v1.0.2 github.com/golang/snappy v0.0.1 // indirect github.com/syndtr/goleveldb v1.0.0 - golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 + golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect ) diff --git a/go.sum b/go.sum index afaa5304..72cab87b 100644 --- a/go.sum +++ b/go.sum @@ -6,26 +6,36 @@ github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufo github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts= github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE= github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/rjected/btcd v0.0.0-20200718165331-907190b086ba h1:RMaSvSBrULixyGJ8zGGzG+LvQ7BjtrjcF7HZmmf8raE= github.com/rjected/btcd v0.0.0-20200718165331-907190b086ba/go.mod h1:Yktc19YNjh/Iz2//CX0vfRTS4IJKM/RKO5YZ9Fn+Pgo= +github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -34,14 +44,22 @@ golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/test/csn_bridge.sh b/test/csn_bridge.sh index 60a04538..28e161cc 100755 --- a/test/csn_bridge.sh +++ b/test/csn_bridge.sh @@ -151,7 +151,7 @@ run_utreexo() { # run ibdsim log "running idbsim..." - eval "$IBDSIM > $TEST_DATA/ibdsim.log 2>&1" + eval "$IBDSIM -host 127.0.0.1 > $TEST_DATA/ibdsim.log 2>&1" kill -SIGQUIT $genproofs_id > /dev/null 2>&1 wait $genproofs_id diff --git a/util/paths.go b/util/paths.go index eb928df0..7555cc4a 100644 --- a/util/paths.go +++ b/util/paths.go @@ -43,7 +43,7 @@ var MiscForestFilePath string = filepath.Join(ForestDirPath, "miscforestfile.dat var ForestLastSyncedBlockHeightFilePath string = filepath.Join(ForestDirPath, "forestlastsyncedheight.dat") -// MakePaths makes the neccessary paths for all files +// MakePaths makes the necessary paths for all files func MakePaths() { os.MkdirAll(OffsetDirPath, os.ModePerm) os.MkdirAll(ProofDirPath, os.ModePerm) diff --git a/util/types.go b/util/types.go index 34536faf..006d4400 100644 --- a/util/types.go +++ b/util/types.go @@ -13,7 +13,7 @@ import ( type Hash [32]byte -// HashFromString hahes the given string with sha256 +// HashFromString hashes the given string with sha256 func HashFromString(s string) Hash { return sha256.Sum256([]byte(s)) } @@ -58,7 +58,7 @@ type LeafData struct { PkScript []byte } -// turn a LeafData into bytes +// ToString turns a LeafData into bytes func (l *LeafData) ToString() (s string) { s = l.Outpoint.String() // s += fmt.Sprintf(" bh %x ", l.BlockHash) @@ -114,8 +114,9 @@ func (l *LeafData) ToBytes() []byte { // can use tags for PkScript // so it's just height, coinbaseness, amt, pkscript tag -// turn a LeafData into bytes (compact, for sending in blockProof) - -// don't hash this, it doesn't commit to everything +// ToCompactBytes turns a LeafData into bytes +// (compact, for sending in blockProof) - don't hash this, +// it doesn't commit to everything func (l *LeafData) ToCompactBytes() []byte { l.Height <<= 1 if l.Coinbase { @@ -149,7 +150,7 @@ func LeafDataFromCompactBytes(b []byte) (LeafData, error) { return l, nil } -// turn a LeafData into a LeafHash +// LeafHash turns a LeafData into a LeafHash func (l *LeafData) LeafHash() [32]byte { return sha256.Sum256(l.ToBytes()) } @@ -261,7 +262,6 @@ func (ub *UBlock) Serialize(w io.Writer) (err error) { } func UDataFromBytes(b []byte) (ud UData, err error) { - // if there's no bytes, it's an empty uData if len(b) == 0 { return @@ -289,7 +289,7 @@ func UDataFromBytes(b []byte) (ud UData, err error) { ud.UtxoData = make([]LeafData, len(ud.AccProof.Targets)) var ldb []byte // loop until we've filled in every leafData (or something breaks first) - for i, _ := range ud.UtxoData { + for i := range ud.UtxoData { // fmt.Printf("leaf %d dataBytes %x ", i, leafDataBytes) ldb, leafDataBytes, err = PopPrefixLen16(leafDataBytes) if err != nil { diff --git a/util/utils.go b/util/utils.go index 534223ab..d3787745 100644 --- a/util/utils.go +++ b/util/utils.go @@ -51,7 +51,7 @@ func GenHashForNet(p chaincfg.Params) (*Hash, error) { case "regtest": return ®TestGenHash, nil } - return nil, fmt.Errorf("net not supported\n") + return nil, fmt.Errorf("net not supported") } // UblockNetworkReader gets Ublocks from the remote host and puts em in the @@ -106,13 +106,18 @@ func UblockNetworkReader( // fmt.Printf("copied %d bytes into buffer\n", n) err = ub.FromBytes(b) + if err != nil { + fmt.Printf("error from connection %s %s\n", + con.RemoteAddr().String(), err.Error()) + return + } ub.Height = curHeight blockChan <- ub } } -// GetUDataFromFile reads the proof data from proof.dat and proofoffset.dat +// GetUDataBytesFromFile reads the proof data from proof.dat and proofoffset.dat // and gives the proof & utxo data back. // Don't ask for block 0, there is no proof of that. func GetUDataBytesFromFile(height int32) (b []byte, err error) { @@ -344,9 +349,9 @@ func CheckMagicByte(bytesgiven []byte) bool { bytes.Compare(bytesgiven, []byte{0xfa, 0xbf, 0xb5, 0xda}) != 0 { // regtest fmt.Printf("got non magic bytes %x, finishing\n", bytesgiven) return false - } else { - return true } + + return true } // HasAccess reports whether we have access to the named file. @@ -364,8 +369,8 @@ func HasAccess(fileName string) bool { return true } -//IsUnspendable determines whether a tx is spenable or not. -//returns true if spendable, false if unspenable. +//IsUnspendable determines whether a tx is spendable or not. +//returns true if spendable, false if unspendable. func IsUnspendable(o *wire.TxOut) bool { switch { case len(o.PkScript) > 10000: //len 0 is OK, spendable