diff --git a/consensus/update.go b/consensus/update.go index 02fa1d1c..a383a817 100644 --- a/consensus/update.go +++ b/consensus/update.go @@ -554,8 +554,6 @@ func (ms *MidState) ApplyV2Transaction(txn types.V2Transaction) { ms.addV2FileContractElement(fce.ID.V2RenewalID(), r.NewContract) case *types.V2StorageProof: renter, host = fc.RenterOutput, fc.HostOutput - case *types.V2FileContractFinalization: - renter, host = fc.RenterOutput, fc.HostOutput case *types.V2FileContractExpiration: renter, host = fc.RenterOutput, fc.MissedHostOutput() } diff --git a/consensus/update_test.go b/consensus/update_test.go index 4434b404..6cba2adb 100644 --- a/consensus/update_test.go +++ b/consensus/update_test.go @@ -913,13 +913,12 @@ func TestApplyRevertBlockV2(t *testing.T) { txn.FileContractRevisions[i].Revision.HostSignature = hostPrivateKey.SignHash(cs.ContractSigHash(txn.FileContractRevisions[i].Revision)) } for i := range txn.FileContractResolutions { - switch r := txn.FileContractResolutions[i].Resolution.(type) { - case *types.V2FileContractRenewal: - r.RenterSignature = renterPrivateKey.SignHash(cs.RenewalSigHash(*r)) - r.HostSignature = hostPrivateKey.SignHash(cs.RenewalSigHash(*r)) - case *types.V2FileContractFinalization: - *r = types.V2FileContractFinalization(renterPrivateKey.SignHash(cs.ContractSigHash(txn.FileContractResolutions[i].Parent.V2FileContract))) + r, ok := txn.FileContractResolutions[i].Resolution.(*types.V2FileContractRenewal) + if !ok { + continue } + r.RenterSignature = renterPrivateKey.SignHash(cs.RenewalSigHash(*r)) + r.HostSignature = hostPrivateKey.SignHash(cs.RenewalSigHash(*r)) } } addBlock := func(b *types.Block) (au ApplyUpdate, err error) { diff --git a/consensus/validation.go b/consensus/validation.go index 140280b9..566227df 100644 --- a/consensus/validation.go +++ b/consensus/validation.go @@ -819,12 +819,6 @@ func validateV2FileContracts(ms *MidState, txn types.V2Transaction) error { } else if !fc.HostPublicKey.VerifyHash(renewalHash, renewal.HostSignature) { return fmt.Errorf("file contract renewal %v has invalid host signature", i) } - case *types.V2FileContractFinalization: - finalRevision := fcr.Parent.V2FileContract - finalRevision.RevisionNumber = types.MaxRevisionNumber - if !finalRevision.RenterPublicKey.VerifyHash(ms.base.ContractSigHash(finalRevision), types.Signature(*r)) { - return fmt.Errorf("file contract finalization %v has invalid signature", i) - } case *types.V2StorageProof: sp := *r if ms.base.childHeight() < fc.ProofHeight { diff --git a/consensus/validation_test.go b/consensus/validation_test.go index 0b72a8e3..c5f4f85e 100644 --- a/consensus/validation_test.go +++ b/consensus/validation_test.go @@ -847,13 +847,12 @@ func TestValidateV2Block(t *testing.T) { txn.FileContractRevisions[i].Revision.HostSignature = hostPrivateKey.SignHash(cs.ContractSigHash(txn.FileContractRevisions[i].Revision)) } for i := range txn.FileContractResolutions { - switch r := txn.FileContractResolutions[i].Resolution.(type) { - case *types.V2FileContractRenewal: - r.RenterSignature = renterPrivateKey.SignHash(cs.RenewalSigHash(*r)) - r.HostSignature = hostPrivateKey.SignHash(cs.RenewalSigHash(*r)) - case *types.V2FileContractFinalization: - *r = types.V2FileContractFinalization(renterPrivateKey.SignHash(cs.ContractSigHash(txn.FileContractResolutions[i].Parent.V2FileContract))) + r, ok := txn.FileContractResolutions[i].Resolution.(*types.V2FileContractRenewal) + if !ok { + continue } + r.RenterSignature = renterPrivateKey.SignHash(cs.RenewalSigHash(*r)) + r.HostSignature = hostPrivateKey.SignHash(cs.RenewalSigHash(*r)) } } @@ -1454,17 +1453,6 @@ func TestValidateV2Block(t *testing.T) { }} }, }, - { - "file contract finalization with wrong revision number", - func(b *types.Block) { - txn := &b.V2.Transactions[0] - resolution := types.V2FileContractFinalization(renterPrivateKey.SignHash(cs.ContractSigHash((testFces[0].V2FileContract)))) - txn.FileContractResolutions = []types.V2FileContractResolution{{ - Parent: testFces[0], - Resolution: &resolution, - }} - }, - }, { "file contract renewal that does not finalize old contract", func(b *types.Block) { diff --git a/types/encoding.go b/types/encoding.go index d1520bf4..60590639 100644 --- a/types/encoding.go +++ b/types/encoding.go @@ -702,11 +702,6 @@ func (ren V2FileContractRenewal) EncodeTo(e *Encoder) { ren.HostSignature.EncodeTo(e) } -// EncodeTo implements types.EncoderTo. -func (fcf V2FileContractFinalization) EncodeTo(e *Encoder) { - Signature(fcf).EncodeTo(e) -} - // EncodeTo implements types.EncoderTo. func (sp V2StorageProof) EncodeTo(e *Encoder) { sp.ProofIndex.EncodeTo(e) @@ -725,10 +720,8 @@ func (res V2FileContractResolution) EncodeTo(e *Encoder) { e.WriteUint8(0) case *V2StorageProof: e.WriteUint8(1) - case *V2FileContractFinalization: - e.WriteUint8(2) case *V2FileContractExpiration: - e.WriteUint8(3) + e.WriteUint8(2) default: panic(fmt.Sprintf("unhandled resolution type %T", r)) } @@ -847,10 +840,6 @@ func (txn V2TransactionSemantics) EncodeTo(e *Encoder) { fcr.Parent.ID.EncodeTo(e) // normalize (being careful not to modify the original) switch res := fcr.Resolution.(type) { - case *V2FileContractFinalization: - fcf := *res - nilSigs((*Signature)(&fcf)) - fcr.Resolution = &fcf case *V2FileContractRenewal: renewal := *res nilSigs( @@ -1305,11 +1294,6 @@ func (ren *V2FileContractRenewal) DecodeFrom(d *Decoder) { ren.HostSignature.DecodeFrom(d) } -// DecodeFrom implements types.DecoderFrom. -func (fcf *V2FileContractFinalization) DecodeFrom(d *Decoder) { - (*Signature)(fcf).DecodeFrom(d) -} - // DecodeFrom implements types.DecoderFrom. func (sp *V2StorageProof) DecodeFrom(d *Decoder) { sp.ProofIndex.DecodeFrom(d) @@ -1329,8 +1313,6 @@ func (res *V2FileContractResolution) DecodeFrom(d *Decoder) { case 1: res.Resolution = new(V2StorageProof) case 2: - res.Resolution = new(V2FileContractFinalization) - case 3: res.Resolution = new(V2FileContractExpiration) default: d.SetErr(fmt.Errorf("unknown resolution type %d", t)) diff --git a/types/types.go b/types/types.go index fa8c870e..981721f9 100644 --- a/types/types.go +++ b/types/types.go @@ -20,7 +20,6 @@ import ( const ( v2ResolutionRenewal = "renewal" v2ResolutionStorageProof = "storageProof" - v2ResolutionFinalization = "finalization" v2ResolutionExpiration = "expiration" ) @@ -528,15 +527,14 @@ type V2FileContractRevision struct { // 3) The host can submit a storage proof, asserting that it has faithfully // stored the contract data for the agreed-upon duration. Typically, a storage // proof is only required if the renter is unable or unwilling to sign a -// finalization or renewal. A storage proof can only be submitted after the -// contract's ProofHeight; this allows the renter (or host) to broadcast the +// renewal. A storage proof can only be submitted after the contract's +// ProofHeight; this allows the renter (or host) to broadcast the // latest contract revision prior to the proof. // -// 4) Lastly, anyone can submit a contract expiration. Typically, an expiration -// is only required if the host is unable or unwilling to sign a finalization or -// renewal. An expiration can only be submitted after the contract's -// ExpirationHeight; this gives the host a reasonable window of time after the -// ProofHeight in which to submit a storage proof. +// 4) Lastly, anyone can submit a contract expiration. An expiration can only +// be submitted after the contract's ExpirationHeight; this gives the host a +// reasonable window of time after the ProofHeight in which to submit a storage +// proof. // // Once a contract has been resolved, it cannot be altered or resolved again. // When a contract is resolved, its RenterOutput and HostOutput are created @@ -557,24 +555,9 @@ type V2FileContractResolutionType interface { isV2FileContractResolution() } -func (*V2FileContractFinalization) isV2FileContractResolution() {} -func (*V2FileContractRenewal) isV2FileContractResolution() {} -func (*V2StorageProof) isV2FileContractResolution() {} -func (*V2FileContractExpiration) isV2FileContractResolution() {} - -// A V2FileContractFinalization finalizes a contract, preventing further -// revisions and immediately creating its valid outputs. -type V2FileContractFinalization Signature - -// MarshalText implements encoding.TextMarshaler. -func (fcf V2FileContractFinalization) MarshalText() ([]byte, error) { - return []byte(hex.EncodeToString(fcf[:])), nil -} - -// UnmarshalText implements encoding.TextUnmarshaler. -func (fcf *V2FileContractFinalization) UnmarshalText(data []byte) error { - return unmarshalHex(fcf[:], data) -} +func (*V2FileContractRenewal) isV2FileContractResolution() {} +func (*V2StorageProof) isV2FileContractResolution() {} +func (*V2FileContractExpiration) isV2FileContractResolution() {} // A V2FileContractRenewal renews a file contract. type V2FileContractRenewal struct { @@ -1207,8 +1190,6 @@ func (res V2FileContractResolution) MarshalJSON() ([]byte, error) { typ = v2ResolutionRenewal case *V2StorageProof: typ = v2ResolutionStorageProof - case *V2FileContractFinalization: - typ = v2ResolutionFinalization case *V2FileContractExpiration: typ = v2ResolutionExpiration default: @@ -1236,8 +1217,6 @@ func (res *V2FileContractResolution) UnmarshalJSON(b []byte) error { res.Resolution = new(V2FileContractRenewal) case v2ResolutionStorageProof: res.Resolution = new(V2StorageProof) - case v2ResolutionFinalization: - res.Resolution = new(V2FileContractFinalization) case v2ResolutionExpiration: res.Resolution = new(V2FileContractExpiration) default: