From 5d9d51ba2de5051499ca6c30eb41462ff1f643ce Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 20 Dec 2019 19:33:11 -0800 Subject: [PATCH 1/3] don't fail execution if the fault set contains an invalid sector ID --- chain/actors/actor_miner.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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() From 8098d237684a4ce08e19e71174e52438086cb6a5 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 20 Dec 2019 20:02:18 -0800 Subject: [PATCH 2/3] test to ensure that submitting bad faults doesnt cause an error --- chain/actors/actor_miner_test.go | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/chain/actors/actor_miner_test.go b/chain/actors/actor_miner_test.go index 28a5ce046..875a19059 100644 --- a/chain/actors/actor_miner_test.go +++ b/chain/actors/actor_miner_test.go @@ -52,6 +52,60 @@ 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}) + + 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) From dafad17a9b036bd2d964ef917de06e2c362e61a8 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 20 Dec 2019 20:04:38 -0800 Subject: [PATCH 3/3] also test fault values out of range --- chain/actors/actor_miner_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/chain/actors/actor_miner_test.go b/chain/actors/actor_miner_test.go index 875a19059..568ce4805 100644 --- a/chain/actors/actor_miner_test.go +++ b/chain/actors/actor_miner_test.go @@ -95,6 +95,16 @@ func TestMinerSubmitBadFault(t *testing.T) { 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}) @@ -104,6 +114,7 @@ func TestMinerSubmitBadFault(t *testing.T) { ApplyOK(t, ret) assertSectorIDs(h, t, minerAddr, []uint64{}) + } func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client address.Address, sid uint64) {