Commit 43be2972 authored by David Vorick's avatar David Vorick

extend and repair renter + hostdb testing

parent 3ec8fc95
......@@ -288,6 +288,7 @@ func TestHostDBAndRenterDownloadDynamicIPs(t *testing.T) {
allowanceValues := url.Values{}
testFunds := "10000000000000000000000000000" // 10k SC
testPeriod := "10"
testPeriodInt := 10
allowanceValues.Set("funds", testFunds)
allowanceValues.Set("period", testPeriod)
err = st.stdPostAPI("/renter", allowanceValues)
......@@ -336,6 +337,19 @@ func TestHostDBAndRenterDownloadDynamicIPs(t *testing.T) {
t.Fatal("data mismatch when downloading a file")
}
// Mine a block before resetting the host, so that the host doesn't lose
// it's contracts when the transaction pool resets.
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
// Close and re-open the host. This should reset the host's address, as the
// host should now be on a new port.
err = stHost.server.Close()
......@@ -399,6 +413,36 @@ func TestHostDBAndRenterDownloadDynamicIPs(t *testing.T) {
if bytes.Compare(orig, download) != 0 {
t.Fatal("data mismatch when downloading a file")
}
// Mine enough blocks that multiple renew cylces happen. After the renewing
// happens, the file should still be downloadable. This is to check that the
// renewal doesn't throw things off.
for i := 0; i < testPeriodInt; i++ {
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
}
// Try downloading the file.
err = st.stdGetAPI("/renter/download/test?destination=" + downpath)
if err != nil {
t.Fatal(err)
}
// Check that the download has the right contents.
download, err = ioutil.ReadFile(downpath)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(orig, download) != 0 {
t.Fatal("data mismatch when downloading a file")
}
}
// TestHostDBAndRenterUploadDynamicIPs checks that the hostdb and the renter are
......@@ -462,6 +506,7 @@ func TestHostDBAndRenterUploadDynamicIPs(t *testing.T) {
allowanceValues := url.Values{}
testFunds := "10000000000000000000000000000" // 10k SC
testPeriod := "10"
testPeriodInt := 10
allowanceValues.Set("funds", testFunds)
allowanceValues.Set("period", testPeriod)
err = st.stdPostAPI("/renter", allowanceValues)
......@@ -491,6 +536,19 @@ func TestHostDBAndRenterUploadDynamicIPs(t *testing.T) {
t.Fatal("the uploading is not succeeding for some reason:", rf.Files[0])
}
// Mine a block before resetting the host, so that the host doesn't lose
// it's contracts when the transaction pool resets.
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
// Close and re-open the host. This should reset the host's address, as the
// host should now be on a new port.
err = stHost.server.Close()
......@@ -581,6 +639,59 @@ func TestHostDBAndRenterUploadDynamicIPs(t *testing.T) {
if bytes.Compare(orig2, download2) != 0 {
t.Fatal("data mismatch when downloading a file")
}
// Mine enough blocks that multiple renew cylces happen. After the renewing
// happens, the file should still be downloadable. This is to check that the
// renewal doesn't throw things off.
for i := 0; i < testPeriodInt; i++ {
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
}
// Try downloading the file.
downpath := filepath.Join(st.dir, "testdown.dat")
err = st.stdGetAPI("/renter/download/test?destination=" + downpath)
if err != nil {
t.Fatal(err)
}
// Check that the download has the right contents.
download, err := ioutil.ReadFile(downpath)
if err != nil {
t.Fatal(err)
}
orig, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(orig, download) != 0 {
t.Fatal("data mismatch when downloading a file")
}
// Try downloading the second file.
err = st.stdGetAPI("/renter/download/test2?destination=" + downpath2)
if err != nil {
t.Fatal(err)
}
// Check that the download has the right contents.
orig2, err = ioutil.ReadFile(path2)
if err != nil {
t.Fatal(err)
}
download2, err = ioutil.ReadFile(downpath2)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(orig2, download2) != 0 {
t.Fatal("data mismatch when downloading a file")
}
}
// TestHostDBAndRenterFormDynamicIPs checks that the hostdb and the renter are
......@@ -640,6 +751,19 @@ func TestHostDBAndRenterFormDynamicIPs(t *testing.T) {
addr := ah.Hosts[0].NetAddress
pks := ah.Hosts[0].PublicKeyString
// Mine a block before resetting the host, so that the host doesn't lose
// it's contracts when the transaction pool resets.
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
// Close and re-open the host. This should reset the host's address, as the
// host should now be on a new port.
err = stHost.server.Close()
......@@ -694,6 +818,7 @@ func TestHostDBAndRenterFormDynamicIPs(t *testing.T) {
allowanceValues := url.Values{}
testFunds := "10000000000000000000000000000" // 10k SC
testPeriod := "10"
testPeriodInt := 10
allowanceValues.Set("funds", testFunds)
allowanceValues.Set("period", testPeriod)
err = st.stdPostAPI("/renter", allowanceValues)
......@@ -741,6 +866,36 @@ func TestHostDBAndRenterFormDynamicIPs(t *testing.T) {
if bytes.Compare(orig, download) != 0 {
t.Fatal("data mismatch when downloading a file")
}
// Mine enough blocks that multiple renew cylces happen. After the renewing
// happens, the file should still be downloadable. This is to check that the
// renewal doesn't throw things off.
for i := 0; i < testPeriodInt; i++ {
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
}
// Try downloading the file.
err = st.stdGetAPI("/renter/download/test?destination=" + downpath)
if err != nil {
t.Fatal(err)
}
// Check that the download has the right contents.
download, err = ioutil.ReadFile(downpath)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(orig, download) != 0 {
t.Fatal("data mismatch when downloading a file")
}
}
// TestHostDBAndRenterRenewDynamicIPs checks that the hostdb and the renter are
......@@ -846,6 +1001,19 @@ func TestHostDBAndRenterRenewDynamicIPs(t *testing.T) {
t.Fatal("data mismatch when downloading a file")
}
// Mine a block before resetting the host, so that the host doesn't lose
// it's contracts when the transaction pool resets.
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
_, err = synchronizationCheck(sts)
if err != nil {
t.Fatal(err)
}
// Give time for the upgrade to happen.
time.Sleep(time.Second * 3)
// Close and re-open the host. This should reset the host's address, as the
// host should now be on a new port.
err = stHost.server.Close()
......@@ -892,8 +1060,7 @@ func TestHostDBAndRenterRenewDynamicIPs(t *testing.T) {
// Mine enough blocks that multiple renew cylces happen. After the renewing
// happens, the file should still be downloadable.
println("mining blocks")
for i := 0; i < testPeriodInt*2; i++ {
for i := 0; i < testPeriodInt; i++ {
_, err = st.miner.AddBlock()
if err != nil {
t.Fatal(err)
......
......@@ -136,6 +136,8 @@ func (c *Contractor) Downloader(id types.FileContractID) (_ Downloader, err erro
} else if host.DownloadBandwidthPrice.Cmp(maxDownloadPrice) > 0 {
return nil, errTooExpensive
}
// Update the contract to the most recent net address for the host.
contract.NetAddress = host.NetAddress
// acquire revising lock
c.mu.Lock()
......@@ -167,13 +169,6 @@ func (c *Contractor) Downloader(id types.FileContractID) (_ Downloader, err erro
}
}
// Update the contract to the most recent net address for the host.
host, exists := c.hdb.Host(contract.HostPublicKey)
if !exists {
return nil, errors.New("unable to find the contract's host in the host database")
}
contract.NetAddress = host.NetAddress
// create downloader
d, err := proto.NewDownloader(host, contract)
if proto.IsRevisionMismatch(err) {
......
......@@ -200,6 +200,7 @@ func (c *Contractor) Editor(id types.FileContractID) (_ Editor, err error) {
host.Collateral = maxUploadCollateral
}
}
contract.NetAddress = host.NetAddress
// acquire revising lock
c.mu.Lock()
......@@ -231,13 +232,6 @@ func (c *Contractor) Editor(id types.FileContractID) (_ Editor, err error) {
}
}
// Make sure that we have the most recent net address for this host.
host, exists := c.hdb.Host(contract.HostPublicKey)
if !exists {
return nil, errors.New("unable to find the host in the hostdb")
}
contract.NetAddress = host.NetAddress
// create editor
e, err := proto.NewEditor(host, contract, height)
if proto.IsRevisionMismatch(err) {
......
......@@ -14,13 +14,10 @@ import (
// It returns the new contract. This is a blocking call that performs network
// I/O.
func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors uint64, newEndHeight types.BlockHeight) (modules.RenterContract, error) {
println("performing renew")
host, ok := c.hdb.Host(contract.HostPublicKey)
if !ok {
println("a")
return modules.RenterContract{}, errors.New("no record of that host")
} else if host.StoragePrice.Cmp(maxStoragePrice) > 0 {
println("b")
return modules.RenterContract{}, errTooExpensive
}
// cap host.MaxCollateral
......@@ -34,7 +31,6 @@ func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors ui
// get an address to use for negotiation
uc, err := c.wallet.NextAddress()
if err != nil {
println("c")
return modules.RenterContract{}, err
}
......@@ -62,7 +58,6 @@ func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors ui
if !ok {
// nothing we can do; return original error
c.log.Printf("wanted to recover contract %v with host %v, but no revision was cached", contract.ID, contract.NetAddress)
println("d")
return modules.RenterContract{}, err
}
c.log.Printf("host %v has different revision for %v; retrying with cached revision", contract.NetAddress, contract.ID)
......@@ -73,11 +68,9 @@ func (c *Contractor) managedRenew(contract modules.RenterContract, numSectors ui
}
if err != nil {
txnBuilder.Drop() // return unused outputs to wallet
println("e")
return modules.RenterContract{}, err
}
println("renew successful")
return newContract, nil
}
......
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