diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index 12fe84522..53a8d303d 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -721,8 +721,10 @@ func RemoveFromSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, ids [ return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node") } - if err := ssr.BatchDelete(ids); err != nil { - return cid.Undef, aerrors.HandleExternalError(err, "failed to delete from sector set") + for _, id := range ids { + if err := ssr.Delete(id); err != nil { + log.Warnf("failed to delete sector %d from set: %s", id, err) + } } ncid, err := ssr.Flush() diff --git a/chain/actors/actor_miner_test.go b/chain/actors/actor_miner_test.go index 28a5ce046..568ce4805 100644 --- a/chain/actors/actor_miner_test.go +++ b/chain/actors/actor_miner_test.go @@ -52,6 +52,71 @@ func TestMinerCommitSectors(t *testing.T) { assertSectorIDs(h, t, minerAddr, []uint64{1}) } +func TestMinerSubmitBadFault(t *testing.T) { + var worker, client address.Address + var minerAddr address.Address + opts := []HarnessOpt{ + HarnessAddr(&worker, 1000000), + HarnessAddr(&client, 1000000), + HarnessActor(&minerAddr, &worker, actors.StorageMinerCodeCid, + func() cbg.CBORMarshaler { + return &actors.StorageMinerConstructorParams{ + Owner: worker, + Worker: worker, + SectorSize: 1024, + PeerID: "fakepeerid", + } + }), + } + + h := NewHarness(t, opts...) + h.vm.Syscalls.ValidatePoRep = func(ctx context.Context, maddr address.Address, ssize uint64, commD, commR, ticket, proof, seed []byte, sectorID uint64) (bool, aerrors.ActorError) { + // all proofs are valid + return true, nil + } + + ret, _ := h.SendFunds(t, worker, minerAddr, types.NewInt(100000)) + ApplyOK(t, ret) + + ret, _ = h.InvokeWithValue(t, client, actors.StorageMarketAddress, actors.SMAMethods.AddBalance, types.NewInt(2000), nil) + ApplyOK(t, ret) + + addSectorToMiner(h, t, minerAddr, worker, client, 1) + + assertSectorIDs(h, t, minerAddr, []uint64{1}) + + bf := types.NewBitField() + bf.Set(6) + ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.DeclareFaults, &actors.DeclareFaultsParams{bf}) + ApplyOK(t, ret) + + ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil) + ApplyOK(t, ret) + + assertSectorIDs(h, t, minerAddr, []uint64{1}) + + badnum := uint64(0) + badnum-- + bf = types.NewBitField() + bf.Set(badnum) + ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.DeclareFaults, &actors.DeclareFaultsParams{bf}) + ApplyOK(t, ret) + + ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil) + ApplyOK(t, ret) + + bf = types.NewBitField() + bf.Set(1) + ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.DeclareFaults, &actors.DeclareFaultsParams{bf}) + ApplyOK(t, ret) + + ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil) + ApplyOK(t, ret) + + assertSectorIDs(h, t, minerAddr, []uint64{}) + +} + func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client address.Address, sid uint64) { t.Helper() s := sectorbuilder.UserBytesForSectorSize(1024)