Fix actor policy codegen

This commit is contained in:
ZenGround0 2021-08-10 13:32:00 -04:00
parent 6da26dcefc
commit 234030218c
2 changed files with 59 additions and 27 deletions

View File

@ -173,18 +173,23 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (a
switch ver { switch ver {
case actors.Version0: case actors.Version0:
return miner0.MaxSealDuration[t], nil return miner0.MaxSealDuration[t], nil
case actors.Version2: case actors.Version2:
return miner2.MaxProveCommitDuration[t], nil return miner2.MaxProveCommitDuration[t], nil
case actors.Version3: case actors.Version3:
return miner3.MaxProveCommitDuration[t], nil return miner3.MaxProveCommitDuration[t], nil
case actors.Version4: case actors.Version4:
return miner4.MaxProveCommitDuration[t], nil return miner4.MaxProveCommitDuration[t], nil
case actors.Version5: case actors.Version5:
return miner5.MaxProveCommitDuration[t], nil return miner5.MaxProveCommitDuration[t], nil
default: default:
@ -231,22 +236,27 @@ func DealProviderCollateralBounds(
switch v { switch v {
case actors.Version0: case actors.Version0:
min, max := market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) min, max := market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
return min, max, nil return min, max, nil
case actors.Version2: case actors.Version2:
min, max := market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) min, max := market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
return min, max, nil return min, max, nil
case actors.Version3: case actors.Version3:
min, max := market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) min, max := market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
return min, max, nil return min, max, nil
case actors.Version4: case actors.Version4:
min, max := market4.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) min, max := market4.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
return min, max, nil return min, max, nil
case actors.Version5: case actors.Version5:
min, max := market5.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) min, max := market5.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
return min, max, nil return min, max, nil
@ -404,7 +414,7 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) {
return miner5.DeclarationsMax, nil return miner5.DeclarationsMax, nil
default: default:
panic("unsupported network version") return 0, xerrors.Errorf("unsupported network version")
} }
} }

View File

@ -4,6 +4,7 @@ import (
"sort" "sort"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/network"
@ -117,18 +118,18 @@ func SetMinVerifiedDealSize(size abi.StoragePower) {
{{end}} {{end}}
} }
func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) {
switch ver { switch ver {
{{range .versions}} {{range .versions}}
case actors.Version{{.}}: case actors.Version{{.}}:
{{if (eq . 0)}} {{if (eq . 0)}}
return miner{{.}}.MaxSealDuration[t] return miner{{.}}.MaxSealDuration[t], nil
{{else}} {{else}}
return miner{{.}}.MaxProveCommitDuration[t] return miner{{.}}.MaxProveCommitDuration[t], nil
{{end}} {{end}}
{{end}} {{end}}
default: default:
panic("unsupported actors version") return 0, xerrors.Errorf("unsupported actors version")
} }
} }
@ -150,18 +151,24 @@ func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool, size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower, rawBytePower, qaPower, baselinePower abi.StoragePower,
circulatingFil abi.TokenAmount, nwVer network.Version, circulatingFil abi.TokenAmount, nwVer network.Version,
) (min, max abi.TokenAmount) { ) (min, max abi.TokenAmount, err error) {
switch actors.VersionForNetwork(nwVer) { v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), big.Zero(), err
}
switch v {
{{range .versions}} {{range .versions}}
case actors.Version{{.}}: case actors.Version{{.}}:
{{if (eq . 0)}} {{if (eq . 0)}}
return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) min, max := market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
return min, max, nil
{{else}} {{else}}
return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) min, max := market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
return min, max, nil
{{end}} {{end}}
{{end}} {{end}}
default: default:
panic("unsupported actors version") return big.Zero(), big.Zero(), xerrors.Errorf("unsupported actors version")
} }
} }
@ -201,8 +208,11 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e
if err != nil { if err != nil {
return 0, err return 0, err
} }
maxSectors := uint64(GetAddressedSectorsMax(nv)) maxSectors, err := GetAddressedSectorsMax(nv)
return int(maxSectors / sectorsPerPart), nil if err != nil {
return 0, err
}
return int(uint64(maxSectors) / sectorsPerPart), nil
} }
func GetDefaultSectorSize() abi.SectorSize { func GetDefaultSectorSize() abi.SectorSize {
@ -236,44 +246,56 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version)
return builtin{{.latestVersion}}.SealProofPoliciesV11[proof].SectorMaxLifetime return builtin{{.latestVersion}}.SealProofPoliciesV11[proof].SectorMaxLifetime
} }
func GetAddressedSectorsMax(nwVer network.Version) int { func GetAddressedSectorsMax(nwVer network.Version) (int, error) {
switch actors.VersionForNetwork(nwVer) { v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return 0, err
}
switch v {
{{range .versions}} {{range .versions}}
case actors.Version{{.}}: case actors.Version{{.}}:
return miner{{.}}.AddressedSectorsMax return miner{{.}}.AddressedSectorsMax, nil
{{end}} {{end}}
default: default:
panic("unsupported network version") return 0, xerrors.Errorf("unsupported network version")
} }
} }
func GetDeclarationsMax(nwVer network.Version) int { func GetDeclarationsMax(nwVer network.Version) (int, error) {
switch actors.VersionForNetwork(nwVer) { v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return 0, err
}
switch v {
{{range .versions}} {{range .versions}}
case actors.Version{{.}}: case actors.Version{{.}}:
{{if (eq . 0)}} {{if (eq . 0)}}
// TODO: Should we instead panic here since the concept doesn't exist yet? // TODO: Should we instead error here since the concept doesn't exist yet?
return miner{{.}}.AddressedPartitionsMax return miner{{.}}.AddressedPartitionsMax, nil
{{else}} {{else}}
return miner{{.}}.DeclarationsMax return miner{{.}}.DeclarationsMax, nil
{{end}} {{end}}
{{end}} {{end}}
default: default:
panic("unsupported network version") return 0, xerrors.Errorf("unsupported network version")
} }
} }
func AggregateNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) abi.TokenAmount { func AggregateNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
switch actors.VersionForNetwork(nwVer) { v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}
switch v {
{{range .versions}} {{range .versions}}
case actors.Version{{.}}: case actors.Version{{.}}:
{{if (le . 4)}} {{if (le . 4)}}
return big.Zero() return big.Zero(), nil
{{else}} {{else}}
return miner{{.}}.AggregateNetworkFee(aggregateSize, baseFee) return miner{{.}}.AggregateNetworkFee(aggregateSize, baseFee), nil
{{end}} {{end}}
{{end}} {{end}}
default: default:
panic("unsupported network version") return big.Zero(), xerrors.Errorf("unsupported network version")
} }
} }