Cleanup handing and add tests
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
65724133ea
commit
5e775929be
@ -946,6 +946,23 @@ func (sma StorageMinerActor) SubmitElectionPoSt(act *types.Actor, vmctx types.VM
|
||||
}
|
||||
|
||||
activeFaults := uint64(0)
|
||||
for f := range faults {
|
||||
if f > amt.MaxIndex {
|
||||
continue
|
||||
}
|
||||
|
||||
var comms [][]byte
|
||||
err := pss.Get(f, &comms)
|
||||
if err != nil {
|
||||
var notfound *amt.ErrNotFound
|
||||
if xerrors.As(err, ¬found) {
|
||||
activeFaults++
|
||||
} else {
|
||||
return nil, aerrors.HandleExternalError(err, "failed to find sector in sector set")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error {
|
||||
if faults[id] {
|
||||
activeFaults++
|
||||
|
@ -104,6 +104,10 @@ func TestMinerSubmitBadFault(t *testing.T) {
|
||||
|
||||
assertSectorIDs(h, t, minerAddr, []uint64{1})
|
||||
|
||||
st, err := getMinerState(context.TODO(), h.vm.StateTree(), h.bs, minerAddr)
|
||||
assert.NoError(t, err)
|
||||
expectedPower := st.Power
|
||||
|
||||
bf := types.NewBitField()
|
||||
bf.Set(6)
|
||||
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.DeclareFaults, &actors.DeclareFaultsParams{bf})
|
||||
@ -127,6 +131,13 @@ func TestMinerSubmitBadFault(t *testing.T) {
|
||||
ApplyOK(t, ret)
|
||||
assertSectorIDs(h, t, minerAddr, []uint64{1})
|
||||
|
||||
st, err = getMinerState(context.TODO(), h.vm.StateTree(), h.bs, minerAddr)
|
||||
assert.NoError(t, err)
|
||||
currentPower := st.Power
|
||||
if types.BigCmp(expectedPower, currentPower) != 0 {
|
||||
t.Errorf("power changed and shouldn't have: %s != %s", expectedPower, currentPower)
|
||||
}
|
||||
|
||||
bf.Set(badnum - 2)
|
||||
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.DeclareFaults, &actors.DeclareFaultsParams{bf})
|
||||
if ret.ExitCode != 3 {
|
||||
@ -215,7 +226,7 @@ func assertSectorIDs(h *Harness, t *testing.T, maddr address.Address, ids []uint
|
||||
}
|
||||
}
|
||||
|
||||
func getMinerSectorSet(ctx context.Context, st types.StateTree, bs blockstore.Blockstore, maddr address.Address) ([]*api.ChainSectorInfo, error) {
|
||||
func getMinerState(ctx context.Context, st types.StateTree, bs blockstore.Blockstore, maddr address.Address) (*actors.StorageMinerActorState, error) {
|
||||
mact, err := st.GetActor(maddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -227,6 +238,14 @@ func getMinerSectorSet(ctx context.Context, st types.StateTree, bs blockstore.Bl
|
||||
if err := cst.Get(ctx, mact.Head, &mstate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mstate, nil
|
||||
}
|
||||
|
||||
func getMinerSectorSet(ctx context.Context, st types.StateTree, bs blockstore.Blockstore, maddr address.Address) ([]*api.ChainSectorInfo, error) {
|
||||
mstate, err := getMinerState(ctx, st, bs, maddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return stmgr.LoadSectorsFromSet(ctx, bs, mstate.Sectors)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user