/
termination.go
83 lines (70 loc) · 2.76 KB
/
termination.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
package util
import (
"context"
"github.com/filecoin-project/go-state-types/builtin/v13/miner"
lotusapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/v6/actors/util/smoothing"
miner8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/miner"
cbor "github.com/ipfs/go-ipld-cbor"
)
// the SimpleQAPower bool is missing here on the conversion
func ConvertSectorType(sector *miner.SectorOnChainInfo) *miner8.SectorOnChainInfo {
return &miner8.SectorOnChainInfo{
SectorNumber: sector.SectorNumber,
SealProof: sector.SealProof,
SealedCID: sector.SealedCID,
DealIDs: sector.DealIDs,
Activation: sector.Activation,
Expiration: sector.Expiration,
DealWeight: sector.DealWeight,
VerifiedDealWeight: sector.VerifiedDealWeight,
InitialPledge: sector.InitialPledge,
ExpectedDayReward: sector.ExpectedDayReward,
ExpectedStoragePledge: sector.ExpectedStoragePledge,
ReplacedDayReward: sector.ReplacedDayReward,
SectorKeyCID: sector.SectorKeyCID,
}
}
func TotalPowerSmoothed(ctx context.Context, api *lotusapi.FullNodeStruct, tsk *types.TipSet) (smoothing.FilterEstimate, error) {
pact, err := api.StateGetActor(ctx, power.Address, tsk.Key())
if err != nil {
return smoothing.FilterEstimate{}, err
}
tbsPow := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(api), blockstore.NewMemory())
pas, err := power.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbsPow)), pact)
if err != nil {
return smoothing.FilterEstimate{}, err
}
smoothedPow, err := pas.TotalPowerSmoothed()
if err != nil {
return smoothing.FilterEstimate{}, err
}
return smoothing.NewEstimate(
smoothedPow.PositionEstimate,
smoothedPow.VelocityEstimate,
), nil
}
func ThisEpochRewardsSmoothed(ctx context.Context, api *lotusapi.FullNodeStruct, tsk *types.TipSet) (smoothing.FilterEstimate, error) {
ract, err := api.StateGetActor(ctx, reward.Address, tsk.Key())
if err != nil {
return smoothing.FilterEstimate{}, err
}
tbsRew := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(api), blockstore.NewMemory())
ras, err := reward.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbsRew)), ract)
if err != nil {
return smoothing.FilterEstimate{}, err
}
smoothedRew, err := ras.ThisEpochRewardSmoothed()
if err != nil {
return smoothing.FilterEstimate{}, err
}
return smoothing.NewEstimate(
smoothedRew.PositionEstimate,
smoothedRew.VelocityEstimate,
), nil
}