more fixes for random garbage
This commit is contained in:
parent
767392332e
commit
6c12068fb7
@ -127,8 +127,8 @@ type SectorInfo struct {
|
||||
CommR []byte
|
||||
Proof []byte
|
||||
Deals []abi.DealID
|
||||
Ticket sectorbuilder.SealTicket
|
||||
Seed sectorbuilder.SealSeed
|
||||
Ticket abi.SealRandomness
|
||||
Seed abi.Randomness
|
||||
Retries uint64
|
||||
|
||||
LastErr string
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"math/rand"
|
||||
|
||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
|
||||
@ -202,7 +201,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
newSectorInfo := &miner.SectorOnChainInfo{
|
||||
Info: miner.SectorPreCommitInfo{
|
||||
SectorNumber: preseal.SectorID,
|
||||
SealedCID: commcid.ReplicaCommitmentV1ToCID(preseal.CommR[:]),
|
||||
SealedCID: preseal.CommR,
|
||||
SealRandEpoch: 0,
|
||||
DealIDs: []abi.DealID{dealIDs[pi]},
|
||||
Expiration: preseal.Deal.EndEpoch,
|
||||
|
@ -2,6 +2,7 @@ package stmgr
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
|
||||
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||
@ -16,10 +17,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
|
||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
@ -155,13 +152,13 @@ func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet,
|
||||
return LoadSectorsFromSet(ctx, sm.ChainStore().Blockstore(), mas.Sectors)
|
||||
}
|
||||
|
||||
func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*sectorbuilder.SortedPublicSectorInfo, error) {
|
||||
func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorInfo, error) {
|
||||
sectors, err := GetMinerProvingSet(ctx, sm, ts, maddr)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get sector set for miner: %w", err)
|
||||
}
|
||||
|
||||
var uselessOtherArray []ffi.PublicSectorInfo
|
||||
var uselessOtherArray []abi.SectorInfo
|
||||
for _, s := range sectors {
|
||||
cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID)
|
||||
if err != nil {
|
||||
@ -169,14 +166,14 @@ func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.
|
||||
}
|
||||
var uselessBuffer [32]byte
|
||||
copy(uselessBuffer[:], cr)
|
||||
uselessOtherArray = append(uselessOtherArray, ffi.PublicSectorInfo{
|
||||
SectorNum: s.ID,
|
||||
CommR: uselessBuffer,
|
||||
uselessOtherArray = append(uselessOtherArray, abi.SectorInfo{
|
||||
RegisteredProof: s.Info.Info.RegisteredProof,
|
||||
SectorNumber: s.ID,
|
||||
SealedCID: s.Info.Info.SealedCID,
|
||||
})
|
||||
}
|
||||
|
||||
ssi := sectorbuilder.NewSortedPublicSectorInfo(uselessOtherArray)
|
||||
return &ssi, nil
|
||||
return uselessOtherArray, nil
|
||||
}
|
||||
|
||||
func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (abi.SectorSize, error) {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
|
||||
@ -64,6 +65,6 @@ type vmRand struct {
|
||||
eCtx *vchain.ExecutionContext
|
||||
}
|
||||
|
||||
func (*vmRand) GetRandomness(ctx context.Context, h int64) ([]byte, error) {
|
||||
func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h int64, input []byte) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"math/bits"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
"github.com/filecoin-project/lotus/lib/zerocomm"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
@ -31,12 +30,17 @@ type syscallShim struct {
|
||||
verifier sectorbuilder.Verifier
|
||||
}
|
||||
|
||||
func (ss *syscallShim) ComputeUnsealedSectorCID(ssize abi.SectorSize, pieces []abi.PieceInfo) (cid.Cid, error) {
|
||||
func (ss *syscallShim) ComputeUnsealedSectorCID(st abi.RegisteredProof, pieces []abi.PieceInfo) (cid.Cid, error) {
|
||||
var sum abi.PaddedPieceSize
|
||||
for _, p := range pieces {
|
||||
sum += p.Size
|
||||
}
|
||||
|
||||
ssize, err := st.SectorSize()
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
{
|
||||
// pad remaining space with 0 CommPs
|
||||
toFill := uint64(abi.PaddedPieceSize(ssize) - sum)
|
||||
@ -54,13 +58,13 @@ func (ss *syscallShim) ComputeUnsealedSectorCID(ssize abi.SectorSize, pieces []a
|
||||
}
|
||||
}
|
||||
|
||||
commd, err := sectorbuilder.GenerateDataCommitment(ssize, ffipieces)
|
||||
commd, err := sectorbuilder.GenerateUnsealedCID(st, pieces)
|
||||
if err != nil {
|
||||
log.Errorf("generate data commitment failed: %s", err)
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
return commcid.DataCommitmentV1ToCID(commd[:]), nil
|
||||
return commd, nil
|
||||
}
|
||||
|
||||
func (ss *syscallShim) HashBlake2b(data []byte) [32]byte {
|
||||
@ -106,17 +110,17 @@ func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error {
|
||||
|
||||
miner, err := address.NewIDAddress(uint64(info.Miner))
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("weirdly failed to construct address: %w", err)
|
||||
return xerrors.Errorf("weirdly failed to construct address: %w", err)
|
||||
}
|
||||
|
||||
ticket := []byte(info.Randomness)
|
||||
proof := []byte(info.OnChain.Proof)
|
||||
seed := []byte(info.InteractiveRandomness)
|
||||
|
||||
log.Infof("Werif %d r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", ssize, commR, commD, miner, ticket, seed, info.SectorID.Number, proof)
|
||||
log.Infof("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", commR, commD, miner, ticket, seed, info.SectorID.Number, proof)
|
||||
|
||||
//func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber)
|
||||
ok, err := ss.verifier.VerifySeal(ssize, commR[:], commD[:], miner, ticket, seed, info.SectorID.Number, proof)
|
||||
ok, err := ss.verifier.VerifySeal(info)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to validate PoRep: %w", err)
|
||||
}
|
||||
|
@ -119,7 +119,12 @@ var preSealCmd = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
gm, key, err := seed.PreSeal(maddr, abi.SectorSize(c.Uint64("sector-size")), abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k)
|
||||
rp, err := registeredProofFromSsize(c.Uint64("sector-size"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gm, key, err := seed.PreSeal(maddr, rp, abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -216,9 +221,20 @@ var aggregateSectorDirsCmd = &cli.Command{
|
||||
|
||||
ssize := abi.SectorSize(cctx.Uint64("sector-size"))
|
||||
|
||||
rp, err := registeredProofFromSsize(cctx.Uint64("sector-size"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sp, err := rp.RegisteredSealProof()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
agsb, err := sectorbuilder.New(§orbuilder.Config{
|
||||
Miner: maddr,
|
||||
SectorSize: ssize,
|
||||
SealProofType: sp,
|
||||
PoStProofType: rp,
|
||||
Paths: sectorbuilder.SimplePath(destdir),
|
||||
WorkerThreads: 2,
|
||||
}, namespace.Wrap(agmds, datastore.NewKey("/sectorbuilder")))
|
||||
@ -279,7 +295,8 @@ var aggregateSectorDirsCmd = &cli.Command{
|
||||
|
||||
sb, err := sectorbuilder.New(§orbuilder.Config{
|
||||
Miner: maddr,
|
||||
SectorSize: genm.SectorSize,
|
||||
SealProofType: sp,
|
||||
PoStProofType: rp,
|
||||
Paths: sectorbuilder.SimplePath(dir),
|
||||
WorkerThreads: 2,
|
||||
}, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder")))
|
||||
@ -319,3 +336,19 @@ func mergeGenMiners(a, b genesis.Miner) genesis.Miner {
|
||||
Sectors: append(a.Sectors, b.Sectors...),
|
||||
}
|
||||
}
|
||||
|
||||
func registeredProofFromSsize(ssize uint64) (abi.RegisteredProof, error) {
|
||||
// TODO: this should be provided to us by something lower down...
|
||||
switch ssize {
|
||||
case 2 << 10:
|
||||
return abi.RegisteredProof_StackedDRG2KiBPoSt, nil
|
||||
case 32 << 30:
|
||||
return abi.RegisteredProof_StackedDRG32GiBPoSt, nil
|
||||
case 8 << 20:
|
||||
return abi.RegisteredProof_StackedDRG8MiBPoSt, nil
|
||||
case 512 << 20:
|
||||
return abi.RegisteredProof_StackedDRG512MiBPoSt, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported sector size: %d", ssize)
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,21 @@ import (
|
||||
|
||||
var log = logging.Logger("preseal")
|
||||
|
||||
func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo) (*genesis.Miner, *types.KeyInfo, error) {
|
||||
func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo) (*genesis.Miner, *types.KeyInfo, error) {
|
||||
ppt, err := pt.RegisteredPoStProof()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
spt, err := pt.RegisteredSealProof()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
cfg := §orbuilder.Config{
|
||||
Miner: maddr,
|
||||
SectorSize: ssize,
|
||||
SealProofType: spt,
|
||||
PoStProofType: ppt,
|
||||
FallbackLastNum: offset,
|
||||
Paths: sectorbuilder.SimplePath(sbroot),
|
||||
WorkerThreads: 2,
|
||||
@ -57,6 +68,11 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ssize, err := pt.SectorSize()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var sealedSectors []*genesis.PreSeal
|
||||
for i := 0; i < sectors; i++ {
|
||||
sid, err := sb.AcquireSectorNumber()
|
||||
@ -70,13 +86,11 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
|
||||
}
|
||||
|
||||
trand := sha256.Sum256(preimage)
|
||||
ticket := sectorbuilder.SealTicket{
|
||||
TicketBytes: trand,
|
||||
}
|
||||
ticket := abi.SealRandomness(trand[:])
|
||||
|
||||
fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi)
|
||||
|
||||
pco, err := sb.SealPreCommit(context.TODO(), sid, ticket, []sectorbuilder.PublicPieceInfo{pi})
|
||||
scid, ucid, err := sb.SealPreCommit(context.TODO(), sid, ticket, []abi.PieceInfo{pi})
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("commit: %w", err)
|
||||
}
|
||||
@ -85,10 +99,10 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
|
||||
return nil, nil, xerrors.Errorf("trim cache: %w", err)
|
||||
}
|
||||
|
||||
log.Warn("PreCommitOutput: ", sid, pco)
|
||||
log.Warn("PreCommitOutput: ", sid, scid, ucid)
|
||||
sealedSectors = append(sealedSectors, &genesis.PreSeal{
|
||||
CommR: pco.CommR,
|
||||
CommD: pco.CommD,
|
||||
CommR: scid,
|
||||
CommD: ucid,
|
||||
SectorID: sid,
|
||||
})
|
||||
}
|
||||
@ -172,10 +186,8 @@ func commDCID(commd []byte) cid.Cid {
|
||||
|
||||
func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize abi.SectorSize) error {
|
||||
for _, sector := range m.Sectors {
|
||||
pref := make([]byte, len(sector.CommD))
|
||||
copy(pref, sector.CommD[:])
|
||||
proposal := &market.DealProposal{
|
||||
PieceCID: commDCID(pref), // just one deal so this == CommP
|
||||
PieceCID: sector.CommD,
|
||||
PieceSize: abi.PaddedPieceSize(ssize),
|
||||
Client: k.Address,
|
||||
Provider: maddr,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
|
||||
@ -17,8 +18,8 @@ const (
|
||||
)
|
||||
|
||||
type PreSeal struct {
|
||||
CommR [32]byte
|
||||
CommD [32]byte
|
||||
CommR cid.Cid
|
||||
CommD cid.Cid
|
||||
SectorID abi.SectorNumber
|
||||
Deal market.DealProposal
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -23,7 +23,7 @@ require (
|
||||
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
|
||||
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56
|
||||
github.com/filecoin-project/go-statestore v0.1.0
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226222915-a3b194d36c61
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226233922-9ed222007d11
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/google/uuid v1.1.1
|
||||
|
4
go.sum
4
go.sum
@ -143,6 +143,10 @@ github.com/filecoin-project/specs-actors v0.0.0-20200226204010-2ecdc6712206/go.m
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226222440-f5d1be727992 h1:T4BLV7JBn+0xxSzWlmMwU4tCGp2QkqcE+xXwNO0ufBo=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226222915-a3b194d36c61 h1:W5/1uYhny36b2x6Ce8awB3tF40z0Lmw7qluukRiVaVM=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226222915-a3b194d36c61/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226232338-edd04eb6eda5 h1:B1JCug32caW45wn0X0oifwhFdveLRoi0wrVkKlf7hMs=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226232338-edd04eb6eda5/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226233922-9ed222007d11 h1:IJJmTpNWYSdPPyMGP7ET3JE04jjZl7AzGiLTDcJOL04=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226233922-9ed222007d11/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0=
|
||||
|
@ -2,7 +2,6 @@ package sbmock
|
||||
|
||||
import (
|
||||
"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/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
@ -11,6 +10,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
"github.com/filecoin-project/lotus/genesis"
|
||||
"github.com/filecoin-project/lotus/lib/zerocomm"
|
||||
)
|
||||
|
||||
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
||||
@ -30,13 +30,12 @@ func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis
|
||||
|
||||
for i := range genm.Sectors {
|
||||
preseal := &genesis.PreSeal{}
|
||||
sdata := randB(uint64(abi.PaddedPieceSize(ssize).Unpadded()))
|
||||
|
||||
preseal.CommD = commDR(sdata)
|
||||
preseal.CommR = commDR(preseal.CommD[:])
|
||||
preseal.CommD = zerocomm.ForSize(abi.PaddedPieceSize(ssize).Unpadded())
|
||||
preseal.CommR = zerocomm.ForSize(abi.PaddedPieceSize(ssize).Unpadded())
|
||||
preseal.SectorID = abi.SectorNumber(i + 1)
|
||||
preseal.Deal = market.DealProposal{
|
||||
PieceCID: commcid.PieceCommitmentV1ToCID(preseal.CommD[:]),
|
||||
PieceCID: preseal.CommD,
|
||||
PieceSize: abi.PaddedPieceSize(ssize),
|
||||
Client: maddr,
|
||||
Provider: maddr,
|
||||
|
@ -81,15 +81,11 @@ func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sect
|
||||
return abi.PieceInfo{}, err
|
||||
}
|
||||
|
||||
// TODO: no idea what i'm doing here, just making a cid
|
||||
c, err := cid.NewPrefixV1(cid.DagCBOR, 0xf104).Sum(b)
|
||||
if err != nil {
|
||||
return abi.PieceInfo{}, err
|
||||
}
|
||||
c := commcid.DataCommitmentV1ToCID(b[:32]) // hax
|
||||
|
||||
ss.pieces = append(ss.pieces, c)
|
||||
return abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(size),
|
||||
Size: size.Padded(),
|
||||
PieceCID: c,
|
||||
}, nil
|
||||
}
|
||||
@ -169,7 +165,7 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
|
||||
pis := make([]abi.PieceInfo, len(ss.pieces))
|
||||
for i, piece := range ss.pieces {
|
||||
pis[i] = abi.PieceInfo{
|
||||
Size: abi.UnpaddedPieceSize(32).Padded(),
|
||||
Size: pieces[i].Size,
|
||||
PieceCID: piece,
|
||||
}
|
||||
}
|
||||
@ -183,10 +179,10 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
commr := make([]byte, 32)
|
||||
for i := range cc {
|
||||
commr[32-i] = cc[i]
|
||||
|
||||
commr[32-(i+1)] = cc[i]
|
||||
}
|
||||
|
||||
commR := commcid.DataCommitmentV1ToCID(commr)
|
||||
@ -378,6 +374,7 @@ func (m mockVerif) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ab
|
||||
panic("todo")
|
||||
}
|
||||
if pieces[0].Size != ssize {
|
||||
fmt.Println("wrong sizes? ", pieces[0].Size, ssize)
|
||||
panic("todo")
|
||||
}
|
||||
return pieces[0].PieceCID, nil
|
||||
|
@ -348,16 +348,6 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(t.CommP) > cbg.ByteArrayMaxLen {
|
||||
return xerrors.Errorf("Byte array in field t.CommP was too long")
|
||||
}
|
||||
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommP)))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write(t.CommP); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -447,10 +437,6 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
|
||||
if maj != cbg.MajByteString {
|
||||
return fmt.Errorf("expected byte array")
|
||||
}
|
||||
t.CommP = make([]byte, extra)
|
||||
if _, err := io.ReadFull(br, t.CommP); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
|
||||
@ -553,17 +539,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(t.CommD) > cbg.ByteArrayMaxLen {
|
||||
return xerrors.Errorf("Byte array in field t.CommD was too long")
|
||||
}
|
||||
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write(t.CommD); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.CommR ([]uint8) (slice)
|
||||
if len("CommR") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"CommR\" was too long")
|
||||
@ -576,17 +551,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(t.CommR) > cbg.ByteArrayMaxLen {
|
||||
return xerrors.Errorf("Byte array in field t.CommR was too long")
|
||||
}
|
||||
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := w.Write(t.CommR); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Proof ([]uint8) (slice)
|
||||
if len("Proof") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"Proof\" was too long")
|
||||
@ -622,10 +586,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.Ticket.MarshalCBOR(w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.PreCommitMessage (cid.Cid) (struct)
|
||||
if len("PreCommitMessage") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long")
|
||||
@ -875,10 +835,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
|
||||
if maj != cbg.MajByteString {
|
||||
return fmt.Errorf("expected byte array")
|
||||
}
|
||||
t.CommD = make([]byte, extra)
|
||||
if _, err := io.ReadFull(br, t.CommD); err != nil {
|
||||
return err
|
||||
}
|
||||
// t.CommR ([]uint8) (slice)
|
||||
case "CommR":
|
||||
|
||||
@ -893,10 +849,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
|
||||
if maj != cbg.MajByteString {
|
||||
return fmt.Errorf("expected byte array")
|
||||
}
|
||||
t.CommR = make([]byte, extra)
|
||||
if _, err := io.ReadFull(br, t.CommR); err != nil {
|
||||
return err
|
||||
}
|
||||
// t.Proof ([]uint8) (slice)
|
||||
case "Proof":
|
||||
|
||||
@ -920,10 +872,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
|
||||
|
||||
{
|
||||
|
||||
if err := t.Ticket.UnmarshalCBOR(br); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
// t.PreCommitMessage (cid.Cid) (struct)
|
||||
case "PreCommitMessage":
|
||||
|
@ -5,12 +5,10 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/multiformats/go-multihash"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
|
||||
@ -45,7 +43,7 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
|
||||
for i, piece := range si.Pieces {
|
||||
if piece.DealID == nil {
|
||||
exp := zerocomm.ForSize(piece.Size)
|
||||
if string(piece.CommP) != string(exp[:]) {
|
||||
if piece.CommP != exp {
|
||||
return &ErrInvalidPiece{xerrors.Errorf("deal %d piece %d had non-zero CommP %+v", piece.DealID, i, piece.CommP)}
|
||||
}
|
||||
continue
|
||||
@ -55,13 +53,8 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
|
||||
return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", piece.DealID, i, err)}
|
||||
}
|
||||
|
||||
h, err := multihash.Decode(deal.Proposal.PieceCID.Hash())
|
||||
if err != nil {
|
||||
return &ErrInvalidDeals{xerrors.Errorf("decoding piece CID: %w", err)}
|
||||
}
|
||||
|
||||
if string(h.Digest) != string(piece.CommP) {
|
||||
return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, h.Digest)}
|
||||
if deal.Proposal.PieceCID != piece.CommP {
|
||||
return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, deal.Proposal.PieceCID)}
|
||||
}
|
||||
|
||||
if piece.Size != deal.Proposal.PieceSize.Unpadded() {
|
||||
@ -84,14 +77,9 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
|
||||
return &ErrApi{xerrors.Errorf("getting chain head: %w", err)}
|
||||
}
|
||||
|
||||
ssize, err := api.StateMinerSectorSize(ctx, maddr, head.Key())
|
||||
if err != nil {
|
||||
return &ErrApi{err}
|
||||
}
|
||||
|
||||
ccparams, err := actors.SerializeParams(&market.ComputeDataCommitmentParams{
|
||||
DealIDs: si.deals(),
|
||||
SectorSize: ssize,
|
||||
SectorType: si.SectorType,
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
|
||||
@ -118,12 +106,8 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
|
||||
if err := c.UnmarshalCBOR(bytes.NewReader(r.Return)); err != nil {
|
||||
return err
|
||||
}
|
||||
cd, err := commcid.CIDToDataCommitmentV1(cid.Cid(c))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if string(cd) != string(si.CommD) {
|
||||
if cid.Cid(c) != *si.CommD {
|
||||
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)}
|
||||
}
|
||||
|
||||
|
@ -66,14 +66,16 @@ type SectorPackingFailed struct{ error }
|
||||
func (evt SectorPackingFailed) apply(*SectorInfo) {}
|
||||
|
||||
type SectorSealed struct {
|
||||
commR []byte
|
||||
commD []byte
|
||||
commR cid.Cid
|
||||
commD cid.Cid
|
||||
ticket SealTicket
|
||||
}
|
||||
|
||||
func (evt SectorSealed) apply(state *SectorInfo) {
|
||||
state.CommD = evt.commD
|
||||
state.CommR = evt.commR
|
||||
commd := evt.commD
|
||||
state.CommD = &commd
|
||||
commr := evt.commR
|
||||
state.CommR = &commr
|
||||
state.Ticket = evt.ticket
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, e
|
||||
existingPieceSizes = append(existingPieceSizes, size)
|
||||
|
||||
out[i] = Piece{
|
||||
Size: ppi.Size,
|
||||
CommP: ppi.CommP[:],
|
||||
Size: ppi.Size.Unpadded(),
|
||||
CommP: ppi.PieceCID,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ const SectorStorePrefix = "/sectors"
|
||||
|
||||
var log = logging.Logger("sectors")
|
||||
|
||||
type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error)
|
||||
type TicketFn func(context.Context) (SealTicket, error)
|
||||
|
||||
type sealingApi interface { // TODO: trim down
|
||||
// Call a read only method on actors (no interaction with the chain required)
|
||||
@ -125,8 +125,8 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
|
||||
{
|
||||
DealID: &dealID,
|
||||
|
||||
Size: ppi.Size,
|
||||
CommP: ppi.CommP[:],
|
||||
Size: ppi.Size.Unpadded(),
|
||||
CommP: ppi.PieceCID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package sealing
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-sectorbuilder/fs"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
@ -69,18 +69,15 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
|
||||
return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)})
|
||||
}
|
||||
|
||||
rspco, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, *ticket, sector.pieceInfos())
|
||||
sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.TicketBytes, sector.pieceInfos())
|
||||
if err != nil {
|
||||
return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)})
|
||||
}
|
||||
|
||||
return ctx.Send(SectorSealed{
|
||||
commD: rspco.CommD[:],
|
||||
commR: rspco.CommR[:],
|
||||
ticket: SealTicket{
|
||||
BlockHeight: abi.ChainEpoch(ticket.BlockHeight),
|
||||
TicketBytes: ticket.TicketBytes[:],
|
||||
},
|
||||
commD: unsealed,
|
||||
commR: sealed,
|
||||
ticket: ticket,
|
||||
})
|
||||
}
|
||||
|
||||
@ -104,7 +101,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
SectorNumber: sector.SectorID,
|
||||
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal,
|
||||
|
||||
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR),
|
||||
SealedCID: *sector.CommR,
|
||||
SealRandEpoch: sector.Ticket.BlockHeight,
|
||||
DealIDs: sector.deals(),
|
||||
}
|
||||
@ -161,7 +158,7 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
|
||||
|
||||
ctx.Send(SectorSeedReady{seed: SealSeed{
|
||||
BlockHeight: randHeight,
|
||||
TicketBytes: rand,
|
||||
TicketBytes: abi.InteractiveSealRandomness(rand),
|
||||
}})
|
||||
|
||||
return nil
|
||||
@ -182,7 +179,7 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo)
|
||||
|
||||
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.TicketBytes, sector.Ticket.BlockHeight, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.pieceInfos(), sector.CommR, sector.CommD)
|
||||
|
||||
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.SB(), sector.Seed.SB(), sector.pieceInfos(), sector.rspco())
|
||||
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.pieceInfos(), *sector.CommR, *sector.CommD)
|
||||
if err != nil {
|
||||
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)})
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"time"
|
||||
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
"golang.org/x/xerrors"
|
||||
@ -96,13 +95,8 @@ func (m *Sealing) handlePreCommitFailed(ctx statemachine.Context, sector SectorI
|
||||
return nil // TODO: SeedWait needs this currently
|
||||
}
|
||||
|
||||
pciR, err := commcid.CIDToReplicaCommitmentV1(pci.Info.SealedCID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if string(pciR) != string(sector.CommR) {
|
||||
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pciR, sector.CommR)
|
||||
if pci.Info.SealedCID != *sector.CommR {
|
||||
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pci.Info.SealedCID, sector.CommR)
|
||||
return nil // TODO: remove when the actor allows re-precommit
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package sealing
|
||||
|
||||
import (
|
||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -9,24 +8,12 @@ import (
|
||||
|
||||
type SealTicket struct {
|
||||
BlockHeight abi.ChainEpoch
|
||||
TicketBytes []byte
|
||||
}
|
||||
|
||||
func (t *SealTicket) SB() sectorbuilder.SealTicket {
|
||||
out := sectorbuilder.SealTicket{BlockHeight: uint64(t.BlockHeight)}
|
||||
copy(out.TicketBytes[:], t.TicketBytes)
|
||||
return out
|
||||
TicketBytes abi.SealRandomness
|
||||
}
|
||||
|
||||
type SealSeed struct {
|
||||
BlockHeight abi.ChainEpoch
|
||||
TicketBytes []byte
|
||||
}
|
||||
|
||||
func (t *SealSeed) SB() sectorbuilder.SealSeed {
|
||||
out := sectorbuilder.SealSeed{BlockHeight: uint64(t.BlockHeight)}
|
||||
copy(out.TicketBytes[:], t.TicketBytes)
|
||||
return out
|
||||
TicketBytes abi.InteractiveSealRandomness
|
||||
}
|
||||
|
||||
func (t *SealSeed) Equals(o *SealSeed) bool {
|
||||
@ -37,13 +24,7 @@ type Piece struct {
|
||||
DealID *abi.DealID
|
||||
|
||||
Size abi.UnpaddedPieceSize
|
||||
CommP []byte
|
||||
}
|
||||
|
||||
func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) {
|
||||
out.Size = p.Size
|
||||
copy(out.CommP[:], p.CommP)
|
||||
return out
|
||||
CommP cid.Cid
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
@ -61,13 +42,15 @@ type SectorInfo struct {
|
||||
SectorID abi.SectorNumber
|
||||
Nonce uint64 // TODO: remove
|
||||
|
||||
SectorType abi.RegisteredProof
|
||||
|
||||
// Packing
|
||||
|
||||
Pieces []Piece
|
||||
|
||||
// PreCommit
|
||||
CommD []byte
|
||||
CommR []byte
|
||||
CommD *cid.Cid
|
||||
CommR *cid.Cid
|
||||
Proof []byte
|
||||
Ticket SealTicket
|
||||
|
||||
@ -88,10 +71,13 @@ type SectorInfo struct {
|
||||
Log []Log
|
||||
}
|
||||
|
||||
func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo {
|
||||
out := make([]sectorbuilder.PublicPieceInfo, len(t.Pieces))
|
||||
func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
|
||||
out := make([]abi.PieceInfo, len(t.Pieces))
|
||||
for i, piece := range t.Pieces {
|
||||
out[i] = piece.ppi()
|
||||
out[i] = abi.PieceInfo{
|
||||
Size: piece.Size.Padded(),
|
||||
PieceCID: piece.CommP,
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@ -114,12 +100,3 @@ func (t *SectorInfo) existingPieces() []abi.UnpaddedPieceSize {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (t *SectorInfo) rspco() sectorbuilder.RawSealPreCommitOutput {
|
||||
var out sectorbuilder.RawSealPreCommitOutput
|
||||
|
||||
copy(out.CommD[:], t.CommD)
|
||||
copy(out.CommR[:], t.CommR)
|
||||
|
||||
return out
|
||||
}
|
||||
|
@ -5,14 +5,17 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/filecoin-project/go-cbor-util"
|
||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||
)
|
||||
|
||||
func TestSectorInfoSelialization(t *testing.T) {
|
||||
d := abi.DealID(1234)
|
||||
|
||||
dummyCid := builtin.AccountActorCodeID
|
||||
|
||||
si := &SectorInfo{
|
||||
State: 123,
|
||||
SectorID: 234,
|
||||
@ -20,9 +23,9 @@ func TestSectorInfoSelialization(t *testing.T) {
|
||||
Pieces: []Piece{{
|
||||
DealID: &d,
|
||||
Size: 5,
|
||||
CommP: []byte{3},
|
||||
CommP: dummyCid,
|
||||
}},
|
||||
CommD: []byte{32, 4},
|
||||
CommD: &dummyCid,
|
||||
CommR: nil,
|
||||
Proof: nil,
|
||||
Ticket: SealTicket{
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/storage/sbmock"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -45,19 +43,3 @@ func TestFillersFromRem(t *testing.T) {
|
||||
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastPledge(t *testing.T) {
|
||||
sz := abi.PaddedPieceSize(16 << 20)
|
||||
|
||||
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
|
||||
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 5); err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
|
||||
sz = abi.PaddedPieceSize(1024)
|
||||
|
||||
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
|
||||
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 64); err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user