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