Skip to content

Commit

Permalink
sealing: numassign: itests/bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Aug 22, 2022
1 parent 00bef60 commit 129eba2
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@ workflows:
suite: itest-sector_miner_collateral
target: "./itests/sector_miner_collateral_test.go"

- test:
name: test-itest-sector_numassign
suite: itest-sector_numassign
target: "./itests/sector_numassign_test.go"

- test:
name: test-itest-sector_pledge
suite: itest-sector_pledge
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
130 changes: 130 additions & 0 deletions itests/sector_numassign_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package itests

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/itests/kit"
)

func TestAssignBasic(t *testing.T) {
kit.QuietMiningLogs()

ctx := context.Background()
blockTime := 1 * time.Millisecond

_, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs())
ens.InterconnectAll().BeginMiningMustPost(blockTime)

nSectors := 2

{
nam, err := miner.SectorNumAssignerMeta(ctx)
require.NoError(t, err)

// genesis sectors start at 1, so if there are 2, we expect the Next to be 3
require.Equal(t, abi.SectorNumber(miner.PresealSectors+1), nam.Next)
}

miner.PledgeSectors(ctx, nSectors, 0, nil)

sl, err := miner.SectorsListNonGenesis(ctx)
require.NoError(t, err)

require.Len(t, sl, nSectors)
require.Equal(t, abi.SectorNumber(miner.PresealSectors+1), sl[0])
require.Equal(t, abi.SectorNumber(miner.PresealSectors+2), sl[1])
}

func rangeBitField(from, to uint64) bitfield.BitField {
var runs []rlepluslazy.Run
if from > 0 {
runs = append(runs, rlepluslazy.Run{
Val: false,
Len: from,
})
}
runs = append(runs, rlepluslazy.Run{
Val: true,
Len: to - from + 1,
})

r, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{Runs: runs})
if err != nil {
panic(err)
}
return r
}

func TestAssignReservation(t *testing.T) {
kit.QuietMiningLogs()

ctx := context.Background()
blockTime := 1 * time.Millisecond

_, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs())
ens.InterconnectAll().BeginMiningMustPost(blockTime)

err := miner.SectorNumReserve(ctx, "test-reservation", rangeBitField(3, 10), false)
require.NoError(t, err)

// colliding name fails
err = miner.SectorNumReserve(ctx, "test-reservation", rangeBitField(30, 33), false)
require.Error(t, err)

// colliding range
err = miner.SectorNumReserve(ctx, "test-reservation2", rangeBitField(7, 12), false)
require.Error(t, err)

// illegal characters in the name
err = miner.SectorNumReserve(ctx, "test/reservation", rangeBitField(99, 100), false)
require.Error(t, err)

nSectors := 2

{
nam, err := miner.SectorNumAssignerMeta(ctx)
require.NoError(t, err)

// reservation to 10, so we expect 11 to be first free
require.Equal(t, abi.SectorNumber(11), nam.Next)
}

miner.PledgeSectors(ctx, nSectors, 0, nil)

sl, err := miner.SectorsListNonGenesis(ctx)
require.NoError(t, err)

require.Len(t, sl, nSectors)
require.Equal(t, abi.SectorNumber(11), sl[0])
require.Equal(t, abi.SectorNumber(12), sl[1])

// drop the reservation and see if we use the unused numbers
err = miner.SectorNumFree(ctx, "test-reservation")
require.NoError(t, err)

{
nam, err := miner.SectorNumAssignerMeta(ctx)
require.NoError(t, err)

// first post-genesis sector is 3
require.Equal(t, abi.SectorNumber(3), nam.Next)
}

miner.PledgeSectors(ctx, 1, nSectors, nil)

sl, err = miner.SectorsListNonGenesis(ctx)
require.NoError(t, err)

require.Len(t, sl, nSectors+1)
require.Equal(t, abi.SectorNumber(3), sl[0])
require.Equal(t, abi.SectorNumber(11), sl[1])
require.Equal(t, abi.SectorNumber(12), sl[2])
}
4 changes: 2 additions & 2 deletions storage/pipeline/numassign.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (m *Sealing) NumReserve(ctx context.Context, name string, reserving bitfiel
if err := cur.UnmarshalCBOR(bytes.NewReader(curRes)); err != nil {
return xerrors.Errorf("unmarshaling existing reservation: %w", err)
}
} else if err == datastore.ErrNotFound {
} else if err != datastore.ErrNotFound {
return xerrors.Errorf("checking if reservation exists: %w", err)
}

Expand Down Expand Up @@ -332,7 +332,7 @@ func (m *Sealing) NumFree(ctx context.Context, name string) error {
}

func reservationKey(name string) (datastore.Key, error) {
ok, err := regexp.Match("[a-zA-Z0-9_\\-]+]", []byte(name))
ok, err := regexp.Match("^[a-zA-Z0-9_\\-]+$", []byte(name))
if err != nil {
return datastore.Key{}, err
}
Expand Down

0 comments on commit 129eba2

Please sign in to comment.