Commit 5c49dfba authored by Luke Champine's avatar Luke Champine

rename Burn -> Collateral

parent 12da2a97
......@@ -18,8 +18,8 @@ type ContractTerms struct {
StartHeight consensus.BlockHeight
WindowSize consensus.BlockHeight // how many blocks a host has to submit each proof
NumWindows uint64
ClientPayout consensus.Currency // client contribution towards payout each window
HostPayout consensus.Currency // host contribution towards payout each window
Price consensus.Currency // client contribution towards payout each window
Collateral consensus.Currency // host contribution towards payout each window
ValidProofAddress consensus.CoinAddress
MissedProofAddress consensus.CoinAddress
}
......
......@@ -43,11 +43,11 @@ func (h *Host) considerTerms(terms modules.ContractTerms) error {
h.state.RUnlock()
duration := terms.WindowSize * consensus.BlockHeight(terms.NumWindows)
requiredFund := (h.Price + h.Burn) * consensus.Currency(duration) * consensus.Currency(terms.FileSize)
switch {
// TODO: check for minheight too?
case terms.StartHeight > maxheight:
return errors.New("startBlock is too far in the future")
return errors.New("first window is too far in the future")
case terms.FileSize < h.MinFilesize || terms.FileSize > h.MaxFilesize:
return errors.New("file is of incorrect size")
......@@ -66,9 +66,12 @@ func (h *Host) considerTerms(terms modules.ContractTerms) error {
case terms.MissedProofAddress != consensus.ZeroAddress:
return errors.New("burn payout needs to go to the zero address")
case terms.HostPayout+terms.ClientPayout != requiredFund:
return errors.New("ContractFund does not match the terms of service.")
// TODO: should this be <= ?
case terms.Price != h.Price:
return errors.New("price does not match host settings")
// TODO: should this be >= ?
case terms.Collateral != h.Collateral:
return errors.New("collateral does not match host settings")
}
return nil
......@@ -88,7 +91,7 @@ func verifyContract(contract consensus.FileContract, terms modules.ContractTerms
case contract.End != terms.StartHeight+(terms.WindowSize*consensus.BlockHeight(terms.NumWindows)):
return errors.New("bad End")
case contract.Payout != terms.HostPayout+terms.ClientPayout:
case contract.Payout != terms.Price+terms.Collateral:
return errors.New("bad Payout")
case contract.ValidProofAddress != terms.ValidProofAddress:
......@@ -110,7 +113,7 @@ func verifyContract(contract consensus.FileContract, terms modules.ContractTerms
func (h *Host) acceptContract(txn consensus.Transaction) error {
contract := txn.FileContracts[0]
duration := contract.End - contract.Start
penalty := h.Burn * consensus.Currency(contract.FileSize) * consensus.Currency(duration)
penalty := h.Collateral * consensus.Currency(contract.FileSize) * consensus.Currency(duration)
id, err := h.wallet.RegisterTransaction(txn)
if err != nil {
......
......@@ -69,7 +69,7 @@ func New(state *consensus.State, wallet modules.Wallet) (h *Host, err error) {
MaxDuration: 1008, // One week.
MinWindow: 20,
Price: 1,
Burn: 1,
Collateral: 1,
CoinAddress: addr,
},
......
......@@ -34,7 +34,7 @@ type HostSettings struct {
MaxDuration consensus.BlockHeight
MinWindow consensus.BlockHeight
Price consensus.Currency
Burn consensus.Currency
Collateral consensus.Currency
CoinAddress consensus.CoinAddress
}
......
......@@ -13,14 +13,15 @@ import (
// host.Weight() determines the weight of a specific host, which is:
//
// Freeze * Burn / square(Price).
// Freeze * Collateral / square(Price).
//
// Freeze has to be linear, because any non-linear freeze will invite sybil
// attacks.
//
// For now, Burn is also linear because an increased burn means increased risk
// for the host (Freeze on the other hand has no risk). It might be better to
// make burn grow sublinearly, such as taking sqrt(Burn) or burn^(4/5).
// For now, Collateral is also linear because an increased burn means
// increased risk for the host (Freeze on the other hand has no risk). It
// might be better to make burn grow sublinearly, such as taking
// sqrt(Collateral) or burn^(4/5).
//
// We take the square of the price to heavily emphasize hosts that have a low
// price. This is also a bit simplistic however, because we're not sure what
......@@ -32,17 +33,17 @@ func entryWeight(entry modules.HostEntry) consensus.Currency {
if entry.Price == 0 {
entry.Price = 1
}
if entry.Burn == 0 {
entry.Burn = 1
if entry.Collateral == 0 {
entry.Collateral = 1
}
if entry.Freeze == 0 {
entry.Freeze = 1
}
adjustedBurn := float64(entry.Burn)
adjustedCollateral := float64(entry.Collateral)
adjustedFreeze := float64(entry.Freeze)
adjustedPrice := math.Sqrt(float64(entry.Price))
weight := adjustedFreeze * adjustedBurn / adjustedPrice
weight := adjustedFreeze * adjustedCollateral / adjustedPrice
return consensus.Currency(weight)
}
......@@ -69,7 +69,7 @@ func TestWeightedList(t *testing.T) {
firstInsertions := 64
for i := 0; i < firstInsertions; i++ {
var entry modules.HostEntry
entry.Burn = 10
entry.Collateral = 10
entry.Price = 10
entry.Freeze = 10
entry.IPAddress = network.Address(strconv.Itoa(i))
......@@ -109,7 +109,7 @@ func TestWeightedList(t *testing.T) {
secondInsertions := 64
for i := firstInsertions; i < firstInsertions+secondInsertions; i++ {
var entry modules.HostEntry
entry.Burn = 10
entry.Collateral = 10
entry.Price = 10
entry.Freeze = 10
entry.IPAddress = network.Address(strconv.Itoa(i))
......
......@@ -26,7 +26,7 @@ Available settings:
mintolerance
maxduration
price
burn`,
collateral`,
Run: wrap(hostsetcmd),
}
......@@ -75,8 +75,8 @@ func hoststatuscmd() {
fmt.Printf(`Host settings:
Storage: %v bytes (%v remaining)
Price: %v coins
Collateral: %v
Max Filesize: %v
Max Duration: %v
Burn: %v
`, config.TotalStorage, config.StorageRemaining, config.Price, config.MaxFilesize, config.MaxDuration, config.Burn)
`, config.TotalStorage, config.StorageRemaining, config.Price, config.Collateral, config.MaxFilesize, config.MaxDuration)
}
......@@ -19,7 +19,7 @@ func (d *daemon) hostConfigHandler(w http.ResponseWriter, req *http.Request) {
"minduration": &config.MinDuration,
"maxduration": &config.MaxDuration,
"price": &config.Price,
"burn": &config.Burn,
"collateral": &config.Collateral,
}
for qs := range qsVars {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment