Skip to content

Commit

Permalink
WIP:feat: limit PoSted partitions to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 10, 2023
1 parent d09d549 commit 650eee3
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 11 deletions.
75 changes: 74 additions & 1 deletion chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,13 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e
if err != nil {
return 0, err
}
return int(uint64(maxSectors) / sectorsPerPart), nil

maxPartitions, err := getPoStedPartitionsMax(nv)
if err != nil {
return 0, err
}

return min(maxPartitions, int(uint64(maxSectors)/sectorsPerPart)), nil
}

func GetDefaultAggregationProof() abi.RegisteredAggregationProof {
Expand Down Expand Up @@ -685,6 +691,66 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
}
}

func getPoStedPartitionsMax(nwVer network.Version) (int, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return 0, err
}
switch v {

case actorstypes.Version0:

return miner0.AddressedPartitionsMax, nil

case actorstypes.Version2:

return miner2.AddressedPartitionsMax, nil

case actorstypes.Version3:

return miner3.AddressedPartitionsMax, nil

case actorstypes.Version4:

return miner4.AddressedPartitionsMax, nil

case actorstypes.Version5:

return miner5.AddressedPartitionsMax, nil

case actorstypes.Version6:

return miner6.AddressedPartitionsMax, nil

case actorstypes.Version7:

return miner7.AddressedPartitionsMax, nil

case actorstypes.Version8:

return miner8.AddressedPartitionsMax, nil

case actorstypes.Version9:

return miner9.AddressedPartitionsMax, nil

case actorstypes.Version10:

return miner10.AddressedPartitionsMax, nil

case actorstypes.Version11:

return miner11.AddressedPartitionsMax, nil

case actorstypes.Version12:

return miner12.PoStedPartitionsMax, nil

default:
return 0, xerrors.Errorf("unsupported network version")
}
}

func GetDeclarationsMax(nwVer network.Version) (int, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
Expand Down Expand Up @@ -865,3 +931,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base
return big.Zero(), xerrors.Errorf("unsupported network version")
}
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
36 changes: 34 additions & 2 deletions chain/actors/policy/policy.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,21 @@ func GetMinSectorExpiration() abi.ChainEpoch {
}

func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) {
sectorsPerPart, err := builtin{{.latestVersion}}.PoStProofWindowPoStPartitionSectors(p)
sectorsPerPart, err := builtin12.PoStProofWindowPoStPartitionSectors(p)
if err != nil {
return 0, err
}
maxSectors, err := GetAddressedSectorsMax(nv)
if err != nil {
return 0, err
}
return int(uint64(maxSectors) / sectorsPerPart), nil

maxPartitions, err := getPoStedPartitionsMax(nv)
if err != nil {
return 0, err
}

return min(maxPartitions, int(uint64(maxSectors) / sectorsPerPart)), nil
}

func GetDefaultAggregationProof() abi.RegisteredAggregationProof {
Expand Down Expand Up @@ -282,6 +288,25 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
}
}

func getPoStedPartitionsMax(nwVer network.Version) (int, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return 0, err
}
switch v {
{{range .versions}}
case actorstypes.Version{{.}}:
{{if (le . 11)}}
return miner{{.}}.AddressedPartitionsMax, nil
{{else}}
return miner{{.}}.PoStedPartitionsMax, nil
{{end}}
{{end}}
default:
return 0, xerrors.Errorf("unsupported network version")
}
}

func GetDeclarationsMax(nwVer network.Version) (int, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
Expand Down Expand Up @@ -341,3 +366,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base
return big.Zero(), xerrors.Errorf("unsupported network version")
}
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,5 @@ require (
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi

replace github.com/filecoin-project/test-vectors => ./extern/test-vectors

replace github.com/filecoin-project/go-state-types => ../go-state-types
18 changes: 10 additions & 8 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,11 @@ func (a *StateAPI) stateComputeDataCIDv1(ctx context.Context, maddr address.Addr
return cid.Undef, xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
}
ccmt := &types.Message{
To: market.Address,
From: maddr,
Value: types.NewInt(0),
Method: market.Methods.ComputeDataCommitment,
To: market.Address,
From: maddr,
Value: types.NewInt(0),
// Hard coded, because the method has since been deprecated
Method: 8,
Params: ccparams,
}
r, err := a.StateCall(ctx, ccmt, tsk)
Expand Down Expand Up @@ -971,10 +972,11 @@ func (a *StateAPI) stateComputeDataCIDv2(ctx context.Context, maddr address.Addr
return cid.Undef, xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
}
ccmt := &types.Message{
To: market.Address,
From: maddr,
Value: types.NewInt(0),
Method: market.Methods.ComputeDataCommitment,
To: market.Address,
From: maddr,
Value: types.NewInt(0),
// Hard coded, because the method has since been deprecated
Method: 8,
Params: ccparams,
}
r, err := a.StateCall(ctx, ccmt, tsk)
Expand Down

0 comments on commit 650eee3

Please sign in to comment.