Skip to content

Commit

Permalink
Merge pull request #232 from SiaFoundation/nate/remove-finalization
Browse files Browse the repository at this point in the history
Remove finalization
  • Loading branch information
lukechampine authored Nov 15, 2024
2 parents 0b6d8d1 + ffb339e commit a6327d7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 80 deletions.
2 changes: 0 additions & 2 deletions consensus/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
11 changes: 5 additions & 6 deletions consensus/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions consensus/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 5 additions & 17 deletions consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 1 addition & 19 deletions types/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
39 changes: 9 additions & 30 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
const (
v2ResolutionRenewal = "renewal"
v2ResolutionStorageProof = "storageProof"
v2ResolutionFinalization = "finalization"
v2ResolutionExpiration = "expiration"
)

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a6327d7

Please sign in to comment.