github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/sector.go (about)

     1  package builtin
     2  
     3  import (
     4  	stabi "github.com/filecoin-project/go-state-types/abi"
     5  	"github.com/filecoin-project/go-state-types/network"
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // Policy values associated with a seal proof type.
    10  type SealProofPolicy struct {
    11  	SectorMaxLifetime stabi.ChainEpoch
    12  }
    13  
    14  // For V1 Stacked DRG sectors, the max is 540 days since Network Version 11
    15  // 	according to https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0014.md
    16  const EpochsIn540Days = stabi.ChainEpoch(540 * EpochsInDay)
    17  
    18  // For V1_1 Stacked DRG sectors, the max is 5 years
    19  const EpochsInFiveYears = stabi.ChainEpoch(5 * EpochsInYear)
    20  
    21  var SealProofPoliciesV0 = map[stabi.RegisteredSealProof]*SealProofPolicy{
    22  	stabi.RegisteredSealProof_StackedDrg2KiBV1: {
    23  		SectorMaxLifetime: EpochsInFiveYears,
    24  	},
    25  	stabi.RegisteredSealProof_StackedDrg8MiBV1: {
    26  		SectorMaxLifetime: EpochsInFiveYears,
    27  	},
    28  	stabi.RegisteredSealProof_StackedDrg512MiBV1: {
    29  		SectorMaxLifetime: EpochsInFiveYears,
    30  	},
    31  	stabi.RegisteredSealProof_StackedDrg32GiBV1: {
    32  		SectorMaxLifetime: EpochsInFiveYears,
    33  	},
    34  	stabi.RegisteredSealProof_StackedDrg64GiBV1: {
    35  		SectorMaxLifetime: EpochsInFiveYears,
    36  	},
    37  
    38  	stabi.RegisteredSealProof_StackedDrg2KiBV1_1: {
    39  		SectorMaxLifetime: EpochsInFiveYears,
    40  	},
    41  	stabi.RegisteredSealProof_StackedDrg8MiBV1_1: {
    42  		SectorMaxLifetime: EpochsInFiveYears,
    43  	},
    44  	stabi.RegisteredSealProof_StackedDrg512MiBV1_1: {
    45  		SectorMaxLifetime: EpochsInFiveYears,
    46  	},
    47  	stabi.RegisteredSealProof_StackedDrg32GiBV1_1: {
    48  		SectorMaxLifetime: EpochsInFiveYears,
    49  	},
    50  	stabi.RegisteredSealProof_StackedDrg64GiBV1_1: {
    51  		SectorMaxLifetime: EpochsInFiveYears,
    52  	},
    53  }
    54  
    55  // 540-day maximum life time setting for V1 since network version 11
    56  var SealProofPoliciesV11 = map[stabi.RegisteredSealProof]*SealProofPolicy{
    57  	stabi.RegisteredSealProof_StackedDrg2KiBV1: {
    58  		SectorMaxLifetime: EpochsIn540Days,
    59  	},
    60  	stabi.RegisteredSealProof_StackedDrg8MiBV1: {
    61  		SectorMaxLifetime: EpochsIn540Days,
    62  	},
    63  	stabi.RegisteredSealProof_StackedDrg512MiBV1: {
    64  		SectorMaxLifetime: EpochsIn540Days,
    65  	},
    66  	stabi.RegisteredSealProof_StackedDrg32GiBV1: {
    67  		SectorMaxLifetime: EpochsIn540Days,
    68  	},
    69  	stabi.RegisteredSealProof_StackedDrg64GiBV1: {
    70  		SectorMaxLifetime: EpochsIn540Days,
    71  	},
    72  
    73  	stabi.RegisteredSealProof_StackedDrg2KiBV1_1: {
    74  		SectorMaxLifetime: EpochsInFiveYears,
    75  	},
    76  	stabi.RegisteredSealProof_StackedDrg8MiBV1_1: {
    77  		SectorMaxLifetime: EpochsInFiveYears,
    78  	},
    79  	stabi.RegisteredSealProof_StackedDrg512MiBV1_1: {
    80  		SectorMaxLifetime: EpochsInFiveYears,
    81  	},
    82  	stabi.RegisteredSealProof_StackedDrg32GiBV1_1: {
    83  		SectorMaxLifetime: EpochsInFiveYears,
    84  	},
    85  	stabi.RegisteredSealProof_StackedDrg64GiBV1_1: {
    86  		SectorMaxLifetime: EpochsInFiveYears,
    87  	},
    88  }
    89  
    90  // Returns the partition size, in sectors, associated with a seal proof type.
    91  // The partition size is the number of sectors proved in a single PoSt proof.
    92  func SealProofWindowPoStPartitionSectors(p stabi.RegisteredSealProof) (uint64, error) {
    93  	wPoStProofType, err := p.RegisteredWindowPoStProof()
    94  	if err != nil {
    95  		return 0, err
    96  	}
    97  	return PoStProofWindowPoStPartitionSectors(wPoStProofType)
    98  }
    99  
   100  // SectorMaximumLifetime is the maximum duration a sector sealed with this proof may exist between activation and expiration
   101  func SealProofSectorMaximumLifetime(p stabi.RegisteredSealProof, nv network.Version) (stabi.ChainEpoch, error) {
   102  	var info *SealProofPolicy
   103  	var ok bool
   104  
   105  	if nv < network.Version11 {
   106  		info, ok = SealProofPoliciesV0[p]
   107  	} else {
   108  		info, ok = SealProofPoliciesV11[p]
   109  	}
   110  
   111  	if !ok {
   112  		return 0, errors.Errorf("unsupported proof type: %v", p)
   113  	}
   114  	return info.SectorMaxLifetime, nil
   115  }
   116  
   117  // The minimum power of an individual miner to meet the threshold for leader election (in bytes).
   118  // Motivation:
   119  // - Limits sybil generation
   120  // - Improves consensus fault detection
   121  // - Guarantees a minimum fee for consensus faults
   122  // - Ensures that a specific soundness for the power table
   123  // Note: We may be able to reduce this in the future, addressing consensus faults with more complicated penalties,
   124  // sybil generation with crypto-economic mechanism, and PoSt soundness by increasing the challenges for small miners.
   125  func ConsensusMinerMinPower(p stabi.RegisteredPoStProof) (stabi.StoragePower, error) {
   126  	info, ok := PoStProofPolicies[p]
   127  	if !ok {
   128  		return stabi.NewStoragePower(0), errors.Errorf("unsupported proof type: %v", p)
   129  	}
   130  	return info.ConsensusMinerMinPower, nil
   131  }
   132  
   133  // Policy values associated with a PoSt proof type.
   134  type PoStProofPolicy struct {
   135  	WindowPoStPartitionSectors uint64
   136  	ConsensusMinerMinPower     stabi.StoragePower
   137  }
   138  
   139  // Partition sizes must match those used by the proofs library.
   140  // See https://github.com/filecoin-project/rust-fil-proofs/blob/master/filecoin-proofs/src/constants.rs#L85
   141  var PoStProofPolicies = map[stabi.RegisteredPoStProof]*PoStProofPolicy{
   142  	stabi.RegisteredPoStProof_StackedDrgWindow2KiBV1: {
   143  		WindowPoStPartitionSectors: 2,
   144  		ConsensusMinerMinPower:     stabi.NewStoragePower(10 << 40),
   145  	},
   146  	stabi.RegisteredPoStProof_StackedDrgWindow8MiBV1: {
   147  		WindowPoStPartitionSectors: 2,
   148  		ConsensusMinerMinPower:     stabi.NewStoragePower(10 << 40),
   149  	},
   150  	stabi.RegisteredPoStProof_StackedDrgWindow512MiBV1: {
   151  		WindowPoStPartitionSectors: 2,
   152  		ConsensusMinerMinPower:     stabi.NewStoragePower(10 << 40),
   153  	},
   154  	stabi.RegisteredPoStProof_StackedDrgWindow32GiBV1: {
   155  		WindowPoStPartitionSectors: 2349,
   156  		ConsensusMinerMinPower:     stabi.NewStoragePower(10 << 40),
   157  	},
   158  	stabi.RegisteredPoStProof_StackedDrgWindow64GiBV1: {
   159  		WindowPoStPartitionSectors: 2300,
   160  		ConsensusMinerMinPower:     stabi.NewStoragePower(10 << 40),
   161  	},
   162  	// Winning PoSt proof types omitted.
   163  }
   164  
   165  // Returns the partition size, in sectors, associated with a Window PoSt proof type.
   166  // The partition size is the number of sectors proved in a single PoSt proof.
   167  func PoStProofWindowPoStPartitionSectors(p stabi.RegisteredPoStProof) (uint64, error) {
   168  	info, ok := PoStProofPolicies[p]
   169  	if !ok {
   170  		return 0, errors.Errorf("unsupported proof type: %v", p)
   171  	}
   172  	return info.WindowPoStPartitionSectors, nil
   173  }