Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

update for lotus/actors network upgrade changes #260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lotus-soup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ require (
github.com/drand/drand v1.1.2-0.20200905144319-79c957281b32
github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20200731171407-e559a0579161 // indirect
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9
github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52
github.com/filecoin-project/go-state-types v0.0.0-20200911004822-964d6c679cfc
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b
github.com/filecoin-project/lotus v0.7.1-0.20200916113100-4ee9e7c1e1ab
github.com/filecoin-project/lotus v0.7.2-0.20200923173402-7d39542522ac
github.com/filecoin-project/specs-actors v0.9.10
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.4
Expand Down
10 changes: 6 additions & 4 deletions lotus-soup/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMX
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
github.com/filecoin-project/go-data-transfer v0.6.3 h1:7TLwm8nuodHYD/uiwJjKc/PGRR+LwqM8jmlZqgWuUfY=
github.com/filecoin-project/go-data-transfer v0.6.3/go.mod h1:PmBKVXkhh67/tnEdJXQwDHl5mT+7Tbcwe1NPninqhnM=
github.com/filecoin-project/go-data-transfer v0.6.4 h1:Q08ABa+cOTOLoAyHeA94fPLcwu53p6eeAaxMxQb0m0A=
github.com/filecoin-project/go-data-transfer v0.6.4/go.mod h1:PmBKVXkhh67/tnEdJXQwDHl5mT+7Tbcwe1NPninqhnM=
github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1:GxJzR3oRIMTPtpZ0b7QF8FKPK6/iPAc7trhlL5k/g+s=
github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c h1:YGoyYmELQ0LHwDj/WcOvY3oYt+3iM0wdrAhqJQUAIy4=
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200911011457-2959ccca6a3c/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A=
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9 h1:SnCUC9wHDId9TtV8PsQp8q1OOsi+NOLOwitIDnAgUa4=
github.com/filecoin-project/go-fil-markets v0.6.1-0.20200917052354-ee0af754c6e9/go.mod h1:PLr9svZxsnHkae1Ky7+66g7fP9AlneVxIVu+oSMq56A=
github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM=
github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24=
github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 h1:FXtCp0ybqdQL9knb3OGDpkNTaBbPxgkqPeWKotUwkH0=
Expand All @@ -276,8 +278,8 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg=
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8=
github.com/filecoin-project/lotus v0.7.1-0.20200916113100-4ee9e7c1e1ab h1:rbxwtt9qjpHAlb9VJsf+1lcU8VXalnyqU7SD3/ahYpI=
github.com/filecoin-project/lotus v0.7.1-0.20200916113100-4ee9e7c1e1ab/go.mod h1:T0of9kQi1A3OgJie3jEaBhJnYcwkFqHORK5OpIR/HO8=
github.com/filecoin-project/lotus v0.7.2-0.20200923173402-7d39542522ac h1:nF/xLKRhXlXu639+VF5/GGO4yEhF3Gzuxfje/w42w6E=
github.com/filecoin-project/lotus v0.7.2-0.20200923173402-7d39542522ac/go.mod h1:ssJ9hlWXFUjQ7vi7NQFBcwU/FcTLsoUdkqlp/Sdi44s=
github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4=
github.com/filecoin-project/specs-actors v0.9.7 h1:7PAZ8kdqwBdmgf/23FCkQZLCXcVu02XJrkpkhBikiA8=
github.com/filecoin-project/specs-actors v0.9.7/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU=
Expand Down
156 changes: 70 additions & 86 deletions lotus-soup/rfwp/chain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api/apibstore"
"github.com/filecoin-project/lotus/build"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"

"github.com/filecoin-project/oni/lotus-soup/testkit"

"github.com/filecoin-project/go-state-types/abi"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/power"

"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
tstats "github.com/filecoin-project/lotus/tools/stats"
)

Expand Down Expand Up @@ -171,9 +172,9 @@ type plainTextMarshaler interface {
}

type ProvingFaultState struct {
// FaultedSectors is a map of deadline indices to a list of faulted sectors for that proving window.
// If the miner has no faulty sectors, the map will be empty.
FaultedSectors map[int][]uint64
// FaultedSectors is a slice per-deadline faulty sectors. If the miner
// has no faulty sectors, this will be nil.
FaultedSectors [][]uint64
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this acceptable? I'm trying to avoid hard-coding the number of deadlines.

}

func (s *ProvingFaultState) MarshalPlainText() ([]byte, error) {
Expand All @@ -186,11 +187,9 @@ func (s *ProvingFaultState) MarshalPlainText() ([]byte, error) {

tw := tabwriter.NewWriter(w, 2, 4, 2, ' ', 0)
_, _ = fmt.Fprintf(tw, "deadline\tsectors")
for deadline := 0; deadline < int(miner.WPoStPeriodDeadlines); deadline++ {
if sectors, ok := s.FaultedSectors[deadline]; ok {
for _, num := range sectors {
_, _ = fmt.Fprintf(tw, "%d\t%d\n", deadline, num)
}
for deadline, sectors := range s.FaultedSectors {
for _, num := range sectors {
_, _ = fmt.Fprintf(tw, "%d\t%d\n", deadline, num)
}
}

Expand All @@ -201,8 +200,6 @@ func provingFaults(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr addr
api := m.FullApi
ctx := context.Background()

s := ProvingFaultState{FaultedSectors: make(map[int][]uint64)}

head, err := api.ChainHead(ctx)
if err != nil {
return nil, err
Expand All @@ -211,25 +208,33 @@ func provingFaults(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr addr
if err != nil {
return nil, err
}
faultedSectors := make([][]uint64, len(deadlines))
hasFaults := false
for dlIdx := range deadlines {
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
if err != nil {
return nil, err
}

for _, partition := range partitions {
faulty, err := partition.Faults.All(10000000)
faulty, err := partition.FaultySectors.All(10000000)
if err != nil {
return nil, err
}

for _, num := range faulty {
s.FaultedSectors[dlIdx] = append(s.FaultedSectors[dlIdx], num)
if len(faulty) > 0 {
hasFaults = true
}

faultedSectors[dlIdx] = append(faultedSectors[dlIdx], faulty...)
}
}
result := new(ProvingFaultState)
if hasFaults {
result.FaultedSectors = faultedSectors
}

return &s, nil
return result, nil
}

type ProvingInfoState struct {
Expand Down Expand Up @@ -279,42 +284,27 @@ func (s *ProvingInfoState) MarshalPlainText() ([]byte, error) {
}

func provingInfo(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr address.Address, height abi.ChainEpoch) (*ProvingInfoState, error) {
api := m.FullApi
lapi := m.FullApi
ctx := context.Background()

head, err := api.ChainHead(ctx)
head, err := lapi.ChainHead(ctx)
if err != nil {
return nil, err
}

cd, err := api.StateMinerProvingDeadline(ctx, maddr, head.Key())
cd, err := lapi.StateMinerProvingDeadline(ctx, maddr, head.Key())
if err != nil {
return nil, err
}

deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key())
deadlines, err := lapi.StateMinerDeadlines(ctx, maddr, head.Key())
if err != nil {
return nil, err
}

var mas miner.State
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't actually use this.

{
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil {
return nil, err
}
rmas, err := api.ChainReadObj(ctx, mact.Head)
if err != nil {
return nil, err
}
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
return nil, err
}
}

parts := map[uint64][]*miner.Partition{}
parts := map[uint64][]api.Partition{}
for dlIdx := range deadlines {
part, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
part, err := lapi.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
if err != nil {
return nil, err
}
Expand All @@ -328,19 +318,19 @@ func provingInfo(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr addres

for _, partitions := range parts {
for _, partition := range partitions {
sc, err := partition.Sectors.Count()
sc, err := partition.LiveSectors.Count()
if err != nil {
return nil, err
}
proving += sc

fc, err := partition.Faults.Count()
fc, err := partition.FaultySectors.Count()
if err != nil {
return nil, err
}
faults += fc

rc, err := partition.Faults.Count()
rc, err := partition.RecoveringSectors.Count()
if err != nil {
return nil, err
}
Expand All @@ -365,12 +355,12 @@ func provingInfo(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr addres
DeadlineClose: cd.Close,
DeadlineChallenge: cd.Challenge,
DeadlineFaultCutoff: cd.FaultCutoff,
WPoStProvingPeriod: miner.WPoStProvingPeriod,
WPoStProvingPeriod: cd.WPoStProvingPeriod,
}

if cd.Index < miner.WPoStPeriodDeadlines {
if cd.Index < cd.WPoStPeriodDeadlines {
for _, partition := range parts[cd.Index] {
sc, err := partition.Sectors.Count()
sc, err := partition.LiveSectors.Count()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -422,37 +412,22 @@ func (d *ProvingDeadlines) MarshalPlainText() ([]byte, error) {
}

func provingDeadlines(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr address.Address, height abi.ChainEpoch) (*ProvingDeadlines, error) {
api := m.FullApi
lapi := m.FullApi
ctx := context.Background()

deadlines, err := api.StateMinerDeadlines(ctx, maddr, types.EmptyTSK)
deadlines, err := lapi.StateMinerDeadlines(ctx, maddr, types.EmptyTSK)
if err != nil {
return nil, err
}

di, err := api.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
di, err := lapi.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
if err != nil {
return nil, err
}

var mas miner.State
{
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil {
return nil, err
}
rmas, err := api.ChainReadObj(ctx, mact.Head)
if err != nil {
return nil, err
}
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
return nil, err
}
}

infos := make([]DeadlineInfo, 0, len(deadlines))
for dlIdx, deadline := range deadlines {
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
partitions, err := lapi.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -541,16 +516,16 @@ func sectorsList(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr addres
}
activeIDs := make(map[abi.SectorNumber]struct{}, len(activeSet))
for _, info := range activeSet {
activeIDs[info.ID] = struct{}{}
activeIDs[info.SectorNumber] = struct{}{}
}

sset, err := node.StateMinerSectors(ctx, maddr, nil, true, types.EmptyTSK)
sset, err := node.StateMinerSectors(ctx, maddr, nil, types.EmptyTSK)
if err != nil {
return nil, err
}
commitedIDs := make(map[abi.SectorNumber]struct{}, len(activeSet))
for _, info := range sset {
commitedIDs[info.ID] = struct{}{}
commitedIDs[info.SectorNumber] = struct{}{}
}

sort.Slice(list, func(i, j int) bool {
Expand Down Expand Up @@ -629,7 +604,7 @@ func (i *MinerInfo) MarshalPlainText() ([]byte, error) {
i.FaultyPercentage)
}

if i.MinerPower.MinerPower.RawBytePower.LessThan(power.ConsensusMinerMinPower) {
if !i.MinerPower.HasMinPower {
fmt.Fprintf(w, "Below minimum power threshold, no blocks will be won\n")
} else {
expWinChance := float64(types.BigMul(qpercI, types.NewInt(build.BlocksPerEpoch)).Int64()) / 1000000
Expand Down Expand Up @@ -675,41 +650,36 @@ func info(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr address.Addre
api := m.FullApi
ctx := context.Background()

mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
ts, err := api.ChainHead(ctx)
if err != nil {
return nil, err
}
var mas miner.State
{
rmas, err := api.ChainReadObj(ctx, mact.Head)
if err != nil {
return nil, err
}
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
return nil, err
}

mact, err := api.StateGetActor(ctx, maddr, ts.Key())
if err != nil {
return nil, err
}

i := MinerInfo{MinerAddr: maddr}

// Sector size
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
mi, err := api.StateMinerInfo(ctx, maddr, ts.Key())
if err != nil {
return nil, err
}

i.SectorSize = types.SizeStr(types.NewInt(uint64(mi.SectorSize)))

i.MinerPower, err = api.StateMinerPower(ctx, maddr, types.EmptyTSK)
i.MinerPower, err = api.StateMinerPower(ctx, maddr, ts.Key())
if err != nil {
return nil, err
}

secCounts, err := api.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
secCounts, err := api.StateMinerSectorCount(ctx, maddr, ts.Key())
if err != nil {
return nil, err
}
faults, err := api.StateMinerFaults(ctx, maddr, types.EmptyTSK)
faults, err := api.StateMinerFaults(ctx, maddr, ts.Key())
if err != nil {
return nil, err
}
Expand All @@ -719,20 +689,34 @@ func info(t *testkit.TestEnvironment, m *testkit.LotusMiner, maddr address.Addre
return nil, err
}

i.CommittedBytes = types.BigMul(types.NewInt(secCounts.Sectors), types.NewInt(uint64(mi.SectorSize)))
i.CommittedBytes = types.BigMul(types.NewInt(secCounts.Live), types.NewInt(uint64(mi.SectorSize)))
i.ProvingBytes = types.BigMul(types.NewInt(secCounts.Active), types.NewInt(uint64(mi.SectorSize)))

if nfaults != 0 {
if secCounts.Sectors != 0 {
i.FaultyPercentage = float64(10000*nfaults/secCounts.Sectors) / 100.
if secCounts.Live != 0 {
i.FaultyPercentage = float64(10000*nfaults/secCounts.Live) / 100.
}
i.FaultyBytes = types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))
}

stor := store.ActorStore(ctx, apibstore.NewAPIBlockstore(api))
mas, err := miner.Load(stor, mact)
if err != nil {
return nil, err
}

funds, err := mas.LockedFunds()
if err != nil {
return nil, err
}

i.Balance = mact.Balance
i.PreCommitDeposits = mas.PreCommitDeposits
i.LockedFunds = mas.LockedFunds
i.AvailableFunds = types.BigSub(mact.Balance, types.BigAdd(mas.LockedFunds, mas.PreCommitDeposits))
i.PreCommitDeposits = funds.PreCommitDeposits
i.LockedFunds = funds.VestingFunds
i.AvailableFunds, err = mas.AvailableBalance(mact.Balance)
if err != nil {
return nil, err
}

wb, err := api.WalletBalance(ctx, mi.Worker)
if err != nil {
Expand Down
Loading