<commit_before>package contractor

import (
	"fmt"
	"path/filepath"

	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/persist"
	"github.com/NebulousLabs/Sia/types"
)

// contractorPersist defines what Contractor data persists across sessions.
type contractorPersist struct {
	Allowance       modules.Allowance                 `json:"allowance"`
	BlockHeight     types.BlockHeight                 `json:"blockheight"`
	CachedRevisions map[string]cachedRevision         `json:"cachedrevisions"`
	Contracts       map[string]modules.RenterContract `json:"contracts"`
	CurrentPeriod   types.BlockHeight                 `json:"currentperiod"`
	LastChange      modules.ConsensusChangeID         `json:"lastchange"`
	OldContracts    []modules.RenterContract          `json:"oldcontracts"`
	RenewedIDs      map[string]string                 `json:"renewedids"`
}

// persistData returns the data in the Contractor that will be saved to disk.
func (c *Contractor) persistData() contractorPersist {
	data := contractorPersist{
		Allowance:       c.allowance,
		BlockHeight:     c.blockHeight,
		CachedRevisions: make(map[string]cachedRevision),
		Contracts:       make(map[string]modules.RenterContract),
		CurrentPeriod:   c.currentPeriod,
		LastChange:      c.lastChange,
		RenewedIDs:      make(map[string]string),
	}
	for _, rev := range c.cachedRevisions {
		data.CachedRevisions[rev.Revision.ParentID.String()] = rev
	}
	for _, contract := range c.contracts {
		data.Contracts[contract.ID.String()] = contract
	}
	for _, contract := range c.oldContracts {
		data.OldContracts = append(data.OldContracts, contract)
	}
	for oldID, newID := range c.renewedIDs {
		data.RenewedIDs[oldID.String()] = newID.String()
	}
	return data
}

// load loads the Contractor persistence data from disk.
func (c *Contractor) load() error {
	var data contractorPersist
	err := c.persist.load(&data)
	if err != nil {
		return err
	}
	c.allowance = data.Allowance
	c.blockHeight = data.BlockHeight<commit_msg>don't save roots of old contracts<commit_after>package contractor

import (
	"fmt"
	"path/filepath"

	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/persist"
	"github.com/NebulousLabs/Sia/types"
)

// contractorPersist defines what Contractor data persists across sessions.
type contractorPersist struct {
	Allowance       modules.Allowance                 `json:"allowance"`
	BlockHeight     types.BlockHeight                 `json:"blockheight"`
	CachedRevisions map[string]cachedRevision         `json:"cachedrevisions"`
	Contracts       map[string]modules.RenterContract `json:"contracts"`
	CurrentPeriod   types.BlockHeight                 `json:"currentperiod"`
	LastChange      modules.ConsensusChangeID         `json:"lastchange"`
	OldContracts    []modules.RenterContract          `json:"oldcontracts"`
	RenewedIDs      map[string]string                 `json:"renewedids"`
}

// persistData returns the data in the Contractor that will be saved to disk.
func (c *Contractor) persistData() contractorPersist {
	data := contractorPersist{
		Allowance:       c.allowance,
		BlockHeight:     c.blockHeight,
		CachedRevisions: make(map[string]cachedRevision),
		Contracts:       make(map[string]modules.RenterContract),
		CurrentPeriod:   c.currentPeriod,
		LastChange:      c.lastChange,
		RenewedIDs:      make(map[string]string),
	}
	for _, rev := range c.cachedRevisions {
		data.CachedRevisions[rev.Revision.ParentID.String()] = rev
	}
	for _, contract := range c.contracts {
		data.Contracts[contract.ID.String()] = contract
	}
	for _, contract := range c.oldContracts {
		contract.MerkleRoots = []crypto.Hash{} // prevent roots from being saved to disk twice
		data.OldContracts = append(data.OldContracts, contract)
	}
	for oldID, newID := range c.renewedIDs {
		data.RenewedIDs[oldID.String()] = newID.String()
	}
	return data
}

// load loads the Contractor persistence data from disk.
func (c *Contractor) load() error {
	var data contractorPersist
	err := c.persist.load(&data)
	if err != nil {
		return err
	}
	c.allowance = data.Allowance
	c.blockHeight = data.BlockHeight
{'fraction_non_alphanumeric': 0.10785015509424958, 'fraction_numerical': 0.0, 'mean_word_length': 3.6785714285714284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6798224', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1310, 'n_words': 280}