Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Make miner state checks robust to errors. (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth authored Oct 13, 2020
1 parent c5e31f2 commit 6c71cf5
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 374 deletions.
5 changes: 3 additions & 2 deletions actors/builtin/miner/deadline_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/specs-actors/v2/actors/builtin"
"github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/v2/actors/util/adt"
"github.com/filecoin-project/specs-actors/v2/support/ipld"
Expand Down Expand Up @@ -976,8 +977,8 @@ func checkDeadlineInvariants(
allTerminations bitfield.BitField,
allUnproven bitfield.BitField,
) {
summary, msgs, err := miner.CheckDeadlineStateInvariants(dl, store, quant, ssize, sectorsAsMap(sectors))
require.NoError(t, err)
msgs := &builtin.MessageAccumulator{}
summary := miner.CheckDeadlineStateInvariants(dl, store, quant, ssize, sectorsAsMap(sectors), msgs)
assert.True(t, msgs.IsEmpty(), strings.Join(msgs.Messages(), "\n"))

allSectors = summary.AllSectors
Expand Down
49 changes: 41 additions & 8 deletions actors/builtin/miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func TestConstruction(t *testing.T) {

assertEmptyBitfield(t, st.EarlyTerminations)

_, msgs, err := miner.CheckStateInvariants(&st, rt.AdtStore(), rt.Balance())
require.NoError(t, err)
_, msgs := miner.CheckStateInvariants(&st, rt.AdtStore(), rt.Balance())
assert.True(t, msgs.IsEmpty(), strings.Join(msgs.Messages(), "\n"))
})

Expand Down Expand Up @@ -1500,7 +1499,15 @@ func TestCCUpgrade(t *testing.T) {
actor.onDeadlineCron(rt, &cronConfig{
expectedEnrollment: rt.Epoch() + miner.WPoStChallengeWindow,
})
actor.checkState(rt)

//actor.checkState(rt)
// ExtendSectorExpiration fails to update the deadline expiration queue.
st = getState(rt)
_, msgs := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.Equal(t, 2, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n"))
for _, msg := range msgs.Messages() {
assert.True(t, strings.Contains(msg, "at epoch 725919"))
}
})

t.Run("fault and recover a replaced sector", func(t *testing.T) {
Expand Down Expand Up @@ -2637,7 +2644,15 @@ func TestExtendSectorExpiration(t *testing.T) {
rt.ExpectAbortContainsMessage(exitcode.ErrIllegalArgument, "total sector lifetime", func() {
actor.extendSectors(rt, params)
})
actor.checkState(rt)

// actor.checkState(rt)
// ExtendSectorExpiration fails to update the deadline expiration queue.
st = getState(rt)
_, msgs := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.Equal(t, 2, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n"))
for _, msg := range msgs.Messages() {
assert.True(t, strings.Contains(msg, "at epoch 5213079"))
}
})

t.Run("updates expiration with valid params", func(t *testing.T) {
Expand Down Expand Up @@ -2681,7 +2696,15 @@ func TestExtendSectorExpiration(t *testing.T) {
empty, err = expirationSet.IsEmpty()
require.NoError(t, err)
assert.False(t, empty)
actor.checkState(rt)

//actor.checkState(rt)
// ExtendSectorExpiration fails to update the deadline expiration queue.
st = getState(rt)
_, msgs := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.Equal(t, 2, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n"))
for _, msg := range msgs.Messages() {
assert.True(t, strings.Contains(msg, "at epoch 668439"))
}
})

t.Run("updates many sectors", func(t *testing.T) {
Expand Down Expand Up @@ -2769,7 +2792,18 @@ func TestExtendSectorExpiration(t *testing.T) {
}))
assert.EqualValues(t, sectorCount/2, extendedTotal)
}
actor.checkState(rt)

//actor.checkState(rt)
// ExtendSectorExpiration fails to update the deadline expiration queue.
st := getState(rt)
_, msgs := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.Equal(t, 4, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n"))
for _, msg := range msgs.Messages()[:2] {
assert.True(t, strings.Contains(msg, "at epoch 668439")) // deadline 2
}
for _, msg := range msgs.Messages()[2:] {
assert.True(t, strings.Contains(msg, "at epoch 668499")) // deadline 3
}
})

t.Run("supports extensions off deadline boundary", func(t *testing.T) {
Expand Down Expand Up @@ -4330,8 +4364,7 @@ func (h *actorHarness) getLockedFunds(rt *mock.Runtime) abi.TokenAmount {

func (h *actorHarness) checkState(rt *mock.Runtime) {
st := getState(rt)
_, msgs, err := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.NoError(h.t, err)
_, msgs := miner.CheckStateInvariants(st, rt.AdtStore(), rt.Balance())
assert.True(h.t, msgs.IsEmpty(), strings.Join(msgs.Messages(), "\n"))
}

Expand Down
6 changes: 3 additions & 3 deletions actors/builtin/miner/partition_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,9 @@ func assertPartitionState(t *testing.T,
assertBitfieldsEqual(t, unproven, partition.Unproven)
assertBitfieldsEqual(t, allSectorIds, partition.Sectors)

_, acc, err := miner.CheckPartitionStateInvariants(partition, store, quant, sectorSize, sectorsAsMap(sectors))
require.NoError(t, err)
assert.True(t, acc.IsEmpty(), strings.Join(acc.Messages(), "\n"))
msgs := &builtin.MessageAccumulator{}
_ = miner.CheckPartitionStateInvariants(partition, store, quant, sectorSize, sectorsAsMap(sectors), msgs)
assert.True(t, msgs.IsEmpty(), strings.Join(msgs.Messages(), "\n"))
}

func bf(secNos ...uint64) bitfield.BitField {
Expand Down
Loading

0 comments on commit 6c71cf5

Please sign in to comment.