Some more progress on interactive porep
This commit is contained in:
parent
7fa3e2db7a
commit
759094198c
@ -98,6 +98,7 @@ type UnprovenSector struct {
|
||||
CommD []byte
|
||||
CommR []byte
|
||||
SubmitHeight uint64
|
||||
TicketEpoch uint64
|
||||
}
|
||||
|
||||
type StorageMinerConstructorParams struct {
|
||||
@ -216,7 +217,6 @@ type SectorPreCommitInfo struct {
|
||||
CommR []byte
|
||||
|
||||
Epoch uint64
|
||||
Proof []byte
|
||||
SectorNumber uint64
|
||||
}
|
||||
|
||||
@ -227,6 +227,14 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if params.Epoch >= vmctx.BlockHeight() {
|
||||
return nil, aerrors.New(1, "sector commitment must be based off past randomness")
|
||||
}
|
||||
|
||||
if vmctx.BlockHeight()-params.Epoch > 1000 {
|
||||
return nil, aerrors.New(2, "sector commitment must be recent enough")
|
||||
}
|
||||
|
||||
mi, err := loadMinerInfo(vmctx, self)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -258,6 +266,7 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
|
||||
CommR: params.CommR,
|
||||
CommD: params.CommD,
|
||||
SubmitHeight: vmctx.BlockHeight(),
|
||||
TicketEpoch: params.Epoch,
|
||||
}
|
||||
|
||||
nstate, err := vmctx.Storage().Put(self)
|
||||
@ -305,10 +314,18 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
|
||||
maddr := vmctx.Message().To
|
||||
|
||||
var pieces []sectorbuilder.PublicPieceInfo // TODO: GET ME FROM DEALS IN STORAGEMARKET
|
||||
var seed []byte // TODO: GET ME FROM SOMEWHERE
|
||||
|
||||
rand, err := vmctx.GetRandomness(us.SubmitHeight + build.InteractivePoRepDelay)
|
||||
if ok, err := ValidatePoRep(maddr, mi.SectorSize, us.CommD, us.CommR, rand, seed, params.Proof, params.SectorID, pieces); err != nil {
|
||||
ticket, err := vmctx.GetRandomness(us.TicketEpoch)
|
||||
if err != nil {
|
||||
return nil, aerrors.Wrap(err, "failed to get ticket randomness")
|
||||
}
|
||||
|
||||
seed, err := vmctx.GetRandomness(us.SubmitHeight + build.InteractivePoRepDelay)
|
||||
if err != nil {
|
||||
return nil, aerrors.Wrap(err, "failed to get randomness for prove sector commitment")
|
||||
}
|
||||
|
||||
if ok, err := ValidatePoRep(maddr, mi.SectorSize, us.CommD, us.CommR, ticket, params.Proof, seed, params.SectorID, pieces); err != nil {
|
||||
return nil, err
|
||||
} else if !ok {
|
||||
return nil, aerrors.New(2, "bad proof!")
|
||||
|
@ -29,9 +29,10 @@ type smaMethods struct {
|
||||
SlashStorageDealCollateral uint64
|
||||
GetLastExpirationFromDealIDs uint64
|
||||
ActivateStorageDeals uint64
|
||||
ComputeDataCommitment uint64
|
||||
}
|
||||
|
||||
var SMAMethods = smaMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||
var SMAMethods = smaMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
|
||||
|
||||
func (sma StorageMarketActor) Exports() []interface{} {
|
||||
return []interface{}{
|
||||
@ -45,6 +46,7 @@ func (sma StorageMarketActor) Exports() []interface{} {
|
||||
// 9: sma.SlashStorageDealCollateral,
|
||||
// 10: sma.GetLastExpirationFromDealIDs,
|
||||
11: sma.ActivateStorageDeals, // TODO: move under PublishStorageDeals after specs team approves
|
||||
12: sma.ComputeDataCommitment,
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,6 +587,42 @@ func transferFunds(from, to, amt types.BigInt) (types.BigInt, types.BigInt) {
|
||||
return types.BigSub(from, amt), types.BigAdd(to, amt)
|
||||
}
|
||||
|
||||
var ComputeDataCommitmentParams struct {
|
||||
DealIDs []uint64
|
||||
SectorSize uint64
|
||||
}
|
||||
|
||||
func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx types.VMContext, params *ComputeDataCommitmentParams) ([]byte, ActorError) {
|
||||
var self StorageMarketState
|
||||
old := vmctx.Storage().GetHead()
|
||||
if err := vmctx.Storage().Get(old, &self); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deals, err := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.Deals)
|
||||
if err != nil {
|
||||
// TODO: kind of annoying that this can be caused by gas, otherwise could be fatal
|
||||
return nil, aerrors.HandleExternalError(err, "loading deals amt")
|
||||
}
|
||||
|
||||
for _, deal := range params.DealIDs {
|
||||
var dealInfo OnChainDeal
|
||||
if err := deals.Get(deal, &dealInfo); err != nil {
|
||||
if _, is := err.(*amt.ErrNotFound); is {
|
||||
return nil, aerrors.New(3, "deal not found")
|
||||
}
|
||||
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
||||
}
|
||||
|
||||
_ = dealInfo
|
||||
}
|
||||
|
||||
// TODO: rust-fil-proofs-magic
|
||||
var commDoutput [32]byte
|
||||
|
||||
return commDoutput[:], nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (sma StorageMarketActor) HandleCronAction(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
||||
|
||||
|
@ -2,6 +2,7 @@ package deals
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/filecoin-project/lotus/lib/cborrpc"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-datastore"
|
||||
|
@ -88,6 +88,7 @@ func main() {
|
||||
actors.ActivateStorageDealsParams{},
|
||||
actors.ProcessStorageDealsPaymentParams{},
|
||||
actors.OnChainDeal{},
|
||||
actors.ComputeDataCommitmentParams{},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
1
go.sum
1
go.sum
@ -823,6 +823,7 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
|
@ -28,6 +28,8 @@ type SealTicket = sectorbuilder.SealTicket
|
||||
|
||||
type SealSeed = sectorbuilder.SealSeed
|
||||
|
||||
type SealPreCommitOutput = sectorbuilder.SealPreCommitOutput
|
||||
|
||||
type SealCommitOutput = sectorbuilder.SealCommitOutput
|
||||
|
||||
type PublicPieceInfo = sectorbuilder.PublicPieceInfo
|
||||
@ -90,7 +92,11 @@ func (sb *SectorBuilder) ReadPieceFromSealedSector(pieceKey string) ([]byte, err
|
||||
return sectorbuilder.ReadPieceFromSealedSector(sb.handle, pieceKey)
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) SealSector(sectorID uint64, seed SealSeed) (SealCommitOutput, error) {
|
||||
func (sb *SectorBuilder) SealPreCommit(sectorID uint64, ticket SealTicket) (SealPreCommitOutput, error) {
|
||||
return sectorbuilder.SealPreCommit(sb.handle, sectorID, ticket)
|
||||
}
|
||||
|
||||
func (sb *SectorBuilder) SealCommit(sectorID uint64, seed SealSeed) (SealCommitOutput, error) {
|
||||
return sectorbuilder.SealCommit(sb.handle, sectorID, seed)
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ func SectorBuilderConfig(storagePath string) func(dtypes.MetadataDS, api.FullNod
|
||||
sb := §orbuilder.SectorBuilderConfig{
|
||||
Miner: minerAddr,
|
||||
SectorSize: ssize,
|
||||
CacheDir:cache,
|
||||
CacheDir: cache,
|
||||
MetadataDir: metadata,
|
||||
SealedDir: sealed,
|
||||
StagedDir: staging,
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"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/address"
|
||||
"github.com/filecoin-project/lotus/chain/events"
|
||||
@ -159,15 +160,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
|
||||
return xerrors.Errorf("failed to check out own sector size: %w", err)
|
||||
}
|
||||
|
||||
// TODO: Interactive porep
|
||||
|
||||
ok, err := sectorbuilder.VerifySeal(ssize, sinfo.CommR[:], sinfo.CommD[:], m.maddr, sinfo.Ticket.TicketBytes[:], sinfo.SectorID, sinfo.Proof)
|
||||
if err != nil {
|
||||
log.Error("failed to verify seal we just created: ", err)
|
||||
}
|
||||
if !ok {
|
||||
log.Error("seal we just created failed verification")
|
||||
}
|
||||
_ = ssize
|
||||
|
||||
// TODO: 2 stage commit
|
||||
/*deals, err := m.secst.DealsForCommit(sinfo.SectorID)
|
||||
@ -178,7 +171,6 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
|
||||
params := &actors.SectorPreCommitInfo{
|
||||
CommD: sinfo.CommD[:],
|
||||
CommR: sinfo.CommR[:],
|
||||
Proof: sinfo.Proof,
|
||||
Epoch: sinfo.Ticket.BlockHeight,
|
||||
|
||||
//DealIDs: deals,
|
||||
@ -205,14 +197,76 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
|
||||
}
|
||||
|
||||
go func() {
|
||||
_, err := m.api.StateWaitMsg(ctx, smsg.Cid())
|
||||
// TODO: maybe just mark this down in the datastore and handle it differently? This feels complicated to restart
|
||||
mw, err := m.api.StateWaitMsg(ctx, smsg.Cid())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
randHeight := mw.TipSet.Height() + build.InteractivePoRepDelay
|
||||
|
||||
err = m.events.ChainAt(func(ts *types.TipSet, curH uint64) error {
|
||||
go func() {
|
||||
rand, err := m.api.ChainGetRandomness(ctx, ts, nil, ts.Height()-randHeight)
|
||||
if err != nil {
|
||||
log.Error(errors.Errorf("failed to get randomness for computing seal proof: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: should this get scheduled to preserve proper resource consumption?
|
||||
proof, err := m.secst.SealComputeProof(ctx, sinfo.SectorID, rand)
|
||||
if err != nil {
|
||||
log.Error(errors.Errorf("computing seal proof failed: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
params := &actors.SectorProveCommitInfo{
|
||||
Proof: proof,
|
||||
SectorID: sinfo.SectorID,
|
||||
//DealIDs: deals,
|
||||
}
|
||||
|
||||
enc, aerr := actors.SerializeParams(params)
|
||||
if aerr != nil {
|
||||
log.Errorf(errors.Wrap(aerr, "could not serialize commit sector parameters"))
|
||||
return
|
||||
}
|
||||
|
||||
msg := &types.Message{
|
||||
To: m.maddr,
|
||||
From: m.worker,
|
||||
Method: actors.MAMethods.ProveCommitSector,
|
||||
Params: enc,
|
||||
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
||||
GasLimit: types.NewInt(1000000 /* i dont know help */),
|
||||
GasPrice: types.NewInt(1),
|
||||
}
|
||||
|
||||
smsg, err := m.api.MpoolPushMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pushing message to mpool")
|
||||
}
|
||||
|
||||
// TODO: now wait for this to get included and handle errors?
|
||||
_, err := m.api.StateWaitMsg(ctx, smsg.Cid())
|
||||
if err != nil {
|
||||
log.Errorf("failed to wait for porep inclusion: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
m.beginPosting(ctx)
|
||||
}()
|
||||
|
||||
return nil
|
||||
}, func(ts *types.TipSet) error {
|
||||
log.Warn("revert in interactive commit sector step")
|
||||
return nil
|
||||
}, 3, mw.TipSet.Height()+build.InteractivePoRepDelay)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
||||
"github.com/ipfs/go-datastore"
|
||||
@ -65,48 +64,6 @@ func (s *Store) Service() {
|
||||
go s.service()
|
||||
}
|
||||
|
||||
func (s *Store) poll() { // TODO: REMOVE ME (and just use the fact that sectorbuilder methods are now blocking)
|
||||
log.Debug("polling for sealed sectors...")
|
||||
|
||||
// get a list of sectors to poll
|
||||
s.waitingLk.Lock()
|
||||
toPoll := make([]uint64, 0, len(s.waiting))
|
||||
|
||||
for id := range s.waiting {
|
||||
toPoll = append(toPoll, id)
|
||||
}
|
||||
s.waitingLk.Unlock()
|
||||
|
||||
var done []sectorbuilder.SectorSealingStatus
|
||||
|
||||
// check status of each
|
||||
for _, sec := range toPoll {
|
||||
status, err := s.sb.SealStatus(sec)
|
||||
if err != nil {
|
||||
log.Errorf("getting seal status: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if status.State == sealing_state.Committed {
|
||||
done = append(done, status)
|
||||
}
|
||||
}
|
||||
|
||||
// send updates
|
||||
s.waitingLk.Lock()
|
||||
for _, sector := range done {
|
||||
watch, ok := s.waiting[sector.SectorID]
|
||||
if ok {
|
||||
close(watch)
|
||||
delete(s.waiting, sector.SectorID)
|
||||
}
|
||||
for _, c := range s.incoming {
|
||||
c <- sector // TODO: ctx!
|
||||
}
|
||||
}
|
||||
s.waitingLk.Unlock()
|
||||
}
|
||||
|
||||
func (s *Store) restartSealing() {
|
||||
sectors, err := s.sb.GetAllStagedSectors()
|
||||
if err != nil {
|
||||
@ -135,26 +92,6 @@ func (s *Store) restartSealing() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) service() {
|
||||
poll := time.Tick(5 * time.Second)
|
||||
|
||||
s.restartSealing()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-poll:
|
||||
s.poll()
|
||||
case <-s.closeCh:
|
||||
s.waitingLk.Lock()
|
||||
for _, c := range s.incoming {
|
||||
close(c)
|
||||
}
|
||||
s.waitingLk.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) AddPiece(ref string, size uint64, r io.Reader, dealIDs ...uint64) (sectorID uint64, err error) {
|
||||
sectorID, err = s.sb.AddPiece(ref, size, r)
|
||||
if err != nil {
|
||||
@ -234,7 +171,7 @@ func (s *Store) DealsForCommit(sectorID uint64) ([]uint64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) SealSector(ctx context.Context, sectorID uint64) error {
|
||||
func (s *Store) SealPreCommit(ctx context.Context, sectorID uint64) error {
|
||||
tkt, err := s.tktFn(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -242,13 +179,17 @@ func (s *Store) SealSector(ctx context.Context, sectorID uint64) error {
|
||||
|
||||
// TODO: That's not async, is it?
|
||||
// - If not then we probably can drop this wait-for-seal hack below
|
||||
_, err = s.sb.SealSector(sectorID, *tkt)
|
||||
_, err = s.sb.SealPreCommit(sectorID, *tkt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) SealComputeProof(ctx context.Context, sectorID uint64, rand []byte) ([]byte, error) {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func (s *Store) CloseIncoming(c <-chan sectorbuilder.SectorSealingStatus) {
|
||||
s.waitingLk.Lock()
|
||||
var at = -1
|
||||
|
Loading…
Reference in New Issue
Block a user