From daaa725e3bf513fd3eac18ee2f48c4b7665acc89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 31 Aug 2021 16:24:29 +0200 Subject: [PATCH] sectors expired: Handle precomitted and unproven sectors correctly --- chain/actors/builtin/miner/actor.go.template | 6 ++++++ chain/actors/builtin/miner/miner.go | 6 ++++++ chain/actors/builtin/miner/state.go.template | 4 ++++ chain/actors/builtin/miner/v0.go | 4 ++++ chain/actors/builtin/miner/v2.go | 4 ++++ chain/actors/builtin/miner/v3.go | 4 ++++ chain/actors/builtin/miner/v4.go | 4 ++++ chain/actors/builtin/miner/v5.go | 4 ++++ cmd/lotus-miner/sectors.go | 19 +++++++++++++++++++ 9 files changed, 55 insertions(+) diff --git a/chain/actors/builtin/miner/actor.go.template b/chain/actors/builtin/miner/actor.go.template index 7ffe9f146..2669a05a6 100644 --- a/chain/actors/builtin/miner/actor.go.template +++ b/chain/actors/builtin/miner/actor.go.template @@ -157,6 +157,12 @@ type Partition interface { // Active sectors are those that are neither terminated nor faulty nor unproven, i.e. actively contributing power. ActiveSectors() (bitfield.BitField, error) + + // Unproven sectors in this partition. This bitfield will be cleared on + // a successful window post (or at the end of the partition's next + // deadline). At that time, any still unproven sectors will be added to + // the faulty sector bitfield. + UnprovenSectors() (bitfield.BitField, error) } type SectorOnChainInfo struct { diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 4621fa48b..e61b95eef 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -216,6 +216,12 @@ type Partition interface { // Active sectors are those that are neither terminated nor faulty nor unproven, i.e. actively contributing power. ActiveSectors() (bitfield.BitField, error) + + // Unproven sectors in this partition. This bitfield will be cleared on + // a successful window post (or at the end of the partition's next + // deadline). At that time, any still unproven sectors will be added to + // the faulty sector bitfield. + UnprovenSectors() (bitfield.BitField, error) } type SectorOnChainInfo struct { diff --git a/chain/actors/builtin/miner/state.go.template b/chain/actors/builtin/miner/state.go.template index b63a73a2c..2ea6a905e 100644 --- a/chain/actors/builtin/miner/state.go.template +++ b/chain/actors/builtin/miner/state.go.template @@ -549,6 +549,10 @@ func (p *partition{{.v}}) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition{{.v}}) UnprovenSectors() (bitfield.BitField, error) { + return {{if (ge .v 2)}}p.Partition.Unproven{{else}}bitfield.New(){{end}}, nil +} + func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorOnChainInfo { {{if (ge .v 2)}} return SectorOnChainInfo{ diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 422afec8a..564bcbbc2 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -500,6 +500,10 @@ func (p *partition0) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition0) UnprovenSectors() (bitfield.BitField, error) { + return bitfield.New(), nil +} + func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo { return (SectorOnChainInfo)(v0) diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index 81b32abb7..fe0863111 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -530,6 +530,10 @@ func (p *partition2) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition2) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo { return SectorOnChainInfo{ diff --git a/chain/actors/builtin/miner/v3.go b/chain/actors/builtin/miner/v3.go index 8ac77915a..b0d5429ea 100644 --- a/chain/actors/builtin/miner/v3.go +++ b/chain/actors/builtin/miner/v3.go @@ -531,6 +531,10 @@ func (p *partition3) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition3) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo { return SectorOnChainInfo{ diff --git a/chain/actors/builtin/miner/v4.go b/chain/actors/builtin/miner/v4.go index 5f442962f..7e5a9761a 100644 --- a/chain/actors/builtin/miner/v4.go +++ b/chain/actors/builtin/miner/v4.go @@ -531,6 +531,10 @@ func (p *partition4) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition4) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo { return SectorOnChainInfo{ diff --git a/chain/actors/builtin/miner/v5.go b/chain/actors/builtin/miner/v5.go index a3e03a7d4..7f4aaf168 100644 --- a/chain/actors/builtin/miner/v5.go +++ b/chain/actors/builtin/miner/v5.go @@ -531,6 +531,10 @@ func (p *partition5) RecoveringSectors() (bitfield.BitField, error) { return p.Partition.Recoveries, nil } +func (p *partition5) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + func fromV5SectorOnChainInfo(v5 miner5.SectorOnChainInfo) SectorOnChainInfo { return SectorOnChainInfo{ diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 194b1e554..ea091e1f4 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -1628,12 +1628,31 @@ var sectorsExpiredCmd = &cli.Command{ } toCheck, err = bitfield.SubtractBitField(toCheck, live) + if err != nil { + return err + } + + unproven, err := part.UnprovenSectors() + if err != nil { + return err + } + + toCheck, err = bitfield.SubtractBitField(toCheck, unproven) + return err }) }); err != nil { return err } + err = mas.ForEachPrecommittedSector(func(pci miner.SectorPreCommitOnChainInfo) error { + toCheck.Unset(uint64(pci.Info.SectorNumber)) + return nil + }) + if err != nil { + return err + } + if cctx.Bool("remove-expired") { color.Red("Removing sectors:\n") }