sealing garbage data into a sector that gets accepted by the chain works!

This commit is contained in:
whyrusleeping 2019-08-07 18:16:58 -07:00
parent 5c32725510
commit ba0d648546
7 changed files with 93 additions and 25 deletions

View File

@ -377,6 +377,7 @@ func AddToSectorSet(ctx context.Context, cst *hamt.CborIpldStore, ss cid.Cid, se
}
func ValidatePoRep(maddr address.Address, ssize types.BigInt, params *CommitSectorParams) (bool, ActorError) {
log.Infof("VALIDATE POREP: %d %x %x %x %s %d %x", ssize.Uint64(), params.CommR, params.CommD, params.CommRStar, maddr, params.SectorID.Uint64(), params.Proof)
ok, err := sectorbuilder.VerifySeal(ssize.Uint64(), params.CommR, params.CommD, params.CommRStar, maddr, params.SectorID.Uint64(), params.Proof)
if err != nil {
return false, aerrors.Escalate(err, "verify seal failed")

View File

@ -2,7 +2,6 @@ package gen
import (
"context"
"fmt"
bls "github.com/filecoin-project/go-bls-sigs"
cid "github.com/ipfs/go-cid"
@ -70,9 +69,6 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
if err != nil {
return nil, errors.Wrap(err, "apply message failure")
}
if rec.ActorErr != nil {
fmt.Println(rec.ActorErr)
}
receipts = append(receipts, rec.MessageReceipt)
}
@ -81,9 +77,6 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
if err != nil {
return nil, errors.Wrap(err, "apply message failure")
}
if rec.ActorErr != nil {
fmt.Println(rec.ActorErr)
}
receipts = append(receipts, rec.MessageReceipt)
}

View File

@ -21,7 +21,7 @@ func (sb *SectorBuilder) pollForSealedSectors(ctx context.Context) {
watching[s.SectorID] = true
}
tick := time.Tick(time.Second * 30)
tick := time.Tick(time.Second * 5)
for {
select {
case <-tick:

View File

@ -36,7 +36,7 @@ type SectorBuilderConfig struct {
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
proverId := addressToProverID(cfg.Miner)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 2, 1, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 1, 1, 1, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
if err != nil {
return nil, err
}

View File

@ -0,0 +1,65 @@
package sectorbuilder
import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"testing"
"github.com/filecoin-project/go-lotus/chain/address"
)
func TestSealAndVerify(t *testing.T) {
t.Skip("this is slow")
dir, err := ioutil.TempDir("", "sbtest")
if err != nil {
t.Fatal(err)
}
addr, err := address.NewFromString("t1tct3nfaw2q543xtybxcyw4deyxmfwkjk43u4t5y")
if err != nil {
t.Fatal(err)
}
sb, err := New(&SectorBuilderConfig{
SectorSize: 1024,
SealedDir: dir,
StagedDir: dir,
MetadataDir: dir,
Miner: addr,
})
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sb.Run(ctx)
fi, err := ioutil.TempFile("", "sbtestfi")
if err != nil {
t.Fatal(err)
}
defer fi.Close()
io.CopyN(fi, rand.New(rand.NewSource(42)), 1016)
if _, err := sb.AddPiece("foo", 1016, fi.Name()); err != nil {
t.Fatal(err)
}
ssinfo := <-sb.SealedSectorChan()
fmt.Println("sector sealed...")
ok, err := VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], ssinfo.CommRStar[:], addr, ssinfo.SectorID, ssinfo.Proof)
if err != nil {
t.Fatal(err)
}
if !ok {
t.Fatal("proof failed to validate")
}
}

View File

@ -18,8 +18,22 @@ import (
"github.com/filecoin-project/go-lotus/storage"
)
func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilderConfig, error) {
return func() (*sectorbuilder.SectorBuilderConfig, error) {
func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) {
maddrb, err := ds.Get(datastore.NewKey("miner-address"))
if err != nil {
return address.Undef, err
}
return address.NewFromBytes(maddrb)
}
func SectorBuilderConfig(storagePath string) func(dtypes.MetadataDS) (*sectorbuilder.SectorBuilderConfig, error) {
return func(ds dtypes.MetadataDS) (*sectorbuilder.SectorBuilderConfig, error) {
minerAddr, err := minerAddrFromDS(ds)
if err != nil {
return nil, err
}
sp, err := homedir.Expand(storagePath)
if err != nil {
return nil, err
@ -29,12 +43,6 @@ func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilde
sealed := filepath.Join(sp, "sealed")
staging := filepath.Join(sp, "staging")
// TODO: get the address of the miner actor
minerAddr, err := address.NewIDAddress(42)
if err != nil {
return nil, err
}
sb := &sectorbuilder.SectorBuilderConfig{
Miner: minerAddr,
SectorSize: 1024,
@ -66,17 +74,11 @@ func SectorBuilder(mctx helpers.MetricsCtx, lc fx.Lifecycle, sbc *sectorbuilder.
}
func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api api.FullNode, h host.Host, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, w *wallet.Wallet) (*storage.Miner, error) {
maddrb, err := ds.Get(datastore.NewKey("miner-address"))
maddr, err := minerAddrFromDS(ds)
if err != nil {
return nil, err
}
maddr, err := address.NewFromBytes(maddrb)
if err != nil {
return nil, err
}
log.Infof("setting up miner: %s", maddr)
sm, err := storage.NewMiner(api, maddr, h, ds, sb, w)
if err != nil {
return nil, err

View File

@ -99,6 +99,14 @@ func (m *Miner) handlePostingSealedSectors(ctx context.Context) {
}
func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSealingStatus) error {
ok, err := sectorbuilder.VerifySeal(1024, sinfo.CommR[:], sinfo.CommD[:], sinfo.CommRStar[:], m.maddr, 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")
}
params := &actors.CommitSectorParams{
SectorID: types.NewInt(sinfo.SectorID),
CommD: sinfo.CommD[:],
@ -168,7 +176,6 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error {
m.worker = worker
// try signing something with that key to make sure we can
has, err := m.w.HasKey(worker)
if err != nil {
return errors.Wrap(err, "failed to check wallet for worker key")