This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
/
miner_state.go
242 lines (210 loc) · 5.59 KB
/
miner_state.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package agent
import (
"context"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/dline"
miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/v5/actors/util/adt"
cid "github.com/ipfs/go-cid"
)
type MinerStateV4 struct {
Root cid.Cid
Ctx context.Context
st *miner4.State
}
func (m *MinerStateV4) state(store adt.Store) (*miner4.State, error) {
if m.st == nil {
var st miner4.State
err := store.Get(m.Ctx, m.Root, &st)
if err != nil {
return nil, err
}
m.st = &st
}
return m.st, nil
}
func (m *MinerStateV4) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) {
st, err := m.state(store)
if err != nil {
return false, err
}
return st.HasSectorNo(store, sectorNo)
}
func (m *MinerStateV4) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) {
st, err := m.state(store)
if err != nil {
return 0, 0, err
}
return st.FindSector(store, sectorNo)
}
func (m *MinerStateV4) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) {
st, err := m.state(store)
if err != nil {
return 0, err
}
return st.ProvingPeriodStart, nil
}
func (m *MinerStateV4) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
sectors, err := st.LoadSectorInfos(store, bitfield.NewFromSet([]uint64{uint64(sectorNo)}))
if err != nil {
return nil, err
}
return &SectorInfoV4{info: sectors[0]}, nil
}
func (m *MinerStateV4) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
return st.DeadlineInfo(currEpoch), nil
}
func (m *MinerStateV4) FeeDebt(store adt.Store) (abi.TokenAmount, error) {
st, err := m.state(store)
if err != nil {
return big.Zero(), err
}
return st.FeeDebt, nil
}
func (m *MinerStateV4) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
dls, err := st.LoadDeadlines(store)
if err != nil {
return nil, err
}
dline, err := dls.LoadDeadline(store, dlIdx)
if err != nil {
return nil, err
}
return &DeadlineStateV4{deadline: dline}, nil
}
type DeadlineStateV4 struct {
deadline *miner4.Deadline
}
func (d *DeadlineStateV4) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) {
part, err := d.deadline.LoadPartition(store, partIdx)
if err != nil {
return nil, err
}
return &PartitionStateV4{partition: part}, nil
}
type PartitionStateV4 struct {
partition *miner4.Partition
}
func (p *PartitionStateV4) Terminated() bitfield.BitField {
return p.partition.Terminated
}
type SectorInfoV4 struct {
info *miner4.SectorOnChainInfo
}
func (s *SectorInfoV4) Expiration() abi.ChainEpoch {
return s.info.Expiration
}
type MinerStateV5 struct {
Root cid.Cid
st *miner5.State
Ctx context.Context
}
func (m *MinerStateV5) state(store adt.Store) (*miner5.State, error) {
if m.st == nil {
var st miner5.State
err := store.Get(m.Ctx, m.Root, &st)
if err != nil {
return nil, err
}
m.st = &st
}
return m.st, nil
}
func (m *MinerStateV5) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) {
st, err := m.state(store)
if err != nil {
return false, err
}
return st.HasSectorNo(store, sectorNo)
}
func (m *MinerStateV5) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) {
st, err := m.state(store)
if err != nil {
return 0, 0, err
}
return st.FindSector(store, sectorNo)
}
func (m *MinerStateV5) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) {
st, err := m.state(store)
if err != nil {
return 0, err
}
return st.ProvingPeriodStart, nil
}
func (m *MinerStateV5) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
sectors, err := st.LoadSectorInfos(store, bitfield.NewFromSet([]uint64{uint64(sectorNo)}))
if err != nil {
return nil, err
}
return &SectorInfoV5{info: sectors[0]}, nil
}
func (m *MinerStateV5) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
return st.DeadlineInfo(currEpoch), nil
}
func (m *MinerStateV5) FeeDebt(store adt.Store) (abi.TokenAmount, error) {
st, err := m.state(store)
if err != nil {
return big.Zero(), err
}
return st.FeeDebt, nil
}
func (m *MinerStateV5) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) {
st, err := m.state(store)
if err != nil {
return nil, err
}
dls, err := st.LoadDeadlines(store)
if err != nil {
return nil, err
}
dline, err := dls.LoadDeadline(store, dlIdx)
if err != nil {
return nil, err
}
return &DeadlineStateV5{deadline: dline}, nil
}
type DeadlineStateV5 struct {
deadline *miner5.Deadline
}
func (d *DeadlineStateV5) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) {
part, err := d.deadline.LoadPartition(store, partIdx)
if err != nil {
return nil, err
}
return &PartitionStateV5{partition: part}, nil
}
type PartitionStateV5 struct {
partition *miner5.Partition
}
func (p *PartitionStateV5) Terminated() bitfield.BitField {
return p.partition.Terminated
}
type SectorInfoV5 struct {
info *miner5.SectorOnChainInfo
}
func (s *SectorInfoV5) Expiration() abi.ChainEpoch {
return s.info.Expiration
}