From 759ae164f7d99c7148a3dd5e4e56ad142ee561ce Mon Sep 17 00:00:00 2001 From: mike76-dev Date: Wed, 2 Aug 2023 00:52:19 +0200 Subject: [PATCH 1/2] Fix write to a nil map in contract maintenance --- modules/renter/contractor/consts.go | 10 +++++----- modules/renter/contractor/contractmaintenance.go | 2 +- modules/renter/contractor/contractor.go | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/renter/contractor/consts.go b/modules/renter/contractor/consts.go index 44fa9222c7..c588aed451 100644 --- a/modules/renter/contractor/consts.go +++ b/modules/renter/contractor/consts.go @@ -46,11 +46,11 @@ var ( // consecutiveRenewalsBeforeReplacement is the number of times a contract // attempt to be renewed before it is marked as !goodForRenew. consecutiveRenewalsBeforeReplacement = build.Select(build.Var{ - Dev: types.BlockHeight(12), - Standard: types.BlockHeight(12), // ~2h - Testnet: types.BlockHeight(12), // ~2h - Testing: types.BlockHeight(12), - }).(types.BlockHeight) + Dev: uint64(12), + Standard: uint64(12), // ~2h + Testnet: uint64(12), // ~2h + Testing: uint64(12), + }).(uint64) // fileContractMinimumFunding is the lowest percentage of an allowace (on a // per-contract basis) that is allowed to go into funding a contract. If the diff --git a/modules/renter/contractor/contractmaintenance.go b/modules/renter/contractor/contractmaintenance.go index 33bfd53c7f..bb1acb2b5e 100644 --- a/modules/renter/contractor/contractmaintenance.go +++ b/modules/renter/contractor/contractmaintenance.go @@ -1188,7 +1188,7 @@ func (c *Contractor) threadedContractMaintenance() { // that we use to track how many times consecutively we failed to renew a // contract with a host, so that we know if we need to abandon that host. c.mu.Lock() - newFirstFailedRenew := make(map[types.FileContractID]types.BlockHeight) + newFirstFailedRenew := make(map[types.FileContractID]uint64) for _, r := range renewSet { if _, exists := c.numFailedRenews[r.id]; exists { newFirstFailedRenew[r.id] = c.numFailedRenews[r.id] diff --git a/modules/renter/contractor/contractor.go b/modules/renter/contractor/contractor.go index c789b2e592..c1780088d6 100644 --- a/modules/renter/contractor/contractor.go +++ b/modules/renter/contractor/contractor.go @@ -86,7 +86,7 @@ type Contractor struct { downloaders map[types.FileContractID]*hostDownloader editors map[types.FileContractID]*hostEditor sessions map[types.FileContractID]*hostSession - numFailedRenews map[types.FileContractID]types.BlockHeight + numFailedRenews map[types.FileContractID]uint64 renewing map[types.FileContractID]bool // prevent revising during renewal // pubKeysToContractID is a map of host pubkeys to the latest contract ID @@ -492,6 +492,7 @@ func contractorBlockingStartup(cs modules.ConsensusSet, w modules.Wallet, tp mod renewing: make(map[types.FileContractID]bool), renewedFrom: make(map[types.FileContractID]types.FileContractID), renewedTo: make(map[types.FileContractID]types.FileContractID), + numFailedRenews: make(map[types.FileContractID]uint64), workerPool: emptyWorkerPool{}, } c.staticChurnLimiter = newChurnLimiter(c) From 232d41f705c678bc692ac740a9d13740c670a032 Mon Sep 17 00:00:00 2001 From: mike76-dev Date: Wed, 2 Aug 2023 09:03:34 +0200 Subject: [PATCH 2/2] Revert to `types.BlockHeight` instead of `uint64` --- modules/renter/contractor/consts.go | 10 +++++----- modules/renter/contractor/contractmaintenance.go | 2 +- modules/renter/contractor/contractor.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/renter/contractor/consts.go b/modules/renter/contractor/consts.go index c588aed451..44fa9222c7 100644 --- a/modules/renter/contractor/consts.go +++ b/modules/renter/contractor/consts.go @@ -46,11 +46,11 @@ var ( // consecutiveRenewalsBeforeReplacement is the number of times a contract // attempt to be renewed before it is marked as !goodForRenew. consecutiveRenewalsBeforeReplacement = build.Select(build.Var{ - Dev: uint64(12), - Standard: uint64(12), // ~2h - Testnet: uint64(12), // ~2h - Testing: uint64(12), - }).(uint64) + Dev: types.BlockHeight(12), + Standard: types.BlockHeight(12), // ~2h + Testnet: types.BlockHeight(12), // ~2h + Testing: types.BlockHeight(12), + }).(types.BlockHeight) // fileContractMinimumFunding is the lowest percentage of an allowace (on a // per-contract basis) that is allowed to go into funding a contract. If the diff --git a/modules/renter/contractor/contractmaintenance.go b/modules/renter/contractor/contractmaintenance.go index bb1acb2b5e..33bfd53c7f 100644 --- a/modules/renter/contractor/contractmaintenance.go +++ b/modules/renter/contractor/contractmaintenance.go @@ -1188,7 +1188,7 @@ func (c *Contractor) threadedContractMaintenance() { // that we use to track how many times consecutively we failed to renew a // contract with a host, so that we know if we need to abandon that host. c.mu.Lock() - newFirstFailedRenew := make(map[types.FileContractID]uint64) + newFirstFailedRenew := make(map[types.FileContractID]types.BlockHeight) for _, r := range renewSet { if _, exists := c.numFailedRenews[r.id]; exists { newFirstFailedRenew[r.id] = c.numFailedRenews[r.id] diff --git a/modules/renter/contractor/contractor.go b/modules/renter/contractor/contractor.go index c1780088d6..99580fced5 100644 --- a/modules/renter/contractor/contractor.go +++ b/modules/renter/contractor/contractor.go @@ -86,7 +86,7 @@ type Contractor struct { downloaders map[types.FileContractID]*hostDownloader editors map[types.FileContractID]*hostEditor sessions map[types.FileContractID]*hostSession - numFailedRenews map[types.FileContractID]uint64 + numFailedRenews map[types.FileContractID]types.BlockHeight renewing map[types.FileContractID]bool // prevent revising during renewal // pubKeysToContractID is a map of host pubkeys to the latest contract ID @@ -492,7 +492,7 @@ func contractorBlockingStartup(cs modules.ConsensusSet, w modules.Wallet, tp mod renewing: make(map[types.FileContractID]bool), renewedFrom: make(map[types.FileContractID]types.FileContractID), renewedTo: make(map[types.FileContractID]types.FileContractID), - numFailedRenews: make(map[types.FileContractID]uint64), + numFailedRenews: make(map[types.FileContractID]types.BlockHeight), workerPool: emptyWorkerPool{}, } c.staticChurnLimiter = newChurnLimiter(c)