Skip to content

Commit

Permalink
Merge pull request #527 from SiaFoundation/nate/relax-v1-formation-re…
Browse files Browse the repository at this point in the history
…strictions

fix(rhp2): Relax hardfork contract formation restrictions
  • Loading branch information
n8maninger authored Dec 12, 2024
2 parents 0f6d95b + 1710fd6 commit b5c4a12
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 60 deletions.
10 changes: 0 additions & 10 deletions rhp/v2/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ func (sh *SessionHandler) rpcUnlock(s *session, log *zap.Logger) (contracts.Usag
// host.
func (sh *SessionHandler) rpcFormContract(s *session, log *zap.Logger) (contracts.Usage, error) {
cs := sh.chain.TipState()
// prevent forming v1 contracts after the allow height
if cs.Index.Height >= cs.Network.HardforkV2.AllowHeight {
s.t.WriteResponseErr(ErrV2Hardfork)
return contracts.Usage{}, ErrV2Hardfork
}

settings, err := sh.settings.RHP2Settings()
if err != nil {
Expand Down Expand Up @@ -263,11 +258,6 @@ func (sh *SessionHandler) rpcFormContract(s *session, log *zap.Logger) (contract
// existing contract
func (sh *SessionHandler) rpcRenewAndClearContract(s *session, log *zap.Logger) (contracts.Usage, error) {
cs := sh.chain.TipState()
// prevent renewing v1 contracts after the allow height
if cs.Index.Height >= cs.Network.HardforkV2.AllowHeight {
s.t.WriteResponseErr(ErrV2Hardfork)
return contracts.Usage{}, ErrV2Hardfork
}

settings, err := sh.settings.RHP2Settings()
if err != nil {
Expand Down
33 changes: 0 additions & 33 deletions rhp/v2/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,39 +451,6 @@ func TestRPCV2(t *testing.T) {
}
})

t.Run("form after allow height", func(t *testing.T) {
// mine until the allow height
testutil.MineAndSync(t, node, node.Wallet.Address(), int(network.HardforkV2.AllowHeight-node.Chain.Tip().Height))

transport := dialHost(t, hostKey.PublicKey(), l.Addr().String())
defer transport.Close()

settings, err := rpc2.RPCSettings(transport)
if err != nil {
t.Fatal(err)
}

// try to form a v1 contract after the allow height
fc := crhp2.PrepareContractFormation(renterKey.PublicKey(), hostKey.PublicKey(), types.Siacoins(10), types.Siacoins(20), node.Chain.Tip().Height+10, settings, node.Wallet.Address())
formationCost := crhp2.ContractFormationCost(node.Chain.TipState(), fc, settings.ContractPrice)
txn := types.Transaction{
FileContracts: []types.FileContract{fc},
}
toSign, err := node.Wallet.FundTransaction(&txn, formationCost, true)
if err != nil {
t.Fatal(err)
}
node.Wallet.SignTransaction(&txn, toSign, wallet.ExplicitCoveredFields(txn))
formationSet := append(node.Chain.UnconfirmedParents(txn), txn)

_, _, err = rpc2.RPCFormContract(transport, renterKey, formationSet)
if runtime.GOOS != "windows" && !errors.Is(err, rhp2.ErrV2Hardfork) { // windows responds with wsarecv rather than the error
t.Fatalf("expected ErrV2Hardfork, got %v", err)
} else if runtime.GOOS == "windows" && err == nil {
t.Fatal("expected windows error, got nil")
}
})

t.Run("rpc after require height", func(t *testing.T) {
// mine until the require height
testutil.MineAndSync(t, node, node.Wallet.Address(), int(network.HardforkV2.RequireHeight-node.Chain.Tip().Height))
Expand Down
5 changes: 0 additions & 5 deletions rhp/v3/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ func (sh *SessionHandler) handleRPCLatestRevision(s *rhp3.Stream, log *zap.Logge

func (sh *SessionHandler) handleRPCRenew(s *rhp3.Stream, log *zap.Logger) (contracts.Usage, error) {
cs := sh.chain.TipState()
// prevent renewing v1 contracts after the allow height
if cs.Index.Height >= cs.Network.HardforkV2.AllowHeight {
s.WriteResponseErr(ErrV2Hardfork)
return contracts.Usage{}, ErrV2Hardfork
}

s.SetDeadline(time.Now().Add(2 * time.Minute))
if !sh.settings.AcceptingContracts() {
Expand Down
12 changes: 0 additions & 12 deletions rhp/v3/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,16 +630,4 @@ func TestRPCV2(t *testing.T) {
if !errors.Is(err, rhp3.ErrAfterV2Hardfork) {
t.Fatalf("expected after v2 hardfork error, got %v", err)
}

// mine to activate the v2 hardfork
testutil.MineAndSync(t, node, node.Wallet.Address(), int(network.HardforkV2.AllowHeight-node.Chain.Tip().Height))

// try to renew the contract with an end height before the require height, but after the hardfork activation
renewHeight = origin.Revision.WindowEnd + 10
renterFunds = types.Siacoins(10)
additionalCollateral = types.Siacoins(20)
_, _, err = session.RenewContract(&origin, node.Wallet.Address(), renterKey, renterFunds, additionalCollateral, renewHeight)
if !errors.Is(err, rhp3.ErrV2Hardfork) {
t.Fatalf("expected v2 hardfork error, got %v", err)
}
}

0 comments on commit b5c4a12

Please sign in to comment.