From 5508deba0840b14c6623be8d431f36005f57a913 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Fri, 25 Oct 2024 09:18:12 -0700 Subject: [PATCH] rhp4: export ProofWindow --- rhp/v4/rhp.go | 8 +++++--- rhp/v4/validation.go | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rhp/v4/rhp.go b/rhp/v4/rhp.go index 176851e..478a911 100644 --- a/rhp/v4/rhp.go +++ b/rhp/v4/rhp.go @@ -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 @@ -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, @@ -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 diff --git a/rhp/v4/validation.go b/rhp/v4/validation.go index 41fcfcb..a36d781 100644 --- a/rhp/v4/validation.go +++ b/rhp/v4/validation.go @@ -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 } @@ -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 @@ -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