Skip to content

Commit

Permalink
Make everything proven
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed May 20, 2021
1 parent 7a02a55 commit 632a989
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 5 deletions.
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions chain/actors/builtin/miner/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type State interface {

// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
// Testing only
EraseAllUnproven() error

LoadDeadline(idx uint64) (Deadline, error)
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
Expand Down
2 changes: 2 additions & 0 deletions chain/actors/builtin/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ type State interface {

// Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors
GetProvingPeriodStart() (abi.ChainEpoch, error)
// Testing only
EraseAllUnproven() error

LoadDeadline(idx uint64) (Deadline, error)
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
Expand Down
39 changes: 39 additions & 0 deletions chain/actors/builtin/miner/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,45 @@ func (s *state{{.v}}) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (Secto
return fromV{{.v}}SectorPreCommitOnChainInfo(sp), nil
}

func (s *state{{.v}}) EraseAllUnproven() error {
{{if (ge .v 2)}}
dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}

err = dls.ForEach(s.store, func(dindx uint64, dl *miner{{.v}}.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}

var part miner{{.v}}.Partition
err = ps.ForEach(&part, func(pindx int64) error {
_ = part.ActivateUnproven()
err = ps.Set(uint64(pindx), &part)
return nil
})

if err != nil {
return err
}

dl.Partitions, err = ps.Root()
if err != nil {
return err
}

return dls.UpdateDeadline(s.store, dindx, dl)
})

return s.State.SaveDeadlines(s.store, dls)
{{else}}
// field doesn't exist until v2
{{end}}
return nil
}

func (d *deadline{{.v}}) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions chain/actors/builtin/miner/v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV0SectorPreCommitOnChainInfo(sp), nil
}

func (s *state0) EraseAllUnproven() error {

// field doesn't exist until v2

return nil
}

func (d *deadline0) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions chain/actors/builtin/miner/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,43 @@ func (s *state2) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV2SectorPreCommitOnChainInfo(sp), nil
}

func (s *state2) EraseAllUnproven() error {

dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}

err = dls.ForEach(s.store, func(dindx uint64, dl *miner2.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}

var part miner2.Partition
err = ps.ForEach(&part, func(pindx int64) error {
_ = part.ActivateUnproven()
err = ps.Set(uint64(pindx), &part)
return nil
})

if err != nil {
return err
}

dl.Partitions, err = ps.Root()
if err != nil {
return err
}

return dls.UpdateDeadline(s.store, dindx, dl)
})

return s.State.SaveDeadlines(s.store, dls)

return nil
}

func (d *deadline2) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions chain/actors/builtin/miner/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,43 @@ func (s *state3) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV3SectorPreCommitOnChainInfo(sp), nil
}

func (s *state3) EraseAllUnproven() error {

dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}

err = dls.ForEach(s.store, func(dindx uint64, dl *miner3.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}

var part miner3.Partition
err = ps.ForEach(&part, func(pindx int64) error {
_ = part.ActivateUnproven()
err = ps.Set(uint64(pindx), &part)
return nil
})

if err != nil {
return err
}

dl.Partitions, err = ps.Root()
if err != nil {
return err
}

return dls.UpdateDeadline(s.store, dindx, dl)
})

return s.State.SaveDeadlines(s.store, dls)

return nil
}

func (d *deadline3) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions chain/actors/builtin/miner/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,43 @@ func (s *state4) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC
return fromV4SectorPreCommitOnChainInfo(sp), nil
}

func (s *state4) EraseAllUnproven() error {

dls, err := s.State.LoadDeadlines(s.store)
if err != nil {
return err
}

err = dls.ForEach(s.store, func(dindx uint64, dl *miner4.Deadline) error {
ps, err := dl.PartitionsArray(s.store)
if err != nil {
return err
}

var part miner4.Partition
err = ps.ForEach(&part, func(pindx int64) error {
_ = part.ActivateUnproven()
err = ps.Set(uint64(pindx), &part)
return nil
})

if err != nil {
return err
}

dl.Partitions, err = ps.Root()
if err != nil {
return err
}

return dls.UpdateDeadline(s.store, dindx, dl)
})

return s.State.SaveDeadlines(s.store, dls)

return nil
}

func (d *deadline4) LoadPartition(idx uint64) (Partition, error) {
p, err := d.Deadline.LoadPartition(d.store, idx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions chain/actors/builtin/paych/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type mockState struct {
lanes map[uint64]paych.LaneState
}

func (ms *mockState) GetState() interface{} {
panic("implement me")
}

type mockLaneState struct {
redeemed big.Int
nonce uint64
Expand Down
30 changes: 30 additions & 0 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,36 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
}

_, err = vm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}

mact, err := vm.StateTree().GetActor(minerInfos[i].maddr)
if err != nil {
return cid.Undef, xerrors.Errorf("getting miner actor: %w", err)
}

mst, err := miner.Load(adt.WrapStore(ctx, cst), mact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting miner state: %w", err)
}

if err = mst.EraseAllUnproven(); err != nil {
return cid.Undef, xerrors.Errorf("failed to erase unproven sectors: %w", err)
}

mcid, err := cst.Put(ctx, mst.GetState())
if err != nil {
return cid.Undef, xerrors.Errorf("putting miner state: %w", err)
}

mact.Head = mcid

if err = vm.StateTree().SetActor(minerInfos[i].maddr, mact); err != nil {
return cid.Undef, xerrors.Errorf("setting miner state: %w", err)
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion chain/state/statetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"testing"

"github.com/filecoin-project/go-state-types/network"

"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"

Expand Down Expand Up @@ -362,7 +364,7 @@ func TestStateTreeConsistency(t *testing.T) {

// TODO: ActorUpgrade: this test tests pre actors v2

sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(network.Version3)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -4551,7 +4551,7 @@ Inputs:
]
```

Response: `11`
Response: `12`

### StateReadState
StateReadState returns the indicated actor's state.
Expand Down
2 changes: 1 addition & 1 deletion documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -4772,7 +4772,7 @@ Inputs:
]
```

Response: `11`
Response: `12`

### StateReadState
StateReadState returns the indicated actor's state.
Expand Down
6 changes: 4 additions & 2 deletions node/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/filecoin-project/go-state-types/network"

"github.com/gorilla/mux"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -277,7 +279,7 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
genms = append(genms, *genm)
}
templ := &genesis.Template{
ActorVersion: actors.Version0,
NetworkVersion: network.Version0,
Accounts: genaccs,
Miners: genms,
NetworkName: "test",
Expand Down Expand Up @@ -441,7 +443,7 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
genms = append(genms, *genm)
}
templ := &genesis.Template{
ActorVersion: actors.Version0,
NetworkVersion: network.Version0,
Accounts: genaccs,
Miners: genms,
NetworkName: "test",
Expand Down

0 comments on commit 632a989

Please sign in to comment.