57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
|
package lpffi
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
ffi "github.com/filecoin-project/filecoin-ffi"
|
||
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
||
|
"github.com/filecoin-project/go-state-types/abi"
|
||
|
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
|
||
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
||
|
"github.com/ipfs/go-cid"
|
||
|
"golang.org/x/xerrors"
|
||
|
)
|
||
|
|
||
|
type ExternPrecommit2 func(ctx context.Context, sector storiface.SectorRef, cache, sealed string, pc1out storiface.PreCommit1Out) (sealedCID cid.Cid, unsealedCID cid.Cid, err error)
|
||
|
|
||
|
type ExternalSealer struct {
|
||
|
PreCommit2 ExternPrecommit2
|
||
|
}
|
||
|
|
||
|
type SealCalls struct {
|
||
|
sectors ffiwrapper.SectorProvider
|
||
|
|
||
|
// externCalls cointain overrides for calling alternative sealing logic
|
||
|
externCalls ExternalSealer
|
||
|
}
|
||
|
|
||
|
func (sb *SealCalls) GenerateSDR(ctx context.Context, sector storiface.SectorRef, ticket abi.SealRandomness, commKcid cid.Cid) error {
|
||
|
paths, releaseSector, err := sb.sectors.AcquireSector(ctx, sector, storiface.FTCache, storiface.FTNone, storiface.PathSealing)
|
||
|
if err != nil {
|
||
|
return xerrors.Errorf("acquiring sector paths: %w", err)
|
||
|
}
|
||
|
defer releaseSector()
|
||
|
|
||
|
// prepare SDR params
|
||
|
commp, err := commcid.CIDToDataCommitmentV1(commKcid)
|
||
|
if err != nil {
|
||
|
return xerrors.Errorf("computing commK: %w", err)
|
||
|
}
|
||
|
|
||
|
replicaID, err := sector.ProofType.ReplicaId(sector.ID.Miner, sector.ID.Number, ticket, commp)
|
||
|
if err != nil {
|
||
|
return xerrors.Errorf("computing replica id: %w", err)
|
||
|
}
|
||
|
|
||
|
// generate new sector key
|
||
|
err = ffi.GenerateSDR(
|
||
|
sector.ProofType,
|
||
|
paths.Cache,
|
||
|
replicaID,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return xerrors.Errorf("generating SDR %d (%s): %w", sector.ID.Number, paths.Unsealed, err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|