make it all build finally

This commit is contained in:
whyrusleeping 2020-02-27 13:45:31 -08:00
parent 48619dc238
commit df6e3e83bf
34 changed files with 315 additions and 491 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore"
"github.com/libp2p/go-libp2p-core/peer"
xerrors "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -228,9 +229,10 @@ type PaymentInfo struct {
}
type VoucherSpec struct {
Amount types.BigInt
TimeLock abi.ChainEpoch
MinSettle abi.ChainEpoch
Amount types.BigInt
TimeLockMin abi.ChainEpoch
TimeLockMax abi.ChainEpoch
MinSettle abi.ChainEpoch
Extra *paych.ModVerifyParams
}
@ -339,3 +341,18 @@ type MpoolUpdate struct {
Type MpoolChange
Message *types.SignedMessage
}
func ProofTypeFromSectorSize(ssize abi.SectorSize) (abi.RegisteredProof, abi.RegisteredProof, error) {
switch ssize {
case 2 << 10:
return abi.RegisteredProof_StackedDRG2KiBPoSt, abi.RegisteredProof_StackedDRG2KiBSeal, nil
case 8 << 20:
return abi.RegisteredProof_StackedDRG8MiBPoSt, abi.RegisteredProof_StackedDRG8MiBSeal, nil
case 512 << 20:
return abi.RegisteredProof_StackedDRG512MiBPoSt, abi.RegisteredProof_StackedDRG512MiBSeal, nil
case 32 << 30:
return abi.RegisteredProof_StackedDRG32GiBPoSt, abi.RegisteredProof_StackedDRG32GiBSeal, nil
default:
return 0, 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize)
}
}

View File

@ -1,10 +1,12 @@
package api
import (
"bytes"
"context"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/go-sectorbuilder"
)
@ -123,12 +125,12 @@ type SectorLog struct {
type SectorInfo struct {
SectorID abi.SectorNumber
State SectorState
CommD []byte
CommR []byte
CommD *cid.Cid
CommR *cid.Cid
Proof []byte
Deals []abi.DealID
Ticket abi.SealRandomness
Seed abi.Randomness
Ticket SealTicket
Seed SealSeed
Retries uint64
LastErr string
@ -145,3 +147,21 @@ type SealedRef struct {
type SealedRefs struct {
Refs []SealedRef
}
type SealTicket struct {
Value abi.SealRandomness
Epoch abi.ChainEpoch
}
type SealSeed struct {
Value abi.InteractiveSealRandomness
Epoch abi.ChainEpoch
}
func (st *SealTicket) Equals(ost *SealTicket) bool {
return bytes.Equal(st.Value, ost.Value) && st.Epoch == ost.Epoch
}
func (st *SealSeed) Equals(ost *SealSeed) bool {
return bytes.Equal(st.Value, ost.Value) && st.Epoch == ost.Epoch
}

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"sync/atomic"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
@ -23,7 +24,6 @@ import (
logging "github.com/ipfs/go-log/v2"
"github.com/ipfs/go-merkledag"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
@ -136,7 +136,7 @@ func NewGenerator() (*ChainGen, error) {
return nil, err
}
genm1, k1, err := seed.PreSeal(maddr1, 1024, 0, 1, m1temp, []byte("some randomness"), nil)
genm1, k1, err := seed.PreSeal(maddr1, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, 1, m1temp, []byte("some randomness"), nil)
if err != nil {
return nil, err
}
@ -148,7 +148,7 @@ func NewGenerator() (*ChainGen, error) {
return nil, err
}
genm2, k2, err := seed.PreSeal(maddr2, 1024, 0, 1, m2temp, []byte("some randomness"), nil)
genm2, k2, err := seed.PreSeal(maddr2, abi.RegisteredProof_StackedDRG2KiBPoSt, 0, 1, m2temp, []byte("some randomness"), nil)
if err != nil {
return nil, err
}
@ -514,32 +514,37 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*cr
}
type ElectionPoStProver interface {
GenerateCandidates(context.Context, sectorbuilder.SortedPublicSectorInfo, []byte) ([]sectorbuilder.EPostCandidate, error)
ComputeProof(context.Context, sectorbuilder.SortedPublicSectorInfo, []byte, []sectorbuilder.EPostCandidate) ([]byte, error)
GenerateCandidates(context.Context, []abi.SectorInfo, abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error)
ComputeProof(context.Context, []abi.SectorInfo, []byte, []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error)
}
type eppProvider struct{}
func (epp *eppProvider) GenerateCandidates(ctx context.Context, _ sectorbuilder.SortedPublicSectorInfo, eprand []byte) ([]sectorbuilder.EPostCandidate, error) {
return []sectorbuilder.EPostCandidate{
func (epp *eppProvider) GenerateCandidates(ctx context.Context, _ []abi.SectorInfo, eprand abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error) {
return []ffi.PoStCandidateWithTicket{
{
SectorNum: 1,
PartialTicket: [32]byte{},
Ticket: [32]byte{},
SectorChallengeIndex: 1,
Candidate: abi.PoStCandidate{
RegisteredProof: abi.RegisteredProof_StackedDRG2KiBPoSt,
SectorID: abi.SectorID{Number: 1},
PartialTicket: abi.PartialTicket{},
PrivateProof: abi.PrivatePoStCandidateProof{},
ChallengeIndex: 1,
},
},
}, nil
}
func (epp *eppProvider) ComputeProof(ctx context.Context, _ sectorbuilder.SortedPublicSectorInfo, eprand []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) {
func (epp *eppProvider) ComputeProof(ctx context.Context, _ []abi.SectorInfo, eprand []byte, winners []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error) {
return []byte("valid proof"), nil
return []abi.PoStProof{{
ProofBytes: []byte("valid proof"),
}}, nil
}
type ProofInput struct {
sectors sectorbuilder.SortedPublicSectorInfo
sectors []abi.SectorInfo
hvrf []byte
winners []sectorbuilder.EPostCandidate
winners []ffi.PoStCandidateWithTicket
vrfout []byte
}
@ -567,23 +572,16 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
return nil, nil
}
var sinfos []ffi.PublicSectorInfo
var sinfos []abi.SectorInfo
for _, s := range pset {
cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID)
if err != nil {
return nil, xerrors.Errorf("get sealed cid: %w", err)
}
var commRa [32]byte
copy(commRa[:], cr)
sinfos = append(sinfos, ffi.PublicSectorInfo{
SectorNum: s.ID,
CommR: commRa,
sinfos = append(sinfos, abi.SectorInfo{
SectorNumber: s.ID,
SealedCID: s.Info.Info.SealedCID,
})
}
sectors := sectorbuilder.NewSortedPublicSectorInfo(sinfos)
hvrf := sha256.Sum256(vrfout)
candidates, err := epp.GenerateCandidates(ctx, sectors, hvrf[:])
candidates, err := epp.GenerateCandidates(ctx, sinfos, hvrf[:])
if err != nil {
return nil, xerrors.Errorf("failed to generate electionPoSt candidates: %w", err)
}
@ -598,9 +596,9 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
return nil, xerrors.Errorf("failed to look up miners sector size: %w", err)
}
var winners []sectorbuilder.EPostCandidate
var winners []ffi.PoStCandidateWithTicket
for _, c := range candidates {
if types.IsTicketWinner(c.PartialTicket[:], ssize, uint64(len(sinfos)), pow.TotalPower) {
if types.IsTicketWinner(c.Candidate.PartialTicket, ssize, uint64(len(sinfos)), pow.TotalPower) {
winners = append(winners, c)
}
}
@ -611,7 +609,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
}
return &ProofInput{
sectors: sectors,
sectors: sinfos,
hvrf: hvrf[:],
winners: winners,
vrfout: vrfout,
@ -625,16 +623,16 @@ func ComputeProof(ctx context.Context, epp ElectionPoStProver, pi *ProofInput) (
}
ept := types.EPostProof{
Proof: proof,
Proofs: proof,
PostRand: pi.vrfout,
}
for _, win := range pi.winners {
part := make([]byte, 32)
copy(part, win.PartialTicket[:])
copy(part, win.Candidate.PartialTicket)
ept.Candidates = append(ept.Candidates, types.EPostTicket{
Partial: part,
SectorID: win.SectorNum,
ChallengeIndex: win.SectorChallengeIndex,
SectorID: win.Candidate.SectorID.Number,
ChallengeIndex: uint64(win.Candidate.ChallengeIndex),
})
}
@ -676,17 +674,17 @@ type genFakeVerifier struct{}
var _ sectorbuilder.Verifier = (*genFakeVerifier)(nil)
func (m genFakeVerifier) VerifyElectionPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address) (bool, error) {
func (m genFakeVerifier) VerifyElectionPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("nyi")
}
func (m genFakeVerifier) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ffi.PublicPieceInfo) ([sectorbuilder.CommLen]byte, error) {
func (m genFakeVerifier) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []abi.PieceInfo) (cid.Cid, error) {
return sbmock.MockVerifier.GenerateDataCommitment(ssize, pieces)
}
func (m genFakeVerifier) VerifySeal(sectorSize abi.SectorSize, commR, commD []byte, proverID address.Address, ticket []byte, seed []byte, sectorID abi.SectorNumber, proof []byte) (bool, error) {
func (m genFakeVerifier) VerifySeal(svi abi.SealVerifyInfo) (bool, error) {
return true, nil
}
func (m genFakeVerifier) VerifyFallbackPost(ctx context.Context, sectorSize abi.SectorSize, sectorInfo sectorbuilder.SortedPublicSectorInfo, challengeSeed []byte, proof []byte, candidates []sectorbuilder.EPostCandidate, proverID address.Address, faults uint64) (bool, error) {
func (m genFakeVerifier) VerifyFallbackPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("nyi")
}

View File

@ -14,8 +14,8 @@ import (
)
func init() {
build.SectorSizes = []abi.SectorSize{1024}
build.MinimumMinerPower = 1024
build.SectorSizes = []abi.SectorSize{2048}
build.MinimumMinerPower = 2048
}
func testGeneration(t testing.TB, n int, msgs int) {

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"github.com/filecoin-project/go-amt-ipld/v2"
"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"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
@ -257,7 +258,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys runtime.Sys
Miner: builtin.InitActorAddr,
Ticket: genesisticket,
EPostProof: types.EPostProof{
Proof: []byte("not a real proof"),
Proofs: []abi.PoStProof{{ProofBytes: []byte("not a real proof")}},
PostRand: []byte("i guess this is kinda random"),
},
Parents: []cid.Cid{},

View File

@ -61,6 +61,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
var maddr address.Address
{
constructorParams := &power.CreateMinerParams{
Owner: m.Worker,
Worker: m.Worker,
SectorSize: m.SectorSize,
Peer: m.PeerId,

View File

@ -2,13 +2,14 @@ package chain
import (
"context"
"crypto/sha256"
"errors"
"fmt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"sync"
"time"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/Gurpartap/async"
amt "github.com/filecoin-project/go-amt-ipld/v2"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
@ -666,14 +667,20 @@ func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.Bloc
return xerrors.Errorf("failed to get sector size for miner: %w", err)
}
var winners []sectorbuilder.EPostCandidate
mid, err := address.IDFromAddress(h.Miner)
if err != nil {
return xerrors.Errorf("failed to get ID from miner address %s: %w", h.Miner, err)
}
var winners []abi.PoStCandidate
for _, t := range h.EPostProof.Candidates {
var partial [32]byte
copy(partial[:], t.Partial)
winners = append(winners, sectorbuilder.EPostCandidate{
PartialTicket: partial,
SectorNum: t.SectorID,
SectorChallengeIndex: t.ChallengeIndex,
winners = append(winners, abi.PoStCandidate{
PartialTicket: t.Partial,
SectorID: abi.SectorID{
Number: t.SectorID,
Miner: abi.ActorID(mid),
},
ChallengeIndex: int64(t.ChallengeIndex),
})
}
@ -687,14 +694,44 @@ func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.Bloc
}
if build.InsecurePoStValidation {
if string(h.EPostProof.Proof) == "valid proof" {
if len(h.EPostProof.Proofs) == 0 {
return xerrors.Errorf("[TESTING] No election post proof given")
}
if string(h.EPostProof.Proofs[0].ProofBytes) == "valid proof" {
return nil
}
return xerrors.Errorf("[TESTING] election post was invalid")
}
hvrf := sha256.Sum256(h.EPostProof.PostRand)
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(ctx, ssize, *sectorInfo, hvrf[:], h.EPostProof.Proof, winners, h.Miner)
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
candidates := make([]abi.PoStCandidate, 0, len(h.EPostProof.Candidates))
for _, c := range h.EPostProof.Candidates {
candidates = append(candidates, abi.PoStCandidate{
RegisteredProof: rt,
PartialTicket: c.Partial,
SectorID: abi.SectorID{Number: c.SectorID}, // this should not be an ID, we already know who the miner is...
ChallengeIndex: int64(c.ChallengeIndex),
})
}
// TODO: why do we need this here?
challengeCount := sectorbuilder.ElectionPostChallengeCount(uint64(len(sectorInfo)), 0)
pvi := abi.PoStVerifyInfo{
Randomness: h.EPostProof.PostRand,
Candidates: candidates,
Proofs: h.EPostProof.Proofs,
EligibleSectors: sectorInfo,
Prover: abi.ActorID(mid),
ChallengeCount: challengeCount,
}
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(ctx, pvi)
if err != nil {
return xerrors.Errorf("failed to verify election post: %w", err)
}

View File

@ -29,7 +29,7 @@ type EPostTicket struct {
}
type EPostProof struct {
Proof []byte
Proofs []abi.PoStProof
PostRand []byte
Candidates []EPostTicket
}

View File

@ -7,6 +7,7 @@ import (
"testing"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
cid "github.com/ipfs/go-cid"
)
@ -27,7 +28,7 @@ func testBlockHeader(t testing.TB) *BlockHeader {
return &BlockHeader{
Miner: addr,
EPostProof: EPostProof{
Proof: []byte("pruuf"),
Proofs: []abi.PoStProof{{ProofBytes: []byte("pruuf")}},
PostRand: []byte("random"),
},
Ticket: &Ticket{

View File

@ -392,16 +392,6 @@ func (t *EPostProof) MarshalCBOR(w io.Writer) error {
}
// t.Proof ([]uint8) (slice)
if len(t.Proof) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Proof was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
// t.PostRand ([]uint8) (slice)
if len(t.PostRand) > cbg.ByteArrayMaxLen {
@ -459,10 +449,6 @@ func (t *EPostProof) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
// t.PostRand ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)

View File

@ -61,7 +61,7 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types
return &types.BlockHeader{
Miner: addr,
EPostProof: types.EPostProof{
Proof: []byte("election post proof proof"),
Proofs: []abi.PoStProof{{ProofBytes: []byte("election post proof proof")}},
},
Ticket: &types.Ticket{
VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)),

View File

@ -138,8 +138,14 @@ var runCmd = &cli.Command{
return xerrors.Errorf("get params: %w", err)
}
ppt, spt, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
sb, err := sectorbuilder.NewStandalone(&sectorbuilder.Config{
SectorSize: ssize,
SealProofType: spt,
PoStProofType: ppt,
Miner: act,
WorkerThreads: workers,
Paths: sectorbuilder.SimplePath(r),

View File

@ -82,13 +82,14 @@ func (w *worker) processTask(ctx context.Context, task sectorbuilder.WorkerTask)
switch task.Type {
case sectorbuilder.WorkerPreCommit:
w.limiter.workLimit <- struct{}{}
rspco, err := w.sb.SealPreCommit(ctx, task.SectorNum, task.SealTicket, task.Pieces)
sealedCid, unsealedCid, err := w.sb.SealPreCommit(ctx, task.SectorNum, task.SealTicket, task.Pieces)
<-w.limiter.workLimit
if err != nil {
return errRes(xerrors.Errorf("precomitting: %w", err))
}
res.Rspco = rspco.ToJson()
res.Rspco.CommD = unsealedCid
res.Rspco.CommR = sealedCid
if err := w.push("sealed", task.SectorNum); err != nil {
return errRes(xerrors.Errorf("pushing precommited data: %w", err))
@ -103,7 +104,7 @@ func (w *worker) processTask(ctx context.Context, task sectorbuilder.WorkerTask)
}
case sectorbuilder.WorkerCommit:
w.limiter.workLimit <- struct{}{}
proof, err := w.sb.SealCommit(ctx, task.SectorNum, task.SealTicket, task.SealSeed, task.Pieces, task.Rspco)
proof, err := w.sb.SealCommit(ctx, task.SectorNum, task.SealTicket, task.SealSeed, task.Pieces, task.SealedCID, task.UnsealedCID)
<-w.limiter.workLimit
if err != nil {

View File

@ -5,15 +5,16 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
crypto2 "github.com/filecoin-project/specs-actors/actors/crypto"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
@ -181,8 +182,14 @@ var initCmd = &cli.Command{
return err
}
ppt, spt, err := lapi.ProofTypeFromSectorSize(ssize)
if err != nil {
return err
}
oldsb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: ssize,
SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: 2,
Paths: sectorbuilder.SimplePath(pssb),
}, namespace.Wrap(oldmds, datastore.NewKey("/sectorbuilder")))
@ -191,7 +198,8 @@ var initCmd = &cli.Command{
}
nsb, err := sectorbuilder.New(&sectorbuilder.Config{
SectorSize: ssize,
SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: 2,
Paths: sectorbuilder.SimplePath(lr.Path()),
}, namespace.Wrap(mds, datastore.NewKey("/sectorbuilder")))
@ -250,6 +258,8 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
if err != nil {
return xerrors.Errorf("finding storage deal for pre-sealed sector %d: %w", sector.SectorID, err)
}
commD := sector.CommD
commR := sector.CommR
info := &sealing.SectorInfo{
State: lapi.Proving,
@ -258,15 +268,15 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
{
DealID: &dealID,
Size: abi.PaddedPieceSize(meta.SectorSize).Unpadded(),
CommP: sector.CommD[:],
CommP: sector.CommD,
},
},
CommD: sector.CommD[:],
CommR: sector.CommR[:],
CommD: &commD,
CommR: &commR,
Proof: nil,
Ticket: sealing.SealTicket{},
Ticket: lapi.SealTicket{},
PreCommitMessage: nil,
Seed: sealing.SealSeed{},
Seed: lapi.SealSeed{},
CommitMessage: nil,
}

View File

@ -2,13 +2,14 @@ package main
import (
"fmt"
"github.com/filecoin-project/lotus/chain/types"
"os"
"sort"
"strconv"
"text/tabwriter"
"time"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
@ -78,10 +79,10 @@ var sectorsStatusCmd = &cli.Command{
fmt.Printf("Status:\t%s\n", api.SectorStates[status.State])
fmt.Printf("CommD:\t\t%x\n", status.CommD)
fmt.Printf("CommR:\t\t%x\n", status.CommR)
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.TicketBytes)
fmt.Printf("TicketH:\t\t%d\n", status.Ticket.BlockHeight)
fmt.Printf("Seed:\t\t%x\n", status.Seed.TicketBytes)
fmt.Printf("SeedH:\t\t%d\n", status.Seed.BlockHeight)
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.Value)
fmt.Printf("TicketH:\t\t%d\n", status.Ticket.Epoch)
fmt.Printf("Seed:\t\t%x\n", status.Seed.Value)
fmt.Printf("SeedH:\t\t%d\n", status.Seed.Epoch)
fmt.Printf("Proof:\t\t%x\n", status.Proof)
fmt.Printf("Deals:\t\t%v\n", status.Deals)
fmt.Printf("Retries:\t\t%d\n", status.Retries)
@ -170,8 +171,8 @@ var sectorsListCmd = &cli.Command{
api.SectorStates[st.State],
yesno(inSSet),
yesno(inPSet),
st.Ticket.BlockHeight,
st.Seed.BlockHeight,
st.Ticket.Epoch,
st.Seed.Epoch,
st.Deals,
)
}

4
go.mod
View File

@ -18,10 +18,10 @@ require (
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9
github.com/filecoin-project/go-fil-markets v0.0.0-20200227194154-8ef88c730c81
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6
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-sectorbuilder v0.0.2-0.20200227214225-a550d0267977
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/specs-actors v0.0.0-20200226233922-9ed222007d11
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1

10
go.sum
View File

@ -116,6 +116,10 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA=
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9 h1:uFS5r3K3AgIuR7cGBYY8k+vgwn/UXhin9NR2yCXVe7o=
github.com/filecoin-project/go-fil-markets v0.0.0-20200223154807-f7afd8e927f9/go.mod h1:ftsiBbjLjNLAZ52FVDigkdCp73ltdcvAzAXav6drSLA=
github.com/filecoin-project/go-fil-markets v0.0.0-20200227185910-091d5f0ab546 h1:wIrzVUX4TZ56WMbTpl9cNr/XRyTfI9RTc3GfFxUtznA=
github.com/filecoin-project/go-fil-markets v0.0.0-20200227185910-091d5f0ab546/go.mod h1:f272JjgKXzn2OxdlmVhq6CjvlX5FfV743TvWLirsDpk=
github.com/filecoin-project/go-fil-markets v0.0.0-20200227194154-8ef88c730c81 h1:3jFhWp4lC7irXg/d4Q4p3FQtw0m8hne+9GHveViCM04=
github.com/filecoin-project/go-fil-markets v0.0.0-20200227194154-8ef88c730c81/go.mod h1:rfRwhd3ujcCXnD4N9oEM2wjh8GRZGoeNXME+UPG/9ts=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE=
github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU=
@ -129,6 +133,12 @@ github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200224193134-7d37ec0f772
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200224193134-7d37ec0f7723/go.mod h1:u8n91UJUua9zEiyAPw8wRAgUEoyTH8BBM9LWJ5WuxOM=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56 h1:CqldkHf9HtAsewneyOZdi19Btc6kEvktVVeZsP9N7NQ=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200226210935-4739f8749f56/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214127-332d57b390aa h1:EVToQ5L+49psMvYP5ICsOcFRua79oDMyYQAeEqxkzwU=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214127-332d57b390aa/go.mod h1:u8n91UJUua9zEiyAPw8wRAgUEoyTH8BBM9LWJ5WuxOM=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214225-a550d0267977 h1:Q4VnMiorS/AcZMDHtoi+7lVzkTj+qDa0bmgMkwmvxIM=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214225-a550d0267977/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 h1:k9qVR9ItcziSB2rxtlkN/MDWNlbsI6yzec+zjUatLW0=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ=
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf h1:fbxBG12yrxilPFV1EG2lYqpUyAlRZWkvtqjk2svSeXY=

View File

@ -31,7 +31,7 @@ func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID uin
if err != nil {
return nil, err
}
return rpn.sb.ReadPieceFromSealedSector(ctx, abi.SectorNumber(sectorID), sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.TicketBytes, si.CommD)
return rpn.sb.ReadPieceFromSealedSector(ctx, abi.SectorNumber(sectorID), sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.Value, *si.CommD)
}
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error) {

View File

@ -76,6 +76,17 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad
if err != nil {
return nil, xerrors.Errorf("failed getting miner worker: %w", err)
}
ssize, err := a.StateMinerSectorSize(ctx, miner, types.EmptyTSK)
if err != nil {
return nil, xerrors.Errorf("failed checking miners sector size: %w", err)
}
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, xerrors.Errorf("bad sector size: %w", err)
}
providerInfo := utils.NewStorageProviderInfo(miner, mw, 0, pid)
ts, err := a.ChainHead(ctx)
if err != nil {
@ -92,7 +103,9 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad
ts.Height()+dealStartBuffer,
ts.Height()+dealStartBuffer+abi.ChainEpoch(blocksDuration),
epochPrice,
big.Zero())
big.Zero(),
rt,
)
if err != nil {
return nil, xerrors.Errorf("failed to start deal: %w", err)

View File

@ -67,7 +67,8 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
Lane: uint64(lane),
Extra: v.Extra,
TimeLock: v.TimeLock,
TimeLockMin: v.TimeLockMin,
TimeLockMax: v.TimeLockMax,
MinSettleHeight: v.MinSettle,
})
if err != nil {

View File

@ -3,13 +3,14 @@ package impl
import (
"context"
"encoding/json"
"github.com/filecoin-project/lotus/chain/types"
"io"
"mime"
"net/http"
"os"
"strconv"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/gorilla/mux"
files "github.com/ipfs/go-ipfs-files"
@ -209,8 +210,8 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid abi.SectorNumb
CommR: info.CommR,
Proof: info.Proof,
Deals: deals,
Ticket: info.Ticket.SB(),
Seed: info.Seed.SB(),
Ticket: info.Ticket,
Seed: info.Seed,
Retries: info.Nonce,
LastErr: info.LastErr,

View File

@ -3,6 +3,7 @@ package modules
import (
"bytes"
"context"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/ipfs/go-bitswap"

View File

@ -14,6 +14,7 @@ import (
deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
storageimpl "github.com/filecoin-project/go-fil-markets/storagemarket/impl"
smnet "github.com/filecoin-project/go-fil-markets/storagemarket/network"
"github.com/filecoin-project/go-fil-markets/storedcounter"
"github.com/filecoin-project/go-statestore"
"github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network"
@ -117,8 +118,9 @@ func StorageClient(h host.Host, ibs dtypes.ClientBlockstore, r repo.LockedRepo,
}
// RetrievalClient creates a new retrieval client attached to the client blockstore
func RetrievalClient(h host.Host, bs dtypes.ClientBlockstore, pmgr *paychmgr.Manager, payapi payapi.PaychAPI, resolver retrievalmarket.PeerResolver) retrievalmarket.RetrievalClient {
func RetrievalClient(h host.Host, bs dtypes.ClientBlockstore, pmgr *paychmgr.Manager, payapi payapi.PaychAPI, resolver retrievalmarket.PeerResolver, ds dtypes.MetadataDS) (retrievalmarket.RetrievalClient, error) {
adapter := retrievaladapter.NewRetrievalClientNode(pmgr, payapi)
network := rmnet.NewFromLibp2pHost(h)
return retrievalimpl.NewClient(network, bs, adapter, resolver)
sc := storedcounter.New(ds, datastore.NewKey("/retr"))
return retrievalimpl.NewClient(network, bs, adapter, resolver, ds, sc)
}

View File

@ -2,10 +2,11 @@ package modules
import (
"context"
"github.com/filecoin-project/lotus/chain/types"
"math"
"reflect"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/go-address"
dtgraphsync "github.com/filecoin-project/go-data-transfer/impl/graphsync"
piecefilestore "github.com/filecoin-project/go-fil-markets/filestore"
@ -21,6 +22,7 @@ import (
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/go-statestore"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network"
@ -61,7 +63,12 @@ func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) {
}
func GetParams(sbc *sectorbuilder.Config) error {
if err := paramfetch.GetParams(build.ParametersJson(), uint64(sbc.SectorSize)); err != nil {
ssize, err := sbc.SealProofType.SectorSize()
if err != nil {
return err
}
if err := paramfetch.GetParams(build.ParametersJson(), uint64(ssize)); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
@ -69,13 +76,13 @@ func GetParams(sbc *sectorbuilder.Config) error {
}
func SectorBuilderConfig(storage []fs.PathConfig, threads uint, noprecommit, nocommit bool) func(dtypes.MetadataDS, api.FullNode) (*sectorbuilder.Config, error) {
return func(ds dtypes.MetadataDS, api api.FullNode) (*sectorbuilder.Config, error) {
return func(ds dtypes.MetadataDS, fnapi api.FullNode) (*sectorbuilder.Config, error) {
minerAddr, err := minerAddrFromDS(ds)
if err != nil {
return nil, err
}
ssize, err := api.StateMinerSectorSize(context.TODO(), minerAddr, types.EmptyTSK)
ssize, err := fnapi.StateMinerSectorSize(context.TODO(), minerAddr, types.EmptyTSK)
if err != nil {
return nil, err
}
@ -91,9 +98,15 @@ func SectorBuilderConfig(storage []fs.PathConfig, threads uint, noprecommit, noc
return nil, xerrors.Errorf("too many sectorbuilder threads specified: %d, max allowed: %d", threads, math.MaxUint8)
}
ppt, spt, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, xerrors.Errorf("bad sector size: %w", err)
}
sb := &sectorbuilder.Config{
Miner: minerAddr,
SectorSize: ssize,
Miner: minerAddr,
SealProofType: spt,
PoStProofType: ppt,
WorkerThreads: uint8(threads),
NoPreCommit: noprecommit,
@ -267,26 +280,21 @@ func SectorBuilder(cfg *sectorbuilder.Config, ds dtypes.MetadataDS) (*sectorbuil
return sb, nil
}
func SealTicketGen(api api.FullNode) sealing.TicketFn {
return func(ctx context.Context) (*sectorbuilder.SealTicket, error) {
ts, err := api.ChainHead(ctx)
func SealTicketGen(fapi api.FullNode) sealing.TicketFn {
return func(ctx context.Context) (*api.SealTicket, error) {
ts, err := fapi.ChainHead(ctx)
if err != nil {
return nil, xerrors.Errorf("getting head ts for SealTicket failed: %w", err)
}
r, err := api.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_SealRandomness, ts.Height()-build.SealRandomnessLookback, nil)
r, err := fapi.ChainGetRandomness(ctx, ts.Key(), crypto.DomainSeparationTag_SealRandomness, ts.Height()-build.SealRandomnessLookback, nil)
if err != nil {
return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err)
}
var tkt [sectorbuilder.CommLen]byte
if n := copy(tkt[:], r); n != sectorbuilder.CommLen {
return nil, xerrors.Errorf("unexpected randomness len: %d (expected %d)", n, sectorbuilder.CommLen)
}
return &sectorbuilder.SealTicket{
BlockHeight: uint64(ts.Height() - build.SealRandomnessLookback),
TicketBytes: tkt,
return &api.SealTicket{
Epoch: ts.Height() - build.SealRandomnessLookback,
Value: abi.SealRandomness(r),
}, nil
}
}
@ -295,7 +303,7 @@ func NewProviderRequestValidator(deals dtypes.ProviderDealStore) *storageimpl.Pr
return storageimpl.NewProviderRequestValidator(deals)
}
func StorageProvider(h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
func StorageProvider(ctx helpers.MetricsCtx, fapi api.FullNode, h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
if err != nil {
return nil, err
@ -305,11 +313,23 @@ func StorageProvider(h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlocks
if err != nil {
return nil, err
}
minerAddress, err := address.NewFromBytes(addr)
if err != nil {
return nil, err
}
return storageimpl.NewProvider(net, ds, ibs, store, pieceStore, dataTransfer, spn, minerAddress)
ssize, err := fapi.StateMinerSectorSize(ctx, minerAddress, types.EmptyTSK)
if err != nil {
return nil, err
}
rt, _, err := api.ProofTypeFromSectorSize(ssize)
if err != nil {
return nil, err
}
return storageimpl.NewProvider(net, ds, ibs, store, pieceStore, dataTransfer, spn, minerAddress, rt)
}
// RetrievalProvider creates a new retrieval provider attached to the provider blockstore
@ -320,5 +340,5 @@ func RetrievalProvider(h host.Host, miner *storage.Miner, sb sectorbuilder.Inter
return nil, err
}
network := rmnet.NewFromLibp2pHost(h)
return retrievalimpl.NewProvider(address, adapter, network, pieceStore, ibs), nil
return retrievalimpl.NewProvider(address, adapter, network, pieceStore, ibs, ds)
}

View File

@ -2,12 +2,10 @@ package storage
import (
"context"
"github.com/filecoin-project/specs-actors/actors/crypto"
"time"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
@ -91,7 +89,7 @@ func (s *FPoStScheduler) declareFaults(ctx context.Context, fc uint64, params *m
return nil
}
func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo) ([]abi.SectorNumber, error) {
func (s *FPoStScheduler) checkFaults(ctx context.Context, ssi []abi.SectorNumber) ([]abi.SectorNumber, error) {
faults := s.sb.Scrub(ssi)
declaredFaults := map[abi.SectorNumber]struct{}{}
@ -160,21 +158,23 @@ func (s *FPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, ts *ty
"eps", eps,
"height", ts.Height())
faults, err := s.checkFaults(ctx, ssi)
var snums []abi.SectorNumber
for _, si := range ssi {
snums = append(snums, si.SectorNumber)
}
faults, err := s.checkFaults(ctx, snums)
if err != nil {
log.Errorf("Failed to declare faults: %+v", err)
}
tsStart := time.Now()
var seed [32]byte
copy(seed[:], rand)
log.Infow("generating fPoSt",
"sectors", len(ssi.Values()),
"sectors", len(ssi),
"faults", len(faults))
scandidates, proof, err := s.sb.GenerateFallbackPoSt(ssi, seed, faults)
scandidates, proof, err := s.sb.GenerateFallbackPoSt(ssi, abi.PoStRandomness(rand), faults)
if err != nil {
return nil, xerrors.Errorf("running post failed: %w", err)
}
@ -182,55 +182,43 @@ func (s *FPoStScheduler) runPost(ctx context.Context, eps abi.ChainEpoch, ts *ty
elapsed := time.Since(tsStart)
log.Infow("submitting PoSt", "pLen", len(proof), "elapsed", elapsed)
mid, err := address.IDFromAddress(s.actor)
if err != nil {
return nil, err
}
candidates := make([]abi.PoStCandidate, len(scandidates))
for i, sc := range scandidates {
part := make([]byte, 32)
copy(part, sc.PartialTicket[:])
copy(part, sc.Candidate.PartialTicket[:])
candidates[i] = abi.PoStCandidate{
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBPoSt, // TODO: build setting
PartialTicket: part,
SectorID: abi.SectorID{
Miner: abi.ActorID(mid),
Number: sc.SectorNum,
},
ChallengeIndex: int64(sc.SectorChallengeIndex), // TODO: fix spec
SectorID: sc.Candidate.SectorID,
ChallengeIndex: sc.Candidate.ChallengeIndex,
}
}
return &abi.OnChainPoStVerifyInfo{
ProofType: abi.RegisteredProof_StackedDRG32GiBPoSt, // TODO: build setting
Proofs: []abi.PoStProof{{proof}},
Proofs: proof,
Candidates: candidates,
}, nil
}
func (s *FPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet) (sectorbuilder.SortedPublicSectorInfo, error) {
func (s *FPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet) ([]abi.SectorInfo, error) {
sset, err := s.api.StateMinerProvingSet(ctx, s.actor, ts.Key())
if err != nil {
return sectorbuilder.SortedPublicSectorInfo{}, xerrors.Errorf("failed to get proving set for miner (tsH: %d): %w", ts.Height(), err)
return nil, xerrors.Errorf("failed to get proving set for miner (tsH: %d): %w", ts.Height(), err)
}
if len(sset) == 0 {
log.Warn("empty proving set! (ts.H: %d)", ts.Height())
}
sbsi := make([]ffi.PublicSectorInfo, len(sset))
sbsi := make([]abi.SectorInfo, len(sset))
for k, sector := range sset {
var commR [sectorbuilder.CommLen]byte
scid := sector.Info.Info.SealedCID.Bytes()
copy(commR[:], scid[len(scid)-32:])
sbsi[k] = ffi.PublicSectorInfo{
SectorNum: sector.Info.Info.SectorNumber,
CommR: commR,
sbsi[k] = abi.SectorInfo{
SectorNumber: sector.Info.Info.SectorNumber,
SealedCID: sector.Info.Info.SealedCID,
}
}
return sectorbuilder.NewSortedPublicSectorInfo(sbsi), nil
return sbsi, nil
}
func (s *FPoStScheduler) submitPost(ctx context.Context, proof *abi.OnChainPoStVerifyInfo) error {

View File

@ -12,6 +12,7 @@ import (
"github.com/libp2p/go-libp2p-core/host"
"golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
@ -127,13 +128,11 @@ func NewElectionPoStProver(sb sectorbuilder.Interface) *SectorBuilderEpp {
var _ gen.ElectionPoStProver = (*SectorBuilderEpp)(nil)
func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo, rand []byte) ([]sectorbuilder.EPostCandidate, error) {
func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi []abi.SectorInfo, rand abi.PoStRandomness) ([]ffi.PoStCandidateWithTicket, error) {
start := time.Now()
var faults []abi.SectorNumber // TODO
var randbuf [32]byte
copy(randbuf[:], rand)
cds, err := epp.sb.GenerateEPostCandidates(ssi, randbuf, faults)
cds, err := epp.sb.GenerateEPostCandidates(ssi, rand, faults)
if err != nil {
return nil, err
}
@ -141,13 +140,19 @@ func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi sectorb
return cds, nil
}
func (epp *SectorBuilderEpp) ComputeProof(ctx context.Context, ssi sectorbuilder.SortedPublicSectorInfo, rand []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) {
func (epp *SectorBuilderEpp) ComputeProof(ctx context.Context, ssi []abi.SectorInfo, rand []byte, winners []ffi.PoStCandidateWithTicket) ([]abi.PoStProof, error) {
if build.InsecurePoStValidation {
log.Warn("Generating fake EPost proof! You should only see this while running tests!")
return []byte("valid proof"), nil
return []abi.PoStProof{{ProofBytes: []byte("valid proof")}}, nil
}
owins := make([]abi.PoStCandidate, 0, len(winners))
for _, w := range winners {
owins = append(owins, w.Candidate)
}
start := time.Now()
proof, err := epp.sb.ComputeElectionPoSt(ssi, rand, winners)
proof, err := epp.sb.ComputeElectionPoSt(ssi, rand, owins)
if err != nil {
return nil, err
}

View File

@ -13,282 +13,6 @@ import (
var _ = xerrors.Errorf
func (t *SealTicket) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (abi.ChainEpoch) (int64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
if _, err := w.Write([]byte("BlockHeight")); err != nil {
return err
}
if t.BlockHeight >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil {
return err
}
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
if _, err := w.Write([]byte("TicketBytes")); err != nil {
return err
}
if len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
if _, err := w.Write(t.TicketBytes); err != nil {
return err
}
return nil
}
func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealTicket: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.BlockHeight (abi.ChainEpoch) (int64)
case "BlockHeight":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.BlockHeight = abi.ChainEpoch(extraI)
}
// t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.TicketBytes = make([]byte, extra)
if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}
func (t *SealSeed) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{162}); err != nil {
return err
}
// t.BlockHeight (abi.ChainEpoch) (int64)
if len("BlockHeight") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockHeight\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("BlockHeight")))); err != nil {
return err
}
if _, err := w.Write([]byte("BlockHeight")); err != nil {
return err
}
if t.BlockHeight >= 0 {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.BlockHeight))); err != nil {
return err
}
} else {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.BlockHeight)-1)); err != nil {
return err
}
}
// t.TicketBytes ([]uint8) (slice)
if len("TicketBytes") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"TicketBytes\" was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("TicketBytes")))); err != nil {
return err
}
if _, err := w.Write([]byte("TicketBytes")); err != nil {
return err
}
if len(t.TicketBytes) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.TicketBytes was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.TicketBytes)))); err != nil {
return err
}
if _, err := w.Write(t.TicketBytes); err != nil {
return err
}
return nil
}
func (t *SealSeed) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajMap {
return fmt.Errorf("cbor input should be of type map")
}
if extra > cbg.MaxLength {
return fmt.Errorf("SealSeed: map struct too large (%d)", extra)
}
var name string
n := extra
for i := uint64(0); i < n; i++ {
{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}
name = string(sval)
}
switch name {
// t.BlockHeight (abi.ChainEpoch) (int64)
case "BlockHeight":
{
maj, extra, err := cbg.CborReadHeader(br)
var extraI int64
if err != nil {
return err
}
switch maj {
case cbg.MajUnsignedInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 positive overflow")
}
case cbg.MajNegativeInt:
extraI = int64(extra)
if extraI < 0 {
return fmt.Errorf("int64 negative oveflow")
}
extraI = -1 - extraI
default:
return fmt.Errorf("wrong type for int64 field: %d", maj)
}
t.BlockHeight = abi.ChainEpoch(extraI)
}
// t.TicketBytes ([]uint8) (slice)
case "TicketBytes":
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.TicketBytes: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.TicketBytes = make([]byte, extra)
if _, err := io.ReadFull(br, t.TicketBytes); err != nil {
return err
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
}
}
return nil
}
func (t *Piece) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
@ -620,10 +344,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if err := t.Seed.MarshalCBOR(w); err != nil {
return err
}
// t.CommitMessage (cid.Cid) (struct)
if len("CommitMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommitMessage\" was too long")
@ -903,10 +623,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
{
if err := t.Seed.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.CommitMessage (cid.Cid) (struct)
case "CommitMessage":

View File

@ -111,8 +111,8 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)}
}
if int64(head.Height())-int64(si.Ticket.BlockHeight+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit {
return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.BlockHeight+build.SealRandomnessLookback, head.Height())}
if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit {
return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.Epoch+build.SealRandomnessLookback, head.Height())}
}
return nil

View File

@ -68,7 +68,7 @@ func (evt SectorPackingFailed) apply(*SectorInfo) {}
type SectorSealed struct {
commR cid.Cid
commD cid.Cid
ticket SealTicket
ticket api.SealTicket
}
func (evt SectorSealed) apply(state *SectorInfo) {
@ -96,7 +96,7 @@ func (evt SectorPreCommitted) apply(state *SectorInfo) {
}
type SectorSeedReady struct {
seed SealSeed
seed api.SealSeed
}
func (evt SectorSeedReady) apply(state *SectorInfo) {

View File

@ -75,12 +75,12 @@ func TestSeedRevert(t *testing.T) {
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing)
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state)
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
require.NoError(t, err)
require.Equal(m.t, m.state.State, api.Committing)
// not changing the seed this time
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state)
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{})

View File

@ -28,7 +28,7 @@ const SectorStorePrefix = "/sectors"
var log = logging.Logger("sectors")
type TicketFn func(context.Context) (SealTicket, error)
type TicketFn func(context.Context) (*api.SealTicket, error)
type sealingApi interface { // TODO: trim down
// Call a read only method on actors (no interaction with the chain required)

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
@ -69,7 +70,7 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)})
}
sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.TicketBytes, sector.pieceInfos())
sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.Value, sector.pieceInfos())
if err != nil {
return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)})
}
@ -77,7 +78,7 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
return ctx.Send(SectorSealed{
commD: unsealed,
commR: sealed,
ticket: ticket,
ticket: *ticket,
})
}
@ -102,7 +103,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal,
SealedCID: *sector.CommR,
SealRandEpoch: sector.Ticket.BlockHeight,
SealRandEpoch: sector.Ticket.Epoch,
DealIDs: sector.deals(),
}
enc, aerr := actors.SerializeParams(params)
@ -156,9 +157,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
return err
}
ctx.Send(SectorSeedReady{seed: SealSeed{
BlockHeight: randHeight,
TicketBytes: abi.InteractiveSealRandomness(rand),
ctx.Send(SectorSeedReady{seed: api.SealSeed{
Epoch: randHeight,
Value: abi.InteractiveSealRandomness(rand),
}})
return nil
@ -177,9 +178,9 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) error {
log.Info("scheduling seal proof computation...")
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)
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.Value, sector.Ticket.Epoch, sector.Seed.Value, sector.Seed.Epoch, sector.pieceInfos(), sector.CommR, sector.CommD)
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.pieceInfos(), *sector.CommR, *sector.CommD)
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.Value, sector.Seed.Value, sector.pieceInfos(), *sector.CommR, *sector.CommD)
if err != nil {
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)})
}
@ -231,7 +232,7 @@ func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo)
}
if mw.Receipt.ExitCode != 0 {
return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)})
return ctx.Send(SectorCommitFailed{xerrors.Errorf("submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.Value, sector.Seed.Value, sector.Seed.Epoch, sector.Proof)})
}
return ctx.Send(SectorProving{})

View File

@ -6,20 +6,6 @@ import (
"github.com/ipfs/go-cid"
)
type SealTicket struct {
BlockHeight abi.ChainEpoch
TicketBytes abi.SealRandomness
}
type SealSeed struct {
BlockHeight abi.ChainEpoch
TicketBytes abi.InteractiveSealRandomness
}
func (t *SealSeed) Equals(o *SealSeed) bool {
return string(t.TicketBytes) == string(o.TicketBytes) && t.BlockHeight == o.BlockHeight
}
type Piece struct {
DealID *abi.DealID
@ -52,12 +38,12 @@ type SectorInfo struct {
CommD *cid.Cid
CommR *cid.Cid
Proof []byte
Ticket SealTicket
Ticket api.SealTicket
PreCommitMessage *cid.Cid
// WaitSeed
Seed SealSeed
Seed api.SealSeed
// Committing
CommitMessage *cid.Cid

View File

@ -4,6 +4,7 @@ import (
"bytes"
"testing"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"gotest.tools/assert"
@ -28,12 +29,12 @@ func TestSectorInfoSelialization(t *testing.T) {
CommD: &dummyCid,
CommR: nil,
Proof: nil,
Ticket: SealTicket{
BlockHeight: 345,
TicketBytes: []byte{87, 78, 7, 87},
Ticket: api.SealTicket{
Epoch: 345,
Value: []byte{87, 78, 7, 87},
},
PreCommitMessage: nil,
Seed: SealSeed{},
Seed: api.SealSeed{},
CommitMessage: nil,
FaultReportMsg: nil,
LastErr: "hi",