Commit 6892bbc9 authored by David Vorick's avatar David Vorick

address most pr comments

parent 09e7d422
......@@ -68,11 +68,11 @@ pkgs = ./api ./build ./compatibility ./crypto ./encoding ./modules ./modules/con
./modules/miner ./modules/renter ./modules/transactionpool \
./modules/wallet ./persist ./siac ./siae ./types
test: REBUILD
go test -short -tags='testing' -timeout=3s $(pkgs) -run $(run)
go test -short -tags='testing' -timeout=3s $(pkgs) -run=$(run)
test-v: REBUILD
go test -race -v -short -tags='debug testing' -timeout=15s $(pkgs) -run $(run)
go test -race -v -short -tags='debug testing' -timeout=15s $(pkgs) -run=$(run)
test-long: clean fmt REBUILD
go test -v -race -tags='testing debug' -timeout=300s $(pkgs) -run $(run)
go test -v -race -tags='testing debug' -timeout=300s $(pkgs) -run=$(run)
bench: clean fmt REBUILD
go test -tags='testing' -timeout=300s -run=XXX -bench=. $(pkgs)
cover: clean REBUILD
......
......@@ -45,7 +45,8 @@ func createReorgSets(name string) *reorgSets {
// save takes all of the blocks in cstMain and moves them to cstBackup.
func (rs *reorgSets) save() {
for i := types.BlockHeight(1); i <= rs.cstMain.cs.dbBlockHeight(); i++ {
mainHeight := rs.cstMain.cs.dbBlockHeight()
for i := types.BlockHeight(1); i <= mainHeight; i++ {
id, err := rs.cstMain.cs.dbGetPath(i)
if err != nil {
panic(err)
......
......@@ -17,7 +17,7 @@ import (
// TestIntegrationDoSBlockHandling checks that saved bad blocks are correctly ignored.
func TestIntegrationDoSBlockHandling(t *testing.T) {
// TestIntegrationDoSBlockHandling catches a wide array of simple errors,
// and therefore is included in the short tests despite being someone
// and therefore is included in the short tests despite being somewhat
// computationally expensive.
cst, err := createConsensusSetTester("TestIntegrationDoSBlockHandling")
if err != nil {
......
......@@ -120,7 +120,7 @@ func applyFileContractRevisions(tx *bolt.Tx, pb *processedBlock, t types.Transac
func applyStorageProofs(tx *bolt.Tx, pb *processedBlock, t types.Transaction) {
for _, sp := range t.StorageProofs {
fc, err := getFileContract(tx, sp.ParentID)
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -153,7 +153,7 @@ func applySiafundInputs(tx *bolt.Tx, pb *processedBlock, t types.Transaction) {
for _, sfi := range t.SiafundInputs {
// Calculate the volume of siacoins to put in the claim output.
sfo, err := getSiafundOutput(tx, sfi.ParentID)
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
claimPortion := getSiafundPool(tx).Sub(sfo.ClaimStart).Div(types.SiafundCount).Mul(sfo.Value)
......
package consensus
import (
"bytes"
"errors"
"fmt"
"strings"
"github.com/boltdb/bolt"
......@@ -47,7 +47,7 @@ func consensusChecksum(tx *bolt.Tx) crypto.Hash {
err := tx.ForEach(func(name []byte, b *bolt.Bucket) error {
// If the bucket is not a delayed siacoin output bucket or a file
// contract expiration bucket, skip.
if !strings.HasPrefix(string(name), string(prefixDSCO)) && !strings.HasPrefix(string(name), string(prefixFCEX)) {
if !bytes.HasPrefix(name, prefixDSCO) && !bytes.HasPrefix(name, prefixFCEX) {
return nil
}
......@@ -73,7 +73,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
var dscoSiacoins types.Currency
err := tx.ForEach(func(name []byte, b *bolt.Bucket) error {
// Check if the bucket is a delayed siacoin output bucket.
if !strings.HasPrefix(string(name), string(prefixDSCO)) {
if !bytes.HasPrefix(name, prefixDSCO) {
return nil
}
......@@ -92,7 +92,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
}
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -107,7 +107,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
scoSiacoins = scoSiacoins.Add(sco.Value)
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -123,7 +123,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
fcSiacoins = fcSiacoins.Add(fcCoins)
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -141,7 +141,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
claimSiacoins = claimSiacoins.Add(claimCoins)
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -157,7 +157,7 @@ func checkSiacoinCount(tx *bolt.Tx) {
}
totalSiacoins := dscoSiacoins.Add(scoSiacoins).Add(fcSiacoins).Add(claimSiacoins)
if totalSiacoins.Cmp(expectedSiacoins) != 0 {
if build.DEBUG && totalSiacoins.Cmp(expectedSiacoins) != 0 {
fmt.Println("Wrong number of siacoins... diagnostics:")
fmt.Println("Dsco:", dscoSiacoins)
fmt.Println("Sco:", scoSiacoins)
......@@ -189,7 +189,7 @@ func checkSiafundCount(tx *bolt.Tx) {
total = total.Add(sfo.Value)
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
if total.Cmp(types.SiafundCount) != 0 {
......@@ -210,7 +210,7 @@ func checkDSCOs(tx *bolt.Tx) {
err := tx.ForEach(func(name []byte, b *bolt.Bucket) error {
// If the bucket is not a delayed siacoin output bucket or a file
// contract expiration bucket, skip.
if !strings.HasPrefix(string(name), string(prefixDSCO)) {
if !bytes.HasPrefix(name, prefixDSCO) {
return nil
}
......@@ -258,7 +258,7 @@ func checkDSCOs(tx *bolt.Tx) {
}
return nil
})
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
......@@ -270,12 +270,12 @@ func checkDSCOs(tx *bolt.Tx) {
continue
}
_, exists := dscoTracker[i]
if !exists {
if build.DEBUG && !exists {
panic("missing a dsco bucket")
}
expectedBuckets++
}
if len(dscoTracker) != expectedBuckets {
if build.DEBUG && len(dscoTracker) != expectedBuckets {
panic("too many dsco buckets")
}
}
......@@ -292,24 +292,24 @@ func (cs *ConsensusSet) checkRevertApply(tx *bolt.Tx) {
}
parent, err := getBlockMap(tx, current.Block.ParentID)
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
if current.Height != parent.Height+1 {
if build.DEBUG && current.Height != parent.Height+1 {
panic("parent structure of a block is incorrect")
}
_, _, err = cs.forkBlockchain(tx, parent)
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
if consensusChecksum(tx) != parent.ConsensusChecksum {
if build.DEBUG && consensusChecksum(tx) != parent.ConsensusChecksum {
panic("consensus checksum mismatch after reverting")
}
_, _, err = cs.forkBlockchain(tx, current)
if err != nil {
if build.DEBUG && err != nil {
panic(err)
}
if consensusChecksum(tx) != current.ConsensusChecksum {
if build.DEBUG && consensusChecksum(tx) != current.ConsensusChecksum {
panic("consensus checksum mismatch after re-applying")
}
}
......
......@@ -26,8 +26,8 @@ const (
func blockHistory(tx *bolt.Tx) (blockIDs [32]types.BlockID) {
height := blockHeight(tx)
step := types.BlockHeight(1)
// The final step is to include the genesis block, which is why `step <
// height` is used as opposed to `step <= height`.
// The final step is to include the genesis block, which is why the final
// element is skipped during iteration.
for i := 0; i < 31; i++ {
// Include the next block.
blockID, err := getPath(tx, height)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment