cleanup PR - remove unused code

parent 14cd5d21
......@@ -29,11 +29,10 @@ dependencies:
# pkgs changes which packages the makefile calls operate on. run changes which
# tests are run during testing.
run = Test
pkgs = ./api ./build ./compatibility ./crypto ./encoding ./modules ./modules/consensus \
./modules/explorer ./modules/gateway ./modules/host ./modules/host/storagemanager \
./modules/renter ./modules/renter/contractor ./modules/renter/hostdb ./modules/renter/proto \
./modules/miner ./modules/wallet ./modules/transactionpool ./persist ./siac ./siad ./sync ./types \
./modules/host/contractmanager
pkgs = ./api ./build ./compatibility ./crypto ./encoding ./modules ./modules/consensus \
./modules/explorer ./modules/gateway ./modules/host ./modules/host/contractmanager ./modules/host/storagemanager \
./modules/renter ./modules/renter/contractor ./modules/renter/hostdb ./modules/renter/proto \
./modules/miner ./modules/wallet ./modules/transactionpool ./persist ./siac ./siad ./sync ./types
# fmt calls go fmt on all packages.
fmt:
......
......@@ -28,7 +28,6 @@ func TestVersion(t *testing.T) {
// TestUpdate checks that /daemon/update correctly asserts that an update is
// not available for the daemon (since the test build is always up to date).
func TestUpdate(t *testing.T) {
t.Skip("offline")
if testing.Short() {
t.SkipNow()
}
......
......@@ -105,110 +105,3 @@ func TestNewContractManager(t *testing.T) {
t.Fatal(err)
}
}
/*
import (
"os"
"path/filepath"
"github.com/NebulousLabs/Sia/build"
"github.com/NebulousLabs/Sia/crypto"
"github.com/NebulousLabs/Sia/modules"
"github.com/NebulousLabs/Sia/persist"
)
// storageManagerTester holds a testing-initialized storage manager and any
// additional fields that may be useful while testing.
type storageManagerTester struct {
sm *StorageManager
persistDir string
}
// addRandFolder connects a storage folder to a random directory in the
// tester's persist dir.
func (smt *storageManagerTester) addRandFolder(size uint64) error {
dir := filepath.Join(smt.persistDir, persist.RandomSuffix())
err := os.Mkdir(dir, 0700)
if err != nil {
return err
}
return smt.sm.AddStorageFolder(dir, size)
}
// capacity returns the amount of storage still available on the machine. The
// amount can be negative if the total capacity was reduced to below the active
// capacity.
func (sm *StorageManager) capacity() (total, remaining uint64) {
// Total storage can be computed by summing the size of all the storage
// folders.
for _, sf := range sm.storageFolders {
total += sf.Size
remaining += sf.SizeRemaining
}
return total, remaining
}
// createSector makes a random, unique sector that can be inserted into the
// storage manager.
func createSector() (sectorRoot crypto.Hash, sectorData []byte, err error) {
sectorData, err = crypto.RandBytes(int(modules.SectorSize))
if err != nil {
return crypto.Hash{}, nil, err
}
sectorRoot = crypto.MerkleRoot(sectorData)
return sectorRoot, sectorData, nil
}
// newStorageManagerTester creates a storage tester ready for use.
func newStorageManagerTester(name string) (*storageManagerTester, error) {
testdir := build.TempDir(modules.StorageManagerDir, name)
sm, err := New(filepath.Join(testdir, modules.StorageManagerDir))
if err != nil {
return nil, err
}
smt := &storageManagerTester{
sm: sm,
persistDir: testdir,
}
return smt, nil
}
// probabilisticReset will probabilistically reboot the storage manager before
// continuing. This helps to verify that the persistence is working correctly.
// The reset is probabilistic to make sure that the test is not passing because
// of the reset.
func (smt *storageManagerTester) probabilisticReset() error {
rand, err := crypto.RandIntn(3)
if err != nil {
return err
}
if rand == 1 {
// Grab the potentially faulty dependencies and replace them with good
// dependencies so that closing happens without issues.
deps := smt.sm.dependencies
smt.sm.dependencies = productionDependencies{}
// Close the storage manager, then create a new storage manager to
// replace it.
err = smt.sm.Close()
if err != nil {
return err
}
// Open the storage manager with production dependencies so that there
// are no errors.
sm, err := New(filepath.Join(smt.persistDir, modules.StorageManagerDir))
if err != nil {
return err
}
sm.dependencies = deps
smt.sm = sm
}
return nil
}
// Close shuts down all of the components of the storage manager tester.
func (smt *storageManagerTester) Close() error {
return smt.sm.Close()
}
*/
package contractmanager
/*
import (
"testing"
"github.com/NebulousLabs/Sia/types"
)
// TestMaxVirtualSectors checks that the max virtual sector limit is enforced
// when adding sectors.
func TestMaxVirtualSectors(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestMaxVirtualSectors")
if err != nil {
t.Fatal(err)
}
defer smt.Close()
// Add a storage folder to receive a sector.
err = smt.sm.AddStorageFolder(smt.persistDir, minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
// Add the first instance of the sector.
sectorRoot, sectorData, err := createSector()
if err != nil {
t.Fatal(err)
}
err = smt.sm.AddSector(sectorRoot, 1, sectorData)
if err != nil {
t.Fatal(err)
}
// Add virtual instances of the sector until there are no more available
// virual slots.
for i := 1; i < maximumVirtualSectors; i++ {
err = smt.sm.AddSector(sectorRoot, types.BlockHeight(i%3+2), sectorData)
if err != nil {
t.Fatal(err)
}
}
// Add another virtual sector, an error should be returned.
err = smt.sm.AddSector(sectorRoot, 1, sectorData)
if err != errMaxVirtualSectors {
t.Fatal(err)
}
}
// TestBadSectorAdd triggers a panic by trying to add an illegal sector.
func TestBadSectorAdd(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestBadSectorAdd")
if err != nil {
t.Fatal(err)
}
defer smt.Close()
// Add a storage folder to receive a sector.
err = smt.sm.AddStorageFolder(smt.persistDir, minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
defer func() {
r := recover()
if r == nil {
t.Fatal("did not trigger panic when adding a bad sector")
}
}()
sectorRoot, sectorData, err := createSector()
if err != nil {
t.Fatal(err)
}
// Error doesn't need to be checked, a panic will be thrown.
_ = smt.sm.AddSector(sectorRoot, 1, sectorData[:1])
t.Fatal("panic not thrown")
}
*/
......@@ -681,25 +681,4 @@ func (sm *StorageManager) ResizeStorageFolder(storageFolderIndex int, newSize ui
resizeFolder.SizeRemaining = 0
return sm.saveSync()
}
// StorageFolders provides information about all of the storage folders in the
// host.
func (sm *StorageManager) StorageFolders() (sfms []modules.StorageFolderMetadata) {
sm.mu.RLock()
defer sm.mu.RUnlock()
for _, sf := range sm.storageFolders {
sfms = append(sfms, modules.StorageFolderMetadata{
Capacity: sf.Size,
CapacityRemaining: sf.SizeRemaining,
Path: sf.Path,
FailedReads: sf.FailedReads,
FailedWrites: sf.FailedWrites,
SuccessfulReads: sf.SuccessfulReads,
SuccessfulWrites: sf.SuccessfulWrites,
})
}
return sfms
}
*/
package contractmanager
/*
import (
"errors"
"path/filepath"
"testing"
"github.com/NebulousLabs/Sia/modules"
)
// TestClosedStorageManagerOperations tries a bunch of operations on the storage manager
// after it has been closed.
func TestClosedStorageManagerOperations(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestClosedStorageManagerOperations")
if err != nil {
t.Fatal(err)
}
// Close the storage manager.
err = smt.sm.Close()
if err != nil {
t.Fatal(err)
}
defer smt.Close()
err = smt.sm.AddStorageFolder(filepath.Join(smt.persistDir, modules.StorageManagerDir), minimumStorageFolderSize)
if err != errStorageManagerClosed {
t.Fatal("expected errStorageManagerClosed:", err)
}
err = smt.sm.RemoveStorageFolder(1, true)
if err != errStorageManagerClosed {
t.Fatal("expected errStorageManagerClosed:", err)
}
err = smt.sm.ResizeStorageFolder(0, minimumStorageFolderSize)
if err != errStorageManagerClosed {
t.Fatal("expected errStorageManagerClosed:", err)
}
// Number of storage folders should still be zero.
if len(smt.sm.storageFolders) != 0 {
t.Error("storage folder should not have been added to the storage manager as the storage manager is closed.")
}
}
// faultyRand is a mocked filesystem which can be configured to fail for certain
// files and folders.
type faultyRand struct {
productionDependencies
}
// errMockBadRand is returned when a mocked dependency is intentionally
// returning an error instead of randomly generating data.
var errMockBadRand = errors.New("mocked randomness is intentionally failing")
// randRead replaces the production dependency crypto/rand.Read with a faulty
// reader - an error is always returned.
func (faultyRand) randRead([]byte) (int, error) {
return 0, errMockBadRand
}
// TestAddFolderNoRand tries adding a folder to the storage manager when the
// cryptographic randomness generator is not working.
func TestAddFolderNoRand(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestAddFolderNoRand")
if err != nil {
t.Fatal(err)
}
defer smt.Close()
// Replace the storage manager with one that cannot do randomness
// operations.
err = smt.sm.Close()
if err != nil {
t.Fatal(err)
}
smt.sm, err = newStorageManager(faultyRand{}, filepath.Join(smt.persistDir, modules.StorageManagerDir))
if err != nil {
t.Fatal(err)
}
err = smt.sm.AddStorageFolder(filepath.Join(smt.persistDir, modules.StorageManagerDir), minimumStorageFolderSize)
if err != errMockBadRand {
t.Fatal(err)
}
// Number of storage folders should be zero.
storageFolders := smt.sm.StorageFolders()
if len(storageFolders) != 0 {
t.Error("storage folder was added to the storage manager despite a dependency failure")
}
}
*/
package contractmanager
/*
import (
"testing"
"github.com/NebulousLabs/Sia/crypto"
"github.com/NebulousLabs/Sia/modules"
)
// TestStorageFolderUIDString probes the uidString method of the storage
// folder.
func TestStorageFolderUIDString(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
// Create a series of uid->string mappings that represent the expected
// output of calling uidString on a storage folder.
trials := []struct {
uid []byte
str string
}{
{
[]byte{0},
"00",
},
{
[]byte{255},
"ff",
},
{
[]byte{50},
"32",
},
{
[]byte{61},
"3d",
},
{
[]byte{248},
"f8",
},
}
for _, trial := range trials {
sf := &storageFolder{
UID: trial.uid,
}
str := sf.uidString()
if str != trial.str {
t.Error("failed UID string trial", str, sf.uidString())
}
}
}
// TestStorageFolderUIDStringSanity probes the sanity checks of the uidString
// method of the storage folder.
func TestStorageFolderUIDStringSanity(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
// Create a storage folder with an illegal UID size.
sf := &storageFolder{
UID: []byte{0, 1},
}
// Catch the resulting panic.
defer func() {
r := recover()
if r == nil {
t.Error("sanity check was not triggered upon incorrect usage of uidString")
}
}()
_ = sf.uidString()
}
// TestAddStorageFolderUIDCollisions checks that storage folders can be added
// with no risk of producing collisions in the storage folder UIDs. This test
// relies on (explicitly checked) assumptions about the size of the name and
// the number of allowed storage folders.
func TestAddStorageFolderUIDCollisions(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestAddStorageFolderUIDCollisions")
if err != nil {
t.Fatal(err)
}
defer smt.Close()
// Check that the environment requirements for the test have been met.
if storageFolderUIDSize != 1 {
t.Fatal("For this test, the storage manager must be using storage folder UIDs that are 1 byte")
}
if maximumStorageFolders < 100 {
t.Fatal("For this test, the storage manager must be allowed to have at least 100 storage folders")
}
// Create 100 storage folders, and check that there are no collisions
// between any of them. Because the UID is only using 1 byte, once there
// are more than 64 there will be at least 1/4 chance of a collision for
// each randomly selected UID. Running into collisions is virtually
// guaranteed, and running into repeated collisions (where two UIDs
// consecutively collide with existing UIDs) are highly likely.
for i := 0; i < maximumStorageFolders; i++ {
err = smt.addRandFolder(minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
}
// Check that there are no collisions.
uidMap := make(map[uint8]struct{})
for _, sf := range smt.sm.storageFolders {
_, exists := uidMap[uint8(sf.UID[0])]
if exists {
t.Error("Collision")
}
uidMap[uint8(sf.UID[0])] = struct{}{}
}
// For coverage purposes, try adding a storage folder after the maximum
// number of storage folders has been reached.
err = smt.addRandFolder(minimumStorageFolderSize)
if err != errMaxStorageFolders {
t.Fatal("expecting errMaxStorageFolders:", err)
}
// Try again, this time removing a random storage folder and then adding
// another one repeatedly - enough times to exceed the 256 possible folder
// UIDs that can be chosen in the testing environment.
for i := 0; i < 300; i++ {
// Replace the very first storage folder.
err = smt.sm.RemoveStorageFolder(0, false)
if err != nil {
t.Fatal(err)
}
err = smt.addRandFolder(minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
// Replace a random storage folder.
n, err := crypto.RandIntn(100)
if err != nil {
t.Fatal(err)
}
err = smt.sm.RemoveStorageFolder(n, false)
if err != nil {
t.Fatal(err)
}
err = smt.addRandFolder(minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
}
uidMap = make(map[uint8]struct{})
for _, sf := range smt.sm.storageFolders {
_, exists := uidMap[uint8(sf.UID[0])]
if exists {
t.Error("Collision")
}
uidMap[uint8(sf.UID[0])] = struct{}{}
}
}
// TestEmptiestStorageFolder checks that emptiestStorageFolder will correctly
// select the emptiest storage folder out of a provided list of storage
// folders.
func TestEmptiestStorageFolder(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
// Create a series of uid->string mappings that represent the expected
// output of calling uidString on a storage folder.
trials := []struct {
folders []*storageFolder
emptiestIndex int
}{
// Empty input.
{
[]*storageFolder{},
-1,
},
// Single valid storage folder.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: minimumStorageFolderSize,
},
},
0,
},
// Single full storage folder.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: 0,
},
},
-1,
},
// Single nearly full storage folder.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize - 1,
},
},
-1,
},
// Two valid storage folders, first is emptier.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize + 1,
},
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize,
},
},
0,
},
// Two valid storage folders, second is emptier.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize,
},
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize + 1,
},
},
1,
},
// Two valid storage folders, first is emptier by percentage but can't
// hold a new sector.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize - 1,
},
{
Size: minimumStorageFolderSize * 5,
SizeRemaining: modules.SectorSize,
},
},
1,
},
// Two valid storage folders, first is emptier by volume but not
// percentage.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: modules.SectorSize * 2,
},
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize,
},
},
1,
},
// Two valid storage folders, second is emptier by volume but not
// percentage.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize,
},
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: modules.SectorSize * 2,
},
},
0,
},
// Three valid storage folders, second is emptier by percentage but not
// volume.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: modules.SectorSize * 2,
},
{
Size: minimumStorageFolderSize,
SizeRemaining: modules.SectorSize,
},
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: modules.SectorSize * 2,
},
},
1,
},
// Three storage folders, none have room for a sector.
{
[]*storageFolder{
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: modules.SectorSize - 1,
},
{
Size: minimumStorageFolderSize,
SizeRemaining: 0,
},
{
Size: minimumStorageFolderSize * 4,
SizeRemaining: 1,
},
},
-1,
},
}
for i, trial := range trials {
sf, index := emptiestStorageFolder(trial.folders)
if index != trial.emptiestIndex {
t.Error("trial", i, "index mismatch")
}
if index > 0 && sf != trial.folders[index] {
t.Error("trial", i, "folder mismatch")
}
if index < 0 && sf != nil {
t.Error("non-nil storage folder returned but there was no winner")
}
}
}
// TestRepeatStorageFolderPath checks that the host correctly rejects a storage
// folder if there is already a storage folder linked to the same path.
func TestRepeatStorageFolderPath(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
smt, err := newStorageManagerTester("TestRepeatStorageFolderPath")
if err != nil {
t.Fatal(err)
}
defer smt.Close()
err = smt.sm.AddStorageFolder(smt.persistDir, minimumStorageFolderSize)
if err != nil {
t.Fatal(err)
}
err = smt.sm.AddStorageFolder(smt.persistDir, minimumStorageFolderSize)
if err != errRepeatFolder {
t.Fatal("expected errRepeatFolder, got", err)
}
}
*/
package main
import (
"bytes"
"fmt"
"os"
"strconv"
"sync"
"syscall"
"time"
"github.com/NebulousLabs/Sia/crypto"
)
type replace struct {
c chan struct{}
}
func setBits(i uint32) uint64 {
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return uint64((((i + (i >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24)
}
// TODO: turn this into a benchmark in the storagemanager2