specs-actors: Fis some test compilation errors

This commit is contained in:
Łukasz Magiera 2020-02-10 20:16:36 +01:00
parent 7e70536bf1
commit c0ed0dda8e
24 changed files with 226 additions and 201 deletions

View File

@ -8,6 +8,16 @@ import (
"testing"
"github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/crypto"
blockstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/stretchr/testify/assert"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
@ -16,10 +26,6 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/rlepluslazy"
blockstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/stretchr/testify/assert"
cbg "github.com/whyrusleeping/cbor-gen"
)
func TestMinerCommitSectors(t *testing.T) {
@ -40,7 +46,7 @@ func TestMinerCommitSectors(t *testing.T) {
}
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) {
h.vm.Syscalls.ValidatePoRep = func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber) (bool, aerrors.ActorError) {
// all proofs are valid
return true, nil
}
@ -53,7 +59,7 @@ func TestMinerCommitSectors(t *testing.T) {
addSectorToMiner(h, t, minerAddr, worker, client, 1)
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
}
@ -74,7 +80,7 @@ var _ rlepluslazy.RunIterator = (*badRuns)(nil)
func TestMinerSubmitBadFault(t *testing.T) {
oldSS, oldMin := build.SectorSizes, build.MinimumMinerPower
build.SectorSizes, build.MinimumMinerPower = []uint64{1024}, 1024
build.SectorSizes, build.MinimumMinerPower = []abi.SectorSize{1024}, 1024
defer func() {
build.SectorSizes, build.MinimumMinerPower = oldSS, oldMin
}()
@ -88,7 +94,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
}
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) {
h.vm.Syscalls.ValidatePoRep = func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber) (bool, aerrors.ActorError) {
// all proofs are valid
return true, nil
}
@ -101,7 +107,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
addSectorToMiner(h, t, minerAddr, worker, client, 1)
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
bf := types.NewBitField()
bf.Set(6)
@ -110,7 +116,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil)
ApplyOK(t, ret)
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
st, err := getMinerState(context.TODO(), h.vm.StateTree(), h.bs, minerAddr)
assert.NoError(t, err)
@ -130,7 +136,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil)
ApplyOK(t, ret)
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
st, err = getMinerState(context.TODO(), h.vm.StateTree(), h.bs, minerAddr)
assert.NoError(t, err)
@ -144,7 +150,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
if ret.ExitCode != 3 {
t.Errorf("expected exit code 3, got %d: %+v", ret.ExitCode, ret.ActorErr)
}
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
rle, err := rlepluslazy.EncodeRuns(&badRuns{}, []byte{})
assert.NoError(t, err)
@ -155,7 +161,7 @@ func TestMinerSubmitBadFault(t *testing.T) {
if ret.ExitCode != 3 {
t.Errorf("expected exit code 3, got %d: %+v", ret.ExitCode, ret.ActorErr)
}
assertSectorIDs(h, t, minerAddr, []uint64{1})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{1})
bf = types.NewBitField()
bf.Set(1)
@ -165,17 +171,17 @@ func TestMinerSubmitBadFault(t *testing.T) {
ret, _ = h.Invoke(t, actors.NetworkAddress, minerAddr, actors.MAMethods.SubmitElectionPoSt, nil)
ApplyOK(t, ret)
assertSectorIDs(h, t, minerAddr, []uint64{})
assertSectorIDs(h, t, minerAddr, []abi.SectorNumber{})
}
func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client address.Address, sid uint64) {
func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client address.Address, sid abi.SectorNumber) {
t.Helper()
s := sectorbuilder.UserBytesForSectorSize(1024)
s := abi.PaddedPieceSize(1024).Unpadded()
deal := h.makeFakeDeal(t, minerAddr, worker, client, s)
ret, _ := h.Invoke(t, worker, actors.StorageMarketAddress, actors.SMAMethods.PublishStorageDeals,
&actors.PublishStorageDealsParams{
Deals: []actors.StorageDealProposal{*deal},
Deals: []market.ClientDealProposal{*deal},
})
ApplyOK(t, ret)
var dealIds actors.PublishStorageDealResponse
@ -183,28 +189,27 @@ func addSectorToMiner(h *Harness, t *testing.T, minerAddr, worker, client addres
t.Fatal(err)
}
dealid := dealIds.DealIDs[0]
dealid := dealIds.IDs[0]
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.PreCommitSector,
&actors.SectorPreCommitInfo{
&miner.SectorPreCommitInfo{
SectorNumber: sid,
CommR: []byte("cats"),
SealedCID: commcid.ReplicaCommitmentV1ToCID([]byte("cats")),
SealEpoch: 10,
DealIDs: []uint64{dealid},
DealIDs: []abi.DealID{dealid},
})
ApplyOK(t, ret)
h.BlockHeight += 100
ret, _ = h.Invoke(t, worker, minerAddr, actors.MAMethods.ProveCommitSector,
&actors.SectorProveCommitInfo{
Proof: []byte("prooofy"),
SectorID: sid,
DealIDs: []uint64{dealid}, // TODO: weird that i have to pass this again
&miner.ProveCommitSectorParams{
SectorNumber: sid,
Proof: abi.SealProof{ProofBytes: []byte("prooofy")},
})
ApplyOK(t, ret)
}
func assertSectorIDs(h *Harness, t *testing.T, maddr address.Address, ids []uint64) {
func assertSectorIDs(h *Harness, t *testing.T, maddr address.Address, ids []abi.SectorNumber) {
t.Helper()
sectors, err := getMinerSectorSet(context.TODO(), h.vm.StateTree(), h.bs, maddr)
if err != nil {
@ -215,7 +220,7 @@ func assertSectorIDs(h *Harness, t *testing.T, maddr address.Address, ids []uint
t.Fatal("miner has wrong number of sectors in their sector set")
}
all := make(map[uint64]bool)
all := make(map[abi.SectorNumber]bool)
for _, s := range sectors {
all[s.SectorID] = true
}
@ -251,7 +256,7 @@ func getMinerSectorSet(ctx context.Context, st types.StateTree, bs blockstore.Bl
return stmgr.LoadSectorsFromSet(ctx, bs, mstate.Sectors)
}
func (h *Harness) makeFakeDeal(t *testing.T, miner, worker, client address.Address, size uint64) *actors.StorageDealProposal {
func (h *Harness) makeFakeDeal(t *testing.T, miner, worker, client address.Address, size abi.UnpaddedPieceSize) *market.ClientDealProposal {
data := make([]byte, size)
rand.Read(data)
commP, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(data), size)
@ -259,23 +264,22 @@ func (h *Harness) makeFakeDeal(t *testing.T, miner, worker, client address.Addre
t.Fatal(err)
}
prop := actors.StorageDealProposal{
PieceRef: commP[:],
PieceSize: size,
prop := market.DealProposal{
PieceCID: commcid.PieceCommitmentV1ToCID(commP[:]),
PieceSize: size.Padded(),
Client: client,
Provider: miner,
ProposalExpiration: 10000,
Duration: 150,
StartEpoch: 10000,
EndEpoch: 10150,
StoragePricePerEpoch: types.NewInt(1),
StorageCollateral: types.NewInt(0),
ProviderCollateral: types.NewInt(0),
}
if err := api.SignWith(context.TODO(), h.w.Sign, client, &prop); err != nil {
t.Fatal(err)
return &market.ClientDealProposal{
Proposal: prop,
ClientSignature: crypto.Signature{}, // TODO: not quite correct
}
return &prop
}

View File

@ -6,6 +6,8 @@ import (
"math/rand"
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/ipfs/go-cid"
@ -49,7 +51,7 @@ type Harness struct {
Nonces map[address.Address]uint64
GasCharges map[address.Address]types.BigInt
Rand vm.Rand
BlockHeight uint64
BlockHeight abi.ChainEpoch
lastBalanceCheck map[address.Address]types.BigInt

View File

@ -6,6 +6,8 @@ import (
"testing"
"time"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/store"
@ -31,7 +33,7 @@ type fakeMsg struct {
type fakeCS struct {
t *testing.T
h uint64
h abi.ChainEpoch
tsc *tipSetCache
msgs map[cid.Cid]fakeMsg
@ -48,11 +50,11 @@ func (fcs *fakeCS) StateGetActor(ctx context.Context, actor address.Address, ts
panic("Not Implemented")
}
func (fcs *fakeCS) ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet) (*types.TipSet, error) {
func (fcs *fakeCS) ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, *types.TipSet) (*types.TipSet, error) {
panic("Not Implemented")
}
func makeTs(t *testing.T, h uint64, msgcid cid.Cid) *types.TipSet {
func makeTs(t *testing.T, h abi.ChainEpoch, msgcid cid.Cid) *types.TipSet {
a, _ := address.NewFromString("t00")
b, _ := address.NewFromString("t02")
var ts, err = types.NewTipSet([]*types.BlockHeader{
@ -206,7 +208,7 @@ func TestAt(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 5, int(ts.Height()))
require.Equal(t, 8, int(curH))
applied = true
@ -271,7 +273,7 @@ func TestAtDoubleTrigger(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 5, int(ts.Height()))
require.Equal(t, 8, int(curH))
applied = true
@ -313,8 +315,8 @@ func TestAtNullTrigger(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
require.Equal(t, uint64(6), ts.Height())
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, abi.ChainEpoch(6), ts.Height())
require.Equal(t, 8, int(curH))
applied = true
return nil
@ -347,7 +349,7 @@ func TestAtNullConf(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 5, int(ts.Height()))
require.Equal(t, 8, int(curH))
applied = true
@ -388,7 +390,7 @@ func TestAtStart(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 5, int(ts.Height()))
require.Equal(t, 8, int(curH))
applied = true
@ -422,7 +424,7 @@ func TestAtStartConfidence(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 5, int(ts.Height()))
require.Equal(t, 11, int(curH))
applied = true
@ -450,8 +452,8 @@ func TestAtChained(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
return events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
return events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 10, int(ts.Height()))
applied = true
return nil
@ -486,8 +488,8 @@ func TestAtChainedConfidence(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
return events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
return events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
require.Equal(t, 10, int(ts.Height()))
applied = true
return nil
@ -520,7 +522,7 @@ func TestAtChainedConfidenceNull(t *testing.T) {
var applied bool
var reverted bool
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH uint64) error {
err := events.ChainAt(func(_ context.Context, ts *types.TipSet, curH abi.ChainEpoch) error {
applied = true
require.Equal(t, 6, int(ts.Height()))
return nil
@ -560,11 +562,11 @@ func TestCalled(t *testing.T) {
var applied, reverted bool
var appliedMsg *types.Message
var appliedTs *types.TipSet
var appliedH uint64
var appliedH abi.ChainEpoch
err = events.Called(func(ts *types.TipSet) (d bool, m bool, e error) {
return false, true, nil
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH uint64) (bool, error) {
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (bool, error) {
require.Equal(t, false, applied)
applied = true
appliedMsg = msg
@ -610,9 +612,9 @@ func TestCalled(t *testing.T) {
require.Equal(t, false, applied)
require.Equal(t, false, reverted)
require.Equal(t, uint64(7), appliedTs.Height())
require.Equal(t, abi.ChainEpoch(7), appliedTs.Height())
require.Equal(t, "bafkqaaa", appliedTs.Blocks()[0].Messages.String())
require.Equal(t, uint64(10), appliedH)
require.Equal(t, abi.ChainEpoch(10), appliedH)
require.Equal(t, t0123, appliedMsg.To)
require.Equal(t, uint64(1), appliedMsg.Nonce)
require.Equal(t, uint64(5), appliedMsg.Method)
@ -647,9 +649,9 @@ func TestCalled(t *testing.T) {
require.Equal(t, false, reverted)
applied = false
require.Equal(t, uint64(9), appliedTs.Height())
require.Equal(t, abi.ChainEpoch(9), appliedTs.Height())
require.Equal(t, "bafkqaaa", appliedTs.Blocks()[0].Messages.String())
require.Equal(t, uint64(12), appliedH)
require.Equal(t, abi.ChainEpoch(12), appliedH)
require.Equal(t, t0123, appliedMsg.To)
require.Equal(t, uint64(2), appliedMsg.Nonce)
require.Equal(t, uint64(5), appliedMsg.Method)
@ -668,9 +670,9 @@ func TestCalled(t *testing.T) {
reverted = false
applied = false
require.Equal(t, uint64(11), appliedTs.Height())
require.Equal(t, abi.ChainEpoch(11), appliedTs.Height())
require.Equal(t, "bafkqaaa", appliedTs.Blocks()[0].Messages.String())
require.Equal(t, uint64(14), appliedH)
require.Equal(t, abi.ChainEpoch(14), appliedH)
require.Equal(t, t0123, appliedMsg.To)
require.Equal(t, uint64(2), appliedMsg.Nonce)
require.Equal(t, uint64(5), appliedMsg.Method)
@ -765,11 +767,11 @@ func TestCalledTimeout(t *testing.T) {
err = events.Called(func(ts *types.TipSet) (d bool, m bool, e error) {
return false, true, nil
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH uint64) (bool, error) {
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (bool, error) {
called = true
require.Nil(t, msg)
require.Equal(t, uint64(20), ts.Height())
require.Equal(t, uint64(23), curH)
require.Equal(t, abi.ChainEpoch(20), ts.Height())
require.Equal(t, abi.ChainEpoch(23), curH)
return false, nil
}, func(_ context.Context, ts *types.TipSet) error {
t.Fatal("revert on timeout")
@ -800,11 +802,11 @@ func TestCalledTimeout(t *testing.T) {
err = events.Called(func(ts *types.TipSet) (d bool, m bool, e error) {
return true, true, nil
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH uint64) (bool, error) {
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (bool, error) {
called = true
require.Nil(t, msg)
require.Equal(t, uint64(20), ts.Height())
require.Equal(t, uint64(23), curH)
require.Equal(t, abi.ChainEpoch(20), ts.Height())
require.Equal(t, abi.ChainEpoch(23), curH)
return false, nil
}, func(_ context.Context, ts *types.TipSet) error {
t.Fatal("revert on timeout")
@ -839,14 +841,14 @@ func TestCalledOrder(t *testing.T) {
err = events.Called(func(ts *types.TipSet) (d bool, m bool, e error) {
return false, true, nil
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH uint64) (bool, error) {
}, func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (bool, error) {
switch at {
case 0:
require.Equal(t, uint64(1), msg.Nonce)
require.Equal(t, uint64(4), ts.Height())
require.Equal(t, abi.ChainEpoch(4), ts.Height())
case 1:
require.Equal(t, uint64(2), msg.Nonce)
require.Equal(t, uint64(5), ts.Height())
require.Equal(t, abi.ChainEpoch(5), ts.Height())
default:
t.Fatal("apply should only get called twice, at: ", at)
}
@ -855,9 +857,9 @@ func TestCalledOrder(t *testing.T) {
}, func(_ context.Context, ts *types.TipSet) error {
switch at {
case 2:
require.Equal(t, uint64(5), ts.Height())
require.Equal(t, abi.ChainEpoch(5), ts.Height())
case 3:
require.Equal(t, uint64(4), ts.Height())
require.Equal(t, abi.ChainEpoch(4), ts.Height())
default:
t.Fatal("revert should only get called twice, at: ", at)
}

View File

@ -4,6 +4,7 @@ import (
"context"
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-address"
@ -11,12 +12,12 @@ import (
)
func TestTsCache(t *testing.T) {
tsc := newTSCache(50, func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) {
tsc := newTSCache(50, func(context.Context, abi.ChainEpoch, *types.TipSet) (*types.TipSet, error) {
t.Fatal("storage call")
return &types.TipSet{}, nil
})
h := uint64(75)
h := abi.ChainEpoch(75)
a, _ := address.NewFromString("t00")
@ -54,12 +55,12 @@ func TestTsCache(t *testing.T) {
}
func TestTsCacheNulls(t *testing.T) {
tsc := newTSCache(50, func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) {
tsc := newTSCache(50, func(context.Context, abi.ChainEpoch, *types.TipSet) (*types.TipSet, error) {
t.Fatal("storage call")
return &types.TipSet{}, nil
})
h := uint64(75)
h := abi.ChainEpoch(75)
a, _ := address.NewFromString("t00")
add := func() {

View File

@ -3,11 +3,13 @@ package gen
import (
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/build"
)
func init() {
build.SectorSizes = []uint64{1024}
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
}

View File

@ -7,6 +7,8 @@ import (
"testing"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
@ -26,7 +28,7 @@ import (
)
func init() {
build.SectorSizes = []uint64{1024}
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
}
@ -154,7 +156,7 @@ func TestForkHeightTriggers(t *testing.T) {
}
inv.Register(actcid, &testActor{}, &testActorState{})
sm.SetVMConstructor(func(c cid.Cid, h uint64, r vm.Rand, a address.Address, b blockstore.Blockstore, s *types.VMSyscalls) (*vm.VM, error) {
sm.SetVMConstructor(func(c cid.Cid, h abi.ChainEpoch, r vm.Rand, a address.Address, b blockstore.Blockstore, s *types.VMSyscalls) (*vm.VM, error) {
nvm, err := vm.NewVM(c, h, r, a, b, s)
if err != nil {
return nil, err

View File

@ -9,11 +9,12 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/specs-actors/actors/abi"
blockstore "github.com/ipfs/go-ipfs-blockstore"
)
func init() {
build.SectorSizes = []uint64{1024}
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
}

View File

@ -7,6 +7,7 @@ import (
"testing"
"time"
"github.com/filecoin-project/specs-actors/actors/abi"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
@ -27,7 +28,7 @@ import (
func init() {
build.InsecurePoStValidation = true
os.Setenv("TRUST_PARAMS", "1")
build.SectorSizes = []uint64{1024}
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
}
@ -398,7 +399,7 @@ func TestSyncBadTimestamp(t *testing.T) {
tu.waitUntilSync(0, client)
base := tu.g.CurTipset
tu.g.Timestamper = func(pts *types.TipSet, tl uint64) uint64 {
tu.g.Timestamper = func(pts *types.TipSet, tl abi.ChainEpoch) uint64 {
return pts.MinTimestamp() + (build.BlockDelay / 2)
}

View File

@ -67,7 +67,7 @@ func TestSizeStr(t *testing.T) {
}
for _, c := range cases {
assert.Equal(t, c.out, NewInt(c.in).SizeStr(), "input %+v, produced wrong result", c)
assert.Equal(t, c.out, SizeStr(NewInt(c.in)), "input %+v, produced wrong result", c)
}
}
@ -75,6 +75,6 @@ func TestSizeStrBig(t *testing.T) {
ZiB := big.NewInt(50000)
ZiB = ZiB.Lsh(ZiB, 70)
assert.Equal(t, "5e+04 ZiB", BigInt{Int: ZiB}.SizeStr(), "inout %+v, produced wrong result", ZiB)
assert.Equal(t, "5e+04 ZiB", SizeStr(BigInt{Int: ZiB}), "inout %+v, produced wrong result", ZiB)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
)
@ -47,7 +48,7 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types
}
var pcids []cid.Cid
var height uint64
var height abi.ChainEpoch
weight := types.NewInt(weightInc)
if parents != nil {
pcids = parents.Cids()

View File

@ -2,6 +2,9 @@ package validation
import (
"context"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder"
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
@ -33,7 +36,7 @@ func (a *Applier) ApplyMessage(eCtx *vchain.ExecutionContext, state vstate.Wrapp
if err != nil {
return vchain.MessageReceipt{}, err
}
lotusVM, err := vm.NewVM(base, eCtx.Epoch, randSrc, minerAddr, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
lotusVM, err := vm.NewVM(base, abi.ChainEpoch(eCtx.Epoch), randSrc, minerAddr, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
if err != nil {
return vchain.MessageReceipt{}, err
}

View File

@ -16,6 +16,7 @@ import (
"github.com/docker/go-units"
ffi "github.com/filecoin-project/filecoin-ffi"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
@ -32,7 +33,7 @@ import (
var log = logging.Logger("lotus-bench")
type BenchResults struct {
SectorSize uint64
SectorSize abi.SectorSize
SealingResults []SealingResult
@ -139,7 +140,7 @@ func main() {
if err != nil {
return err
}
sectorSize := uint64(sectorSizeInt)
sectorSize := abi.SectorSize(sectorSizeInt)
mds := datastore.NewMapDatastore()
cfg := &sectorbuilder.Config{
@ -155,7 +156,7 @@ func main() {
}
}
if err := paramfetch.GetParams(build.ParametersJson(), sectorSize); err != nil {
if err := paramfetch.GetParams(build.ParametersJson(), uint64(sectorSize)); err != nil {
return xerrors.Errorf("getting params: %w", err)
}
sb, err := sectorbuilder.New(cfg, mds)
@ -163,18 +164,16 @@ func main() {
return err
}
dataSize := sectorbuilder.UserBytesForSectorSize(sectorSize)
var sealTimings []SealingResult
var sealedSectors []ffi.PublicSectorInfo
numSectors := uint64(1)
for i := uint64(1); i <= numSectors && robench == ""; i++ {
numSectors := abi.SectorNumber(1)
for i := abi.SectorNumber(1); i <= numSectors && robench == ""; i++ {
start := time.Now()
log.Info("Writing piece into sector...")
r := rand.New(rand.NewSource(100 + int64(i)))
pi, err := sb.AddPiece(context.TODO(), dataSize, i, r, nil)
pi, err := sb.AddPiece(context.TODO(), abi.UnpaddedPieceSize(sectorSize), i, r, nil)
if err != nil {
return err
}
@ -197,7 +196,7 @@ func main() {
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{
CommR: pco.CommR,
SectorID: i,
SectorID: uint64(i),
})
seed := sectorbuilder.SealSeed{
@ -225,7 +224,7 @@ func main() {
if !c.Bool("skip-unseal") {
log.Info("Unsealing sector")
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, dataSize, ticket.TicketBytes[:], commD[:])
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, uint64(sectorSize), ticket.TicketBytes[:], commD[:])
if err != nil {
return err
}
@ -273,14 +272,14 @@ func main() {
for _, s := range genm.Sectors {
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{
CommR: s.CommR,
SectorID: s.SectorID,
SectorID: uint64(s.SectorID),
})
}
}
log.Info("generating election post candidates")
sinfos := sectorbuilder.NewSortedPublicSectorInfo(sealedSectors)
candidates, err := sb.GenerateEPostCandidates(sinfos, challenge, []uint64{})
candidates, err := sb.GenerateEPostCandidates(sinfos, challenge, []abi.SectorNumber{})
if err != nil {
return err
}
@ -355,7 +354,7 @@ func main() {
fmt.Printf("unseal: %s (%s)\n", bo.SealingResults[0].Unseal, bps(bo.SectorSize, bo.SealingResults[0].Unseal))
}
}
fmt.Printf("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*uint64(len(bo.SealingResults)), bo.PostGenerateCandidates))
fmt.Printf("generate candidates: %s (%s)\n", bo.PostGenerateCandidates, bps(bo.SectorSize*abi.SectorSize(len(bo.SealingResults)), bo.PostGenerateCandidates))
fmt.Printf("compute epost proof (cold): %s\n", bo.PostEProofCold)
fmt.Printf("compute epost proof (hot): %s\n", bo.PostEProofHot)
fmt.Printf("verify epost proof (cold): %s\n", bo.VerifyEPostCold)
@ -371,9 +370,9 @@ func main() {
}
}
func bps(data uint64, d time.Duration) string {
bdata := new(big.Int).SetUint64(data)
func bps(data abi.SectorSize, d time.Duration) string {
bdata := new(big.Int).SetUint64(uint64(data))
bdata = bdata.Mul(bdata, big.NewInt(time.Second.Nanoseconds()))
bps := bdata.Div(bdata, big.NewInt(d.Nanoseconds()))
return (types.BigInt{bps}).SizeStr() + "/s"
return types.SizeStr(types.BigInt{bps}) + "/s"
}

View File

@ -2,7 +2,6 @@ package main
import (
"database/sql"
"encoding/hex"
"fmt"
"sync"
"time"
@ -13,7 +12,6 @@ import (
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
)
@ -267,8 +265,8 @@ create table if not exists deals
pieceSize bigint not null,
client text not null,
provider text not null,
expiration decimal not null,
duration decimal not null,
start decimal not null,
end decimal not null,
epochPrice decimal not null,
collateral decimal not null,
constraint deals_pk
@ -842,7 +840,7 @@ func (st *storage) storeMpoolInclusions(msgs []api.MpoolUpdate) error {
return tx.Commit()
}
func (st *storage) storeDeals(deals map[string]actors.OnChainDeal) error {
func (st *storage) storeDeals(deals map[string]api.MarketDeal) error {
tx, err := st.db.Begin()
if err != nil {
return err
@ -854,7 +852,7 @@ func (st *storage) storeDeals(deals map[string]actors.OnChainDeal) error {
return xerrors.Errorf("prep temp: %w", err)
}
stmt, err := tx.Prepare(`copy d (id, pieceref, piecesize, client, "provider", expiration, duration, epochprice, collateral) from stdin `)
stmt, err := tx.Prepare(`copy d (id, pieceref, piecesize, client, "provider", "start", "end", epochprice, collateral) from stdin `)
if err != nil {
return err
}
@ -862,20 +860,20 @@ func (st *storage) storeDeals(deals map[string]actors.OnChainDeal) error {
var bloat uint64
for id, deal := range deals {
if len(deal.PieceRef) > 40 {
bloat += uint64(len(deal.PieceRef))
if len(deal.Proposal.PieceCID.String()) > 100 {
bloat += uint64(len(deal.Proposal.PieceCID.String()))
continue
}
if _, err := stmt.Exec(
id,
hex.EncodeToString(deal.PieceRef),
deal.PieceSize,
deal.Client.String(),
deal.Provider.String(),
fmt.Sprint(deal.ProposalExpiration),
fmt.Sprint(deal.Duration),
deal.StoragePricePerEpoch.String(),
deal.StorageCollateral.String(),
deal.Proposal.PieceCID.String(),
deal.Proposal.PieceSize,
deal.Proposal.Client.String(),
deal.Proposal.Provider.String(),
fmt.Sprint(deal.Proposal.StartEpoch),
fmt.Sprint(deal.Proposal.EndEpoch),
deal.Proposal.StoragePricePerEpoch.String(),
deal.Proposal.ProviderCollateral.String(),
); err != nil {
return err
}
@ -915,12 +913,12 @@ func (st *storage) storeDeals(deals map[string]actors.OnChainDeal) error {
}
for id, deal := range deals {
if deal.ActivationEpoch == 0 {
if deal.State.SectorStartEpoch <= 0 {
continue
}
if _, err := stmt.Exec(
id,
deal.ActivationEpoch,
deal.State.SectorStartEpoch,
); err != nil {
return err
}

View File

@ -9,6 +9,8 @@ import (
"sync"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
actors2 "github.com/filecoin-project/lotus/chain/actors"
"github.com/ipfs/go-cid"
@ -114,7 +116,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
}
for len(allToSync) > 0 {
minH := uint64(math.MaxUint64)
minH := abi.ChainEpoch(math.MaxInt64)
for _, header := range allToSync {
if header.Height < minH {

View File

@ -10,6 +10,7 @@ import (
"time"
rice "github.com/GeertJohan/go.rice"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-peer"
@ -263,7 +264,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
Owner: owner,
Worker: owner,
SectorSize: uint64(ssize),
SectorSize: abi.SectorSize(ssize),
PeerID: peer.ID("SETME"),
})
if err != nil {

View File

@ -6,6 +6,8 @@ import (
"os"
"path/filepath"
"github.com/filecoin-project/specs-actors/actors/abi"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/ipfs/go-datastore"
@ -66,7 +68,7 @@ var preSealCmd = &cli.Command{
},
&cli.Uint64Flag{
Name: "sector-size",
Value: build.SectorSizes[0],
Value: uint64(build.SectorSizes[0]),
Usage: "specify size of sectors to pre-seal",
},
&cli.StringFlag{
@ -97,7 +99,7 @@ var preSealCmd = &cli.Command{
return err
}
gm, err := seed.PreSeal(maddr, c.Uint64("sector-size"), c.Uint64("sector-offset"), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")))
gm, err := seed.PreSeal(maddr, abi.SectorSize(c.Uint64("sector-size")), c.Uint64("sector-offset"), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")))
if err != nil {
return err
}
@ -192,7 +194,7 @@ var aggregateSectorDirsCmd = &cli.Command{
}
defer agmds.Close()
ssize := cctx.Uint64("sector-size")
ssize := abi.SectorSize(cctx.Uint64("sector-size"))
agsb, err := sectorbuilder.New(&sectorbuilder.Config{
Miner: maddr,
@ -205,7 +207,7 @@ var aggregateSectorDirsCmd = &cli.Command{
}
var aggrGenMiner genesis.GenesisMiner
var highestSectorID uint64
var highestSectorID abi.SectorNumber
for _, dir := range cctx.Args().Slice() {
dir, err := homedir.Expand(dir)
if err != nil {

View File

@ -94,15 +94,12 @@ func main() {
actors.ArbitrateConsensusFaultParams{},
actors.PledgeCollateralParams{},
actors.MinerSlashConsensusFault{},
actors.StorageParticipantBalance{},
actors.StorageMarketState{},
actors.WithdrawBalanceParams{},
actors.StorageDealProposal{},
actors.PublishStorageDealsParams{},
actors.PublishStorageDealResponse{},
actors.ActivateStorageDealsParams{},
actors.ProcessStorageDealsPaymentParams{},
actors.OnChainDeal{},
actors.ComputeDataCommitmentParams{},
actors.SectorProveCommitInfo{},
actors.CheckMinerParams{},

View File

@ -13,6 +13,7 @@ import (
"github.com/filecoin-project/go-address"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
badger "github.com/ipfs/go-ds-badger2"
@ -43,7 +44,7 @@ import (
func init() {
_ = logging.SetLogLevel("*", "INFO")
build.SectorSizes = []uint64{1024}
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
}

View File

@ -4,7 +4,8 @@ import (
"math"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
@ -12,7 +13,7 @@ import (
"github.com/filecoin-project/lotus/genesis"
)
func PreSeal(ssize uint64, maddr address.Address, sectors int) (*genesis.GenesisMiner, error) {
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.GenesisMiner, error) {
k, err := wallet.GenerateKey(types.KTBLS)
if err != nil {
return nil, err
@ -28,21 +29,20 @@ func PreSeal(ssize uint64, maddr address.Address, sectors int) (*genesis.Genesis
for i := range genm.Sectors {
preseal := &genesis.PreSeal{}
sdata := randB(sectorbuilder.UserBytesForSectorSize(ssize))
sdata := randB(uint64(abi.PaddedPieceSize(ssize).Unpadded()))
preseal.CommD = commD(sdata)
preseal.CommR = commDR(preseal.CommD[:])
preseal.SectorID = uint64(i + 1)
preseal.SectorID = abi.SectorNumber(i + 1)
preseal.Deal = actors.StorageDealProposal{
PieceRef: preseal.CommD[:],
PieceSize: sectorbuilder.UserBytesForSectorSize(ssize),
PieceCID: commcid.PieceCommitmentV1ToCID(preseal.CommD[:]),
PieceSize: abi.PaddedPieceSize(ssize),
Client: maddr,
Provider: maddr,
ProposalExpiration: math.MaxUint64,
Duration: math.MaxUint64,
StartEpoch: 1,
EndEpoch: math.MaxInt64,
StoragePricePerEpoch: types.NewInt(0),
StorageCollateral: types.NewInt(0),
ProposerSignature: nil,
ProviderCollateral: types.NewInt(0),
}
genm.Sectors[i] = preseal

View File

@ -14,13 +14,14 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors"
)
type SBMock struct {
sectors map[uint64]*sectorState
sectorSize uint64
nextSectorID uint64
sectors map[abi.SectorNumber]*sectorState
sectorSize abi.SectorSize
nextSectorID abi.SectorNumber
rateLimit chan struct{}
lk sync.Mutex
@ -28,9 +29,9 @@ type SBMock struct {
type mockVerif struct{}
func NewMockSectorBuilder(threads int, ssize uint64) *SBMock {
func NewMockSectorBuilder(threads int, ssize abi.SectorSize) *SBMock {
return &SBMock{
sectors: make(map[uint64]*sectorState),
sectors: make(map[abi.SectorNumber]*sectorState),
sectorSize: ssize,
nextSectorID: 5,
rateLimit: make(chan struct{}, threads),
@ -61,7 +62,7 @@ func (sb *SBMock) RateLimit() func() {
}
}
func (sb *SBMock) AddPiece(ctx context.Context, size uint64, sectorId uint64, r io.Reader, existingPieces []uint64) (sectorbuilder.PublicPieceInfo, error) {
func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (sectorbuilder.PublicPieceInfo, error) {
sb.lk.Lock()
ss, ok := sb.sectors[sectorId]
if !ok {
@ -81,16 +82,16 @@ func (sb *SBMock) AddPiece(ctx context.Context, size uint64, sectorId uint64, r
ss.pieces = append(ss.pieces, b)
return sectorbuilder.PublicPieceInfo{
Size: size,
Size: uint64(size),
CommP: commD(b),
}, nil
}
func (sb *SBMock) SectorSize() uint64 {
func (sb *SBMock) SectorSize() abi.SectorSize {
return sb.sectorSize
}
func (sb *SBMock) AcquireSectorId() (uint64, error) {
func (sb *SBMock) AcquireSectorId() (abi.SectorNumber, error) {
sb.lk.Lock()
defer sb.lk.Unlock()
id := sb.nextSectorID
@ -100,7 +101,7 @@ func (sb *SBMock) AcquireSectorId() (uint64, error) {
func (sb *SBMock) Scrub(sectorbuilder.SortedPublicSectorInfo) []*sectorbuilder.Fault {
sb.lk.Lock()
mcopy := make(map[uint64]*sectorState)
mcopy := make(map[abi.SectorNumber]*sectorState)
for k, v := range sb.sectors {
mcopy[k] = v
}
@ -111,7 +112,7 @@ func (sb *SBMock) Scrub(sectorbuilder.SortedPublicSectorInfo) []*sectorbuilder.F
ss.lk.Lock()
if ss.failed {
out = append(out, &sectorbuilder.Fault{
SectorID: sid,
SectorID: uint64(sid),
Err: fmt.Errorf("mock sector failed"),
})
@ -122,11 +123,11 @@ func (sb *SBMock) Scrub(sectorbuilder.SortedPublicSectorInfo) []*sectorbuilder.F
return out
}
func (sb *SBMock) GenerateFallbackPoSt(sectorbuilder.SortedPublicSectorInfo, [sectorbuilder.CommLen]byte, []uint64) ([]sectorbuilder.EPostCandidate, []byte, error) {
func (sb *SBMock) GenerateFallbackPoSt(sectorbuilder.SortedPublicSectorInfo, [sectorbuilder.CommLen]byte, []abi.SectorNumber) ([]sectorbuilder.EPostCandidate, []byte, error) {
panic("NYI")
}
func (sb *SBMock) SealPreCommit(ctx context.Context, sid uint64, ticket sectorbuilder.SealTicket, pieces []sectorbuilder.PublicPieceInfo) (sectorbuilder.RawSealPreCommitOutput, error) {
func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket sectorbuilder.SealTicket, pieces []sectorbuilder.PublicPieceInfo) (sectorbuilder.RawSealPreCommitOutput, error) {
sb.lk.Lock()
ss, ok := sb.sectors[sid]
sb.lk.Unlock()
@ -137,13 +138,13 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid uint64, ticket sectorbu
ss.lk.Lock()
defer ss.lk.Unlock()
ussize := sectorbuilder.UserBytesForSectorSize(sb.sectorSize)
ussize := abi.UnpaddedPieceSize(sb.sectorSize)
// TODO: verify pieces in sinfo.pieces match passed in pieces
var sum uint64
var sum abi.UnpaddedPieceSize
for _, p := range pieces {
sum += p.Size
sum += abi.UnpaddedPieceSize(p.Size)
}
if sum != ussize {
@ -166,7 +167,7 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid uint64, ticket sectorbu
}
}
commd, err := MockVerifier.GenerateDataCommitment(sb.sectorSize, pis)
commd, err := MockVerifier.GenerateDataCommitment(abi.PaddedPieceSize(sb.sectorSize), pis)
if err != nil {
return sectorbuilder.RawSealPreCommitOutput{}, err
}
@ -177,7 +178,7 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid uint64, ticket sectorbu
}, nil
}
func (sb *SBMock) SealCommit(ctx context.Context, sid uint64, ticket sectorbuilder.SealTicket, seed sectorbuilder.SealSeed, pieces []sectorbuilder.PublicPieceInfo, precommit sectorbuilder.RawSealPreCommitOutput) ([]byte, error) {
func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket sectorbuilder.SealTicket, seed sectorbuilder.SealSeed, pieces []sectorbuilder.PublicPieceInfo, precommit sectorbuilder.RawSealPreCommitOutput) ([]byte, error) {
sb.lk.Lock()
ss, ok := sb.sectors[sid]
sb.lk.Unlock()
@ -208,7 +209,7 @@ func (sb *SBMock) GetPath(string, string) (string, error) {
panic("nyi")
}
func (sb *SBMock) CanCommit(sectorID uint64) (bool, error) {
func (sb *SBMock) CanCommit(sectorID abi.SectorNumber) (bool, error) {
return true, nil
}
@ -226,7 +227,7 @@ func (sb *SBMock) TaskDone(context.Context, uint64, sectorbuilder.SealRes) error
// Test Instrumentation Methods
func (sb *SBMock) FailSector(sid uint64) error {
func (sb *SBMock) FailSector(sid abi.SectorNumber) error {
sb.lk.Lock()
defer sb.lk.Unlock()
ss, ok := sb.sectors[sid]
@ -258,7 +259,7 @@ func (sb *SBMock) ComputeElectionPoSt(sectorInfo sectorbuilder.SortedPublicSecto
panic("implement me")
}
func (sb *SBMock) GenerateEPostCandidates(sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed [sectorbuilder.CommLen]byte, faults []uint64) ([]sectorbuilder.EPostCandidate, error) {
func (sb *SBMock) GenerateEPostCandidates(sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed [sectorbuilder.CommLen]byte, faults []abi.SectorNumber) ([]sectorbuilder.EPostCandidate, error) {
if len(faults) > 0 {
panic("todo")
}
@ -285,15 +286,15 @@ func (sb *SBMock) GenerateEPostCandidates(sectorInfo sectorbuilder.SortedPublicS
return out, nil
}
func (sb *SBMock) ReadPieceFromSealedSector(ctx context.Context, sectorID uint64, offset uint64, size uint64, ticket []byte, commD []byte) (io.ReadCloser, error) {
func (sb *SBMock) ReadPieceFromSealedSector(ctx context.Context, sectorID abi.SectorNumber, offset uint64, size uint64, ticket []byte, commD []byte) (io.ReadCloser, error) {
if len(sb.sectors[sectorID].pieces) > 1 {
panic("implme")
}
return ioutil.NopCloser(io.LimitReader(bytes.NewReader(sb.sectors[sectorID].pieces[0][offset:]), int64(size))), nil
}
func (sb *SBMock) StageFakeData() (uint64, []sectorbuilder.PublicPieceInfo, error) {
usize := sectorbuilder.UserBytesForSectorSize(sb.sectorSize)
func (sb *SBMock) StageFakeData() (abi.SectorNumber, []sectorbuilder.PublicPieceInfo, error) {
usize := abi.UnpaddedPieceSize(sb.sectorSize)
sid, err := sb.AcquireSectorId()
if err != nil {
return 0, nil, err
@ -310,19 +311,19 @@ func (sb *SBMock) StageFakeData() (uint64, []sectorbuilder.PublicPieceInfo, erro
return sid, []sectorbuilder.PublicPieceInfo{pi}, nil
}
func (sb *SBMock) FinalizeSector(context.Context, uint64) error {
func (sb *SBMock) FinalizeSector(context.Context, abi.SectorNumber) error {
return nil
}
func (sb *SBMock) DropStaged(context.Context, uint64) error {
func (sb *SBMock) DropStaged(context.Context, abi.SectorNumber) error {
return nil
}
func (sb *SBMock) SectorPath(typ fs.DataType, sectorID uint64) (fs.SectorPath, error) {
func (sb *SBMock) SectorPath(typ fs.DataType, sectorID abi.SectorNumber) (fs.SectorPath, error) {
panic("implement me")
}
func (sb *SBMock) AllocSectorPath(typ fs.DataType, sectorID uint64, cache bool) (fs.SectorPath, error) {
func (sb *SBMock) AllocSectorPath(typ fs.DataType, sectorID abi.SectorNumber, cache bool) (fs.SectorPath, error) {
panic("implement me")
}
@ -330,15 +331,15 @@ func (sb *SBMock) ReleaseSector(fs.DataType, fs.SectorPath) {
panic("implement me")
}
func (m mockVerif) VerifyElectionPost(ctx context.Context, sectorSize uint64, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address) (bool, error) {
func (m mockVerif) VerifyElectionPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address) (bool, error) {
panic("implement me")
}
func (m mockVerif) VerifyFallbackPost(ctx context.Context, sectorSize uint64, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address, faults uint64) (bool, error) {
func (m mockVerif) VerifyFallbackPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address, faults uint64) (bool, error) {
panic("implement me")
}
func (m mockVerif) VerifySeal(sectorSize uint64, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID uint64, proof []byte) (bool, error) {
func (m mockVerif) VerifySeal(sectorSize abi.SectorSize, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID abi.SectorNumber, proof []byte) (bool, error) {
if len(proof) != 32 { // Real ones are longer, but this should be fine
return false, nil
}
@ -352,11 +353,11 @@ func (m mockVerif) VerifySeal(sectorSize uint64, commR, commD []byte, proverID a
return true, nil
}
func (m mockVerif) GenerateDataCommitment(ssize uint64, pieces []ffi.PublicPieceInfo) ([sectorbuilder.CommLen]byte, error) {
func (m mockVerif) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ffi.PublicPieceInfo) ([sectorbuilder.CommLen]byte, error) {
if len(pieces) != 1 {
panic("todo")
}
if pieces[0].Size != sectorbuilder.UserBytesForSectorSize(ssize) {
if pieces[0].Size != uint64(ssize) {
panic("todo")
}
return pieces[0].CommP, nil

View File

@ -6,6 +6,8 @@ import (
"io"
"io/ioutil"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder"
)
@ -26,7 +28,7 @@ func commDR(in []byte) (out [32]byte) {
}
func commD(b []byte) [32]byte {
c, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(b), uint64(len(b)))
c, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(b), abi.UnpaddedPieceSize(len(b)))
if err != nil {
panic(err)
}

View File

@ -1,20 +1,21 @@
package sealing
import (
"github.com/filecoin-project/lotus/storage/sbmock"
"testing"
"github.com/stretchr/testify/assert"
"github.com/filecoin-project/specs-actors/actors/abi"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/storage/sbmock"
"github.com/stretchr/testify/assert"
)
func testFill(t *testing.T, n uint64, exp []uint64) {
func testFill(t *testing.T, n abi.UnpaddedPieceSize, exp []abi.UnpaddedPieceSize) {
f, err := fillersFromRem(n)
assert.NoError(t, err)
assert.Equal(t, exp, f)
var sum uint64
var sum abi.UnpaddedPieceSize
for _, u := range f {
sum += u
}
@ -24,39 +25,39 @@ func testFill(t *testing.T, n uint64, exp []uint64) {
func TestFillersFromRem(t *testing.T) {
for i := 8; i < 32; i++ {
// single
ub := sectorbuilder.UserBytesForSectorSize(uint64(1) << i)
testFill(t, ub, []uint64{ub})
ub := abi.PaddedPieceSize(uint64(1) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub})
// 2
ub = sectorbuilder.UserBytesForSectorSize(uint64(5) << i)
ub1 := sectorbuilder.UserBytesForSectorSize(uint64(1) << i)
ub3 := sectorbuilder.UserBytesForSectorSize(uint64(4) << i)
testFill(t, ub, []uint64{ub1, ub3})
ub = abi.PaddedPieceSize(uint64(5) << i).Unpadded()
ub1 := abi.PaddedPieceSize(uint64(1) << i).Unpadded()
ub3 := abi.PaddedPieceSize(uint64(4) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub3})
// 4
ub = sectorbuilder.UserBytesForSectorSize(uint64(15) << i)
ub2 := sectorbuilder.UserBytesForSectorSize(uint64(2) << i)
ub4 := sectorbuilder.UserBytesForSectorSize(uint64(8) << i)
testFill(t, ub, []uint64{ub1, ub2, ub3, ub4})
ub = abi.PaddedPieceSize(uint64(15) << i).Unpadded()
ub2 := abi.PaddedPieceSize(uint64(2) << i).Unpadded()
ub4 := abi.PaddedPieceSize(uint64(8) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub2, ub3, ub4})
// different 2
ub = sectorbuilder.UserBytesForSectorSize(uint64(9) << i)
testFill(t, ub, []uint64{ub1, ub4})
ub = abi.PaddedPieceSize(uint64(9) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
}
}
func TestFastPledge(t *testing.T) {
sz := uint64(16 << 20)
sz := abi.PaddedPieceSize(16 << 20)
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, sz)}
if _, err := s.fastPledgeCommitment(sectorbuilder.UserBytesForSectorSize(sz), 5); err != nil {
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 5); err != nil {
t.Fatalf("%+v", err)
}
sz = uint64(1024)
sz = abi.PaddedPieceSize(1024)
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, sz)}
if _, err := s.fastPledgeCommitment(sectorbuilder.UserBytesForSectorSize(sz), 64); err != nil {
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 64); err != nil {
t.Fatalf("%+v", err)
}
}

View File

@ -6,6 +6,7 @@ import (
"os"
"time"
"github.com/filecoin-project/specs-actors/actors/abi"
logging "github.com/ipfs/go-log/v2"
)
@ -66,7 +67,7 @@ func main() {
log.Fatal(err)
}
tipsetsCh, err := GetTips(ctx, api, uint64(height))
tipsetsCh, err := GetTips(ctx, api, abi.ChainEpoch(height))
if err != nil {
log.Fatal(err)
}

View File

@ -5,6 +5,7 @@ import (
"net/http"
"time"
"github.com/filecoin-project/specs-actors/actors/abi"
manet "github.com/multiformats/go-multiaddr-net"
"golang.org/x/xerrors"
@ -120,7 +121,7 @@ sync_complete:
}
}
func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *types.TipSet, error) {
func GetTips(ctx context.Context, api api.FullNode, lastHeight abi.ChainEpoch) (<-chan *types.TipSet, error) {
chmain := make(chan *types.TipSet)
notif, err := api.ChainNotify(ctx)
@ -175,7 +176,7 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *
return chmain, nil
}
func loadTipsets(ctx context.Context, api api.FullNode, curr *types.TipSet, lowestHeight uint64) ([]*types.TipSet, error) {
func loadTipsets(ctx context.Context, api api.FullNode, curr *types.TipSet, lowestHeight abi.ChainEpoch) ([]*types.TipSet, error) {
tipsets := []*types.TipSet{}
for {
if curr.Height() == 0 {