Skip to content

Commit

Permalink
Merge pull request #666 from SiaFoundation/pj/pruning-fixes
Browse files Browse the repository at this point in the history
Pruning Fixes
  • Loading branch information
ChrisSchinnerl authored Oct 12, 2023
2 parents fb23113 + 5bec2d2 commit bc9ea4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
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

0 comments on commit bc9ea4e

Please sign in to comment.