Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHP4 #200

Merged
merged 74 commits into from
Oct 28, 2024
Merged

RHP4 #200

Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4b8b5fb
rhp/v4: Add package
lukechampine Jan 30, 2024
4aff767
rhp/v4: Split RPCs into distinct types
lukechampine Feb 1, 2024
f87b97b
rhp/v4: Further tweaks
lukechampine Feb 1, 2024
84b8197
rhp/v4: Remove RPC wrapping types
lukechampine Feb 1, 2024
c50e95e
rhp/v4: Split WriteRequest apart again
lukechampine Feb 1, 2024
5345902
rhp/v4: Remove Transport and Stream
lukechampine Feb 1, 2024
89bd171
rhp/v4: Export Request.ID
lukechampine Feb 1, 2024
507e3a3
rhp/v4: Add AccountIDs
lukechampine Feb 2, 2024
2572aad
rhp/v4: Send SatisfiedPolicies
lukechampine Feb 2, 2024
1b40f96
rhp/v4: Add Proof to RPCSectorRootsResponse
lukechampine Feb 2, 2024
f23104c
rhp/v4: Make Account a PublicKey
lukechampine Feb 6, 2024
c043522
types: Remove V2FileContract.TotalCollateral
lukechampine Feb 7, 2024
0cf54ec
types: Rename MissedHostValue -> HostCollateral
lukechampine Feb 8, 2024
8ca5519
switch net.Conn with reader and writer
n8maninger Feb 8, 2024
0f48aed
rhp/v4: Add various RPC helpers
lukechampine Feb 8, 2024
e1a00b7
rhp/v4: add json tags
n8maninger Feb 28, 2024
981f67e
rhp4: implement initial rhp4 spec
n8maninger Sep 13, 2024
e41015d
types: remove debug policy test
n8maninger Sep 13, 2024
024e87b
rhp4: remove HostSettings.Sign()
n8maninger Sep 13, 2024
5a1fb00
rhp: remove update todo
n8maninger Sep 13, 2024
6f671cd
rhp4: minimize form and renew contract RPC
n8maninger Sep 13, 2024
a9e3f56
rhp4: fix lint
n8maninger Sep 13, 2024
057286a
rhp4: add common request validation methods
n8maninger Sep 17, 2024
de41d81
rhp/v4: add read sector streaming response
n8maninger Sep 17, 2024
41a6639
rhp/v4: fix form and renew contract validation
n8maninger Sep 17, 2024
801d360
rhp4: increment revision number when paying with contract
n8maninger Sep 26, 2024
2e1de82
rhpv4: add verify sector rpc
n8maninger Sep 27, 2024
a84f936
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Sep 27, 2024
1faa556
rhp4: increase request max len
n8maninger Sep 27, 2024
f4d384d
rhp4: return RPC error when validating prices
n8maninger Sep 27, 2024
5f92bcf
rhp: always call PayWithContract for modify sectors RPC
n8maninger Sep 27, 2024
fbb3e17
rhp4: add streaming validation
n8maninger Sep 28, 2024
311e17d
rhpv4: stream RPCWrite
n8maninger Sep 28, 2024
0e77790
rhp4: validate prices in validate functions
n8maninger Sep 28, 2024
4182368
rhp4: add append sectors rpc
n8maninger Oct 2, 2024
425f957
consensus: remove need for setup transactions from resolutions
n8maninger Oct 3, 2024
3e8b91d
core: add regression test
n8maninger Oct 7, 2024
aab39a1
Merge pull request #209 from SiaFoundation/nate/remove-resolution-txn…
n8maninger Oct 7, 2024
ea8efbf
rhp4: add rpc refresh objects and helpers
n8maninger Oct 7, 2024
5c6335b
Update rhp/v4/validation.go
n8maninger Oct 8, 2024
934e48c
rhp4: clearer allowance validation errors
n8maninger Oct 8, 2024
3a44c07
rhp4: address comments
n8maninger Oct 8, 2024
77750c2
Merge pull request #212 from SiaFoundation/nate/rhp4-rpc-refresh
n8maninger Oct 8, 2024
79a9c28
rhp4: remove fun
n8maninger Oct 9, 2024
50c4202
rhp4: update ModifyAction comments
n8maninger Oct 9, 2024
1c83fe2
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Oct 9, 2024
c4d9719
rhp/v4: Implement Merkle proofs
lukechampine Oct 10, 2024
e48286d
consensus: Reduce test noise
lukechampine Oct 10, 2024
efc26ef
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Oct 21, 2024
f72797b
rhp4: implement rpc changes
n8maninger Oct 21, 2024
cd694ed
rhp4: update docstring
n8maninger Oct 21, 2024
7cabe01
rhp4: fix lint
n8maninger Oct 21, 2024
bed2bdc
types,consensus: Add Capacity field to V2FileContract
lukechampine Oct 21, 2024
f0d4bda
rhp4: use capacity field
n8maninger Oct 21, 2024
fd212fd
rhp4: validate sector indices
n8maninger Oct 21, 2024
dfdf69e
rhp4: validate duplicate indices
n8maninger Oct 21, 2024
4715717
Merge remote-tracking branch 'origin/master' into nate/rhp4-rpc-changes
n8maninger Oct 21, 2024
8ee63c4
rhp4: return usage
n8maninger Oct 21, 2024
094716d
rhp4: remove account funding cost
n8maninger Oct 21, 2024
54b5123
rhp4: add usage to revise methods
n8maninger Oct 21, 2024
db1d712
rhp4: add usage to renew and refresh
n8maninger Oct 21, 2024
0639228
rhp4: add usage to new contract
n8maninger Oct 21, 2024
fe2567f
rhp4: fix docstring
n8maninger Oct 21, 2024
5672e6c
Update rhp/v4/validation.go
n8maninger Oct 22, 2024
2652ab2
rhp4: RPC remove -> RPC free
n8maninger Oct 22, 2024
6769c7c
Merge pull request #219 from SiaFoundation/nate/rhp4-rpc-changes
n8maninger Oct 23, 2024
9018cb0
rhp/v4: Fix Merkle proofs
lukechampine Oct 24, 2024
43d1f1d
consensus: Add BlockInterval and MaturityDelay network parameters
lukechampine Oct 21, 2024
1d4b0c2
Merge remote-tracking branch 'origin/master' into nate/rhp4
n8maninger Oct 24, 2024
760b1e6
rhp4: increase max size of transaction set responses
n8maninger Oct 24, 2024
f6a828f
rhp4: remove debugging
n8maninger Oct 24, 2024
dae1954
rhp4: remove debug log
n8maninger Oct 24, 2024
5508deb
rhp4: export ProofWindow
n8maninger Oct 25, 2024
7fcde66
consensus: add more renewal tests
n8maninger Oct 25, 2024
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
12 changes: 2 additions & 10 deletions consensus/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,6 @@ func validateV2Siafunds(ms *MidState, txn types.V2Transaction) error {
}

func validateV2FileContracts(ms *MidState, txn types.V2Transaction) error {
// Contract resolutions are height-sensitive, and thus can be invalidated by
// shallow reorgs; to minimize disruption, we require that transactions
// containing a resolution do not create new outputs. Creating, revising or
// resolving contracts *is* permitted, as these effects are generally not
// "built upon" as quickly as outputs, and therefore cause less disruption.
if len(txn.FileContractResolutions) > 0 &&
(len(txn.SiacoinOutputs) > 0 || len(txn.SiafundOutputs) > 0) {
return errors.New("transaction both resolves a file contract and creates new outputs")
}

revised := make(map[types.Hash256]int)
resolved := make(map[types.Hash256]int)
validateParent := func(fce types.V2FileContractElement) error {
Expand Down Expand Up @@ -759,6 +749,8 @@ func validateV2FileContracts(ms *MidState, txn types.V2Transaction) error {
return fmt.Errorf("does not increase revision number (%v -> %v)", cur.RevisionNumber, rev.RevisionNumber)
case !revOutputSum.Equals(curOutputSum):
return fmt.Errorf("modifies output sum (%d H -> %d H)", curOutputSum, revOutputSum)
case rev.MissedHostValue.Cmp(cur.MissedHostValue) > 0:
return fmt.Errorf("has missed host value (%d H) exceeding old value (%d H)", rev.MissedHostValue, cur.MissedHostValue)
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
case rev.TotalCollateral != cur.TotalCollateral:
return errors.New("modifies total collateral")
case rev.ProofHeight < ms.base.childHeight():
Expand Down
108 changes: 106 additions & 2 deletions consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,6 @@ func TestValidateBlock(t *testing.T) {

if err := ValidateBlock(cs, corruptBlock, db.supplementTipBlock(corruptBlock)); err == nil {
t.Fatalf("accepted block with %v", test.desc)
} else {
t.Log(test.desc, err)
}
}
}
Expand Down Expand Up @@ -1813,3 +1811,109 @@ func TestV2RevisionApply(t *testing.T) {
applyContractChanges(au)
checkRevision(t, 100)
}

func TestV2ResolutionRollover(t *testing.T) {
n, genesisBlock := testnet()

n.HardforkOak.Height = 0
n.HardforkTax.Height = 0
n.HardforkFoundation.Height = 0
n.InitialTarget = types.BlockID{0xFF}
n.HardforkV2.AllowHeight = 0
n.HardforkV2.RequireHeight = 0

pk := types.GeneratePrivateKey()
addr := types.AnyoneCanSpend().Address()
fc := types.V2FileContract{
ProofHeight: 100,
ExpirationHeight: 150,
RenterPublicKey: pk.PublicKey(),
HostPublicKey: pk.PublicKey(),
HostOutput: types.SiacoinOutput{
Address: addr, Value: types.Siacoins(10),
},
RenterOutput: types.SiacoinOutput{
Address: addr, Value: types.ZeroCurrency,
},
}
cs := n.GenesisState()
sigHash := cs.ContractSigHash(fc)
fc.HostSignature = pk.SignHash(sigHash)
fc.RenterSignature = pk.SignHash(sigHash)
contractCost := cs.V2FileContractTax(fc).Add(fc.HostOutput.Value)

genesisTxn := types.V2Transaction{
SiacoinOutputs: []types.SiacoinOutput{
{Address: addr, Value: contractCost},
},
FileContracts: []types.V2FileContract{fc},
}
genesisBlock.V2 = &types.V2BlockData{
Transactions: []types.V2Transaction{genesisTxn},
}
contractID := genesisTxn.V2FileContractID(genesisTxn.ID(), 0)
fces := make(map[types.Hash256]types.V2FileContractElement)
applyContractChanges := func(au ApplyUpdate) {
au.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
switch {
case res != nil:
delete(fces, fce.ID)
case rev != nil:
fces[fce.ID] = *rev
default:
fces[fce.ID] = fce
}
})

// update proofs
for key, fce := range fces {
au.UpdateElementProof(&fce.StateElement)
fces[key] = fce
}
}

cs, au := ApplyBlock(cs, genesisBlock, V1BlockSupplement{}, time.Time{})
applyContractChanges(au)

finalRevision := fc
finalRevision.RevisionNumber = types.MaxRevisionNumber
finalRevision.RenterSignature = types.Signature{}
finalRevision.HostSignature = types.Signature{}

renewal := types.V2FileContractRenewal{
FinalRevision: finalRevision,
NewContract: types.V2FileContract{
ProofHeight: 100,
ExpirationHeight: 150,
RenterPublicKey: pk.PublicKey(),
HostPublicKey: pk.PublicKey(),
HostOutput: types.SiacoinOutput{
Address: addr, Value: types.Siacoins(1),
},
RenterOutput: types.SiacoinOutput{
Address: addr, Value: types.ZeroCurrency,
},
},
HostRollover: types.Siacoins(10),
}
newContractCost := cs.V2FileContractTax(renewal.NewContract)
escapeAmount := renewal.HostRollover.Sub(renewal.NewContract.HostOutput.Value).Sub(newContractCost)
renewTxn := types.V2Transaction{
FileContractResolutions: []types.V2FileContractResolution{
{
Parent: fces[types.Hash256(contractID)],
Resolution: &renewal,
},
},
SiacoinOutputs: []types.SiacoinOutput{
{Value: escapeAmount, Address: types.VoidAddress},
},
}

ms := NewMidState(cs)
if err := ValidateV2Transaction(ms, renewTxn); err == nil {
t.Fatalf("expected error")
} else if !strings.Contains(err.Error(), "exceeding new contract cost") {
n8maninger marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal(err)
}
}
Loading