Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions consensus/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ func TestApplyRevertBlockV2(t *testing.T) {
v1FC.Filesize = 65
v1FC.FileMerkleRoot = blake2b.SumPair((State{}).StorageProofLeafHash([]byte{1}), (State{}).StorageProofLeafHash([]byte{2}))
v2FC := types.V2FileContract{
Capacity: v1FC.Filesize,
Filesize: v1FC.Filesize,
FileMerkleRoot: v1FC.FileMerkleRoot,
ProofHeight: 20,
Expand Down
6 changes: 6 additions & 0 deletions consensus/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ func validateV2FileContracts(ms *MidState, txn types.V2Transaction) error {

validateContract := func(fc types.V2FileContract, renewal bool) error {
switch {
case fc.Filesize > fc.Capacity:
return fmt.Errorf("has filesize (%v) exceeding capacity (%v)", fc.Filesize, fc.Capacity)
case fc.ProofHeight < ms.base.childHeight():
return fmt.Errorf("has proof height (%v) that has already passed", fc.ProofHeight)
case fc.ExpirationHeight <= fc.ProofHeight:
Expand All @@ -747,6 +749,10 @@ func validateV2FileContracts(ms *MidState, txn types.V2Transaction) error {
curOutputSum := cur.RenterOutput.Value.Add(cur.HostOutput.Value)
revOutputSum := rev.RenterOutput.Value.Add(rev.HostOutput.Value)
switch {
case rev.Capacity < cur.Capacity:
return fmt.Errorf("decreases capacity")
case rev.Filesize > rev.Capacity:
return fmt.Errorf("has filesize (%v) exceeding capacity (%v)", rev.Filesize, rev.Capacity)
case cur.ProofHeight < ms.base.childHeight():
return fmt.Errorf("revises contract after its proof window has opened")
case rev.RevisionNumber <= cur.RevisionNumber:
Expand Down
1 change: 1 addition & 0 deletions consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ func TestValidateV2Block(t *testing.T) {
v1GiftFC.Filesize = 65
v1GiftFC.FileMerkleRoot = blake2b.SumPair((State{}).StorageProofLeafHash([]byte{1}), (State{}).StorageProofLeafHash([]byte{2}))
v2GiftFC := types.V2FileContract{
Capacity: v1GiftFC.Filesize,
Filesize: v1GiftFC.Filesize,
FileMerkleRoot: v1GiftFC.FileMerkleRoot,
ProofHeight: 20,
Expand Down
2 changes: 2 additions & 0 deletions types/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ func (sfe SiafundElement) EncodeTo(e *Encoder) {

// EncodeTo implements types.EncoderTo.
func (fc V2FileContract) EncodeTo(e *Encoder) {
e.WriteUint64(fc.Capacity)
e.WriteUint64(fc.Filesize)
fc.FileMerkleRoot.EncodeTo(e)
e.WriteUint64(fc.ProofHeight)
Expand Down Expand Up @@ -1246,6 +1247,7 @@ func (sfe *SiafundElement) DecodeFrom(d *Decoder) {

// DecodeFrom implements types.DecoderFrom.
func (fc *V2FileContract) DecodeFrom(d *Decoder) {
fc.Capacity = d.ReadUint64()
fc.Filesize = d.ReadUint64()
fc.FileMerkleRoot.DecodeFrom(d)
fc.ProofHeight = d.ReadUint64()
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func (txn *Transaction) TotalFees() Currency {
// or "missed" depending on whether a valid StorageProof is submitted for the
// contract.
type V2FileContract struct {
Capacity uint64 `json:"capacity"`
Filesize uint64 `json:"filesize"`
FileMerkleRoot Hash256 `json:"fileMerkleRoot"`
ProofHeight uint64 `json:"proofHeight"`
Expand Down