github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/renter/contractor/update.go (about)

     1  package contractor
     2  
     3  import (
     4  	"github.com/NebulousLabs/Sia/modules"
     5  	"github.com/NebulousLabs/Sia/types"
     6  )
     7  
     8  // ProcessConsensusChange will be called by the consensus set every time there
     9  // is a change in the blockchain. Updates will always be called in order.
    10  func (c *Contractor) ProcessConsensusChange(cc modules.ConsensusChange) {
    11  	c.mu.Lock()
    12  	defer c.mu.Unlock()
    13  
    14  	for _, block := range cc.RevertedBlocks {
    15  		if block.ID() != types.GenesisID {
    16  			c.blockHeight--
    17  		}
    18  	}
    19  	for _, block := range cc.AppliedBlocks {
    20  		if block.ID() != types.GenesisID {
    21  			c.blockHeight++
    22  		}
    23  	}
    24  
    25  	// delete expired contracts
    26  	var expired []types.FileContractID
    27  	for id, contract := range c.contracts {
    28  		// TODO: offset this by some sort of confirmation height?
    29  		if c.blockHeight > contract.LastRevision.NewWindowStart {
    30  			expired = append(expired, id)
    31  		}
    32  	}
    33  	for _, id := range expired {
    34  		delete(c.contracts, id)
    35  		c.log.Debugln("INFO: deleted expired contract", id)
    36  	}
    37  
    38  	// renew contracts
    39  	// TODO: re-enable this functionality
    40  	// if c.blockHeight+c.allowance.RenewWindow >= c.renewHeight {
    41  	// 	c.renewHeight += c.allowance.Period
    42  	// 	go c.threadedRenewContracts(c.allowance, c.renewHeight)
    43  	// 	// reset the spentPeriod metric
    44  	// 	c.spentPeriod = types.ZeroCurrency
    45  	// }
    46  
    47  	c.lastChange = cc.ID
    48  	err := c.save()
    49  	if err != nil {
    50  		c.log.Println(err)
    51  	}
    52  }