sealing: numassign: itests/bug fixes
This commit is contained in:
parent
00bef607ca
commit
129eba2b5d
@ -979,6 +979,11 @@ workflows:
|
|||||||
suite: itest-sector_miner_collateral
|
suite: itest-sector_miner_collateral
|
||||||
target: "./itests/sector_miner_collateral_test.go"
|
target: "./itests/sector_miner_collateral_test.go"
|
||||||
|
|
||||||
|
- test:
|
||||||
|
name: test-itest-sector_numassign
|
||||||
|
suite: itest-sector_numassign
|
||||||
|
target: "./itests/sector_numassign_test.go"
|
||||||
|
|
||||||
- test:
|
- test:
|
||||||
name: test-itest-sector_pledge
|
name: test-itest-sector_pledge
|
||||||
suite: itest-sector_pledge
|
suite: itest-sector_pledge
|
||||||
|
Binary file not shown.
Binary file not shown.
130
itests/sector_numassign_test.go
Normal file
130
itests/sector_numassign_test.go
Normal file
@ -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])
|
||||||
|
}
|
@ -224,7 +224,7 @@ func (m *Sealing) NumReserve(ctx context.Context, name string, reserving bitfiel
|
|||||||
if err := cur.UnmarshalCBOR(bytes.NewReader(curRes)); err != nil {
|
if err := cur.UnmarshalCBOR(bytes.NewReader(curRes)); err != nil {
|
||||||
return xerrors.Errorf("unmarshaling existing reservation: %w", err)
|
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)
|
return xerrors.Errorf("checking if reservation exists: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ func (m *Sealing) NumFree(ctx context.Context, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reservationKey(name string) (datastore.Key, 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 {
|
if err != nil {
|
||||||
return datastore.Key{}, err
|
return datastore.Key{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user