Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pruning Fixes #666

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions worker/rhpv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ func (w *worker) PruneContract(ctx context.Context, hostIP string, hostKey types
if deleted < uint64(len(indices)) {
remaining = uint64(len(indices)) - deleted
}

// return sizes instead of number of roots
deleted *= rhpv2.SectorSize
remaining *= rhpv2.SectorSize
return
})
})
Expand All @@ -324,12 +328,6 @@ func (w *worker) deleteContractRoots(t *rhpv2.Transport, rev *rhpv2.ContractRevi
return 0, nil
}

// record contract spending
var totalCost types.Currency
defer func() {
w.contractSpendingRecorder.Record(rev.ID(), rev.Revision.RevisionNumber, rev.Revision.Filesize, api.ContractSpending{Deletions: totalCost})
}()

// sort in descending order so that we can use 'range'
sort.Slice(indices, func(i, j int) bool {
return indices[i] > indices[j]
Expand Down Expand Up @@ -472,9 +470,11 @@ func (w *worker) deleteContractRoots(t *rhpv2.Transport, rev *rhpv2.ContractRevi
rev.Signatures[0].Signature = renterSig.Signature[:]
rev.Signatures[1].Signature = hostSig.Signature[:]

// update total cost
totalCost = totalCost.Add(cost)
// update deleted count
deleted += uint64(len(batch))

// record spending
w.contractSpendingRecorder.Record(rev.ID(), rev.Revision.RevisionNumber, rev.Revision.Filesize, api.ContractSpending{Deletions: cost})
return nil
}(); err != nil {
return
Expand All @@ -497,12 +497,6 @@ func (w *worker) fetchContractRoots(t *rhpv2.Transport, rev *rhpv2.ContractRevis
// derive the renter key
renterKey := w.deriveRenterKey(rev.HostKey())

// record contract spending
var totalCost types.Currency
defer func() {
w.contractSpendingRecorder.Record(rev.ID(), rev.Revision.RevisionNumber, rev.Revision.Filesize, api.ContractSpending{SectorRoots: totalCost})
}()

// download the full set of SectorRoots
numsectors := rev.NumSectors()
for offset := uint64(0); offset < numsectors; {
Expand Down Expand Up @@ -564,12 +558,12 @@ func (w *worker) fetchContractRoots(t *rhpv2.Transport, rev *rhpv2.ContractRevis
return nil, ErrInvalidMerkleProof
}

// update the total cost
totalCost = totalCost.Add(cost)

// append roots
roots = append(roots, rootsResp.SectorRoots...)
offset += n

// record spending
w.contractSpendingRecorder.Record(rev.ID(), rev.Revision.RevisionNumber, rev.Revision.Filesize, api.ContractSpending{SectorRoots: cost})
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion worker/rhpv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (h *host) UploadSector(ctx context.Context, sector *[rhpv2.SectorSize]byte,

// record spending
h.contractSpendingRecorder.Record(rev.ParentID, rev.RevisionNumber, rev.Filesize, api.ContractSpending{Uploads: cost})
return root, err
return root, nil
}

// padBandwitdh pads the bandwidth to the next multiple of 1460 bytes. 1460
Expand Down