Skip to content

Commit

Permalink
rhp4: export ProofWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 25, 2024
1 parent dae1954 commit 5508deb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions rhp/v4/rhp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
)

const (
proofWindow = 144 // 24 hours
// ProofWindow is the number of blocks a host has to submit a proof after
// the contract expires.
ProofWindow = 144 // 24 hours

// SectorSize is the size of one sector in bytes.
SectorSize = 1 << 22 // 4 MiB
Expand Down Expand Up @@ -564,7 +566,7 @@ func NewContract(p HostPrices, cp RPCFormContractParams, hostKey types.PublicKey
Filesize: 0,
FileMerkleRoot: types.Hash256{},
ProofHeight: cp.ProofHeight,
ExpirationHeight: cp.ProofHeight + proofWindow,
ExpirationHeight: cp.ProofHeight + ProofWindow,
RenterOutput: types.SiacoinOutput{
Value: cp.Allowance,
Address: cp.RenterAddress,
Expand Down Expand Up @@ -686,7 +688,7 @@ func RenewContract(fc types.V2FileContract, prices HostPrices, rp RPCRenewContra
renewal.NewContract.RevisionNumber = 0
renewal.NewContract.RenterSignature = types.Signature{}
renewal.NewContract.HostSignature = types.Signature{}
renewal.NewContract.ExpirationHeight = rp.ProofHeight + proofWindow
renewal.NewContract.ExpirationHeight = rp.ProofHeight + ProofWindow
renewal.NewContract.ProofHeight = rp.ProofHeight
// the renter output value only needs to cover the new allowance
renewal.NewContract.RenterOutput.Value = rp.Allowance
Expand Down
8 changes: 4 additions & 4 deletions rhp/v4/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func (req *RPCWriteSectorStreamingRequest) Validate(pk types.PublicKey, maxDurat
switch {
case req.Duration == 0:
return errors.New("duration must be greater than 0")
case req.Duration > maxDuration:
return fmt.Errorf("duration exceeds maximum: %d > %d", req.Duration, maxDuration)
case req.DataLength == 0:
return errors.New("sector must not be empty")
case req.DataLength%LeafSize != 0:
return errors.New("sector must be segment aligned")
case req.DataLength > SectorSize:
return errors.New("sector exceeds sector bounds")
case req.Duration > maxDuration:
return fmt.Errorf("duration exceeds maximum: %d > %d", req.Duration, maxDuration)
}
return nil
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (req *RPCFormContractRequest) Validate(pk types.PublicKey, tip types.ChainI

// validate the contract fields
hp := req.Prices
expirationHeight := req.Contract.ProofHeight + proofWindow
expirationHeight := req.Contract.ProofHeight + ProofWindow
duration := expirationHeight - hp.TipHeight
// calculate the minimum allowance required for the contract based on the
// host's locked collateral and the contract duration
Expand Down Expand Up @@ -143,7 +143,7 @@ func (req *RPCRenewContractRequest) Validate(pk types.PublicKey, tip types.Chain

// validate the contract fields
hp := req.Prices
expirationHeight := req.Renewal.ProofHeight + proofWindow
expirationHeight := req.Renewal.ProofHeight + ProofWindow
duration := expirationHeight - hp.TipHeight
// calculate the minimum allowance required for the contract based on the
// host's locked collateral and the contract duration
Expand Down

0 comments on commit 5508deb

Please sign in to comment.