Fix post seed height math

This commit is contained in:
Łukasz Magiera 2019-09-19 19:38:48 +02:00
parent c40f89f2a9
commit 839597012d
7 changed files with 21 additions and 10 deletions

View File

@ -1,7 +1,7 @@
package build
// Seconds
const BlockDelay = 5
const BlockDelay = 3
// Seconds
const AllowableClockDrift = BlockDelay * 2

View File

@ -20,7 +20,7 @@ const ForkLengthThreshold = 20
const RandomnessLookback = 20
// Blocks
const ProvingPeriodDuration = 20
const PoSTChallangeTime = 10
const ProvingPeriodDuration = 10
const PoSTChallangeTime = 5
// TODO: Move other important consts here

View File

@ -2,6 +2,7 @@ package actors
import (
"context"
"encoding/base64"
"fmt"
"github.com/filecoin-project/go-lotus/build"
@ -336,13 +337,16 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
}
}
var dbgRandH uint64
var seed [sectorbuilder.CommLen]byte
{
var rand []byte
var err ActorError
if !lateSubmission {
dbgRandH = self.ProvingPeriodEnd - build.PoSTChallangeTime
rand, err = vmctx.GetRandomness(self.ProvingPeriodEnd - build.PoSTChallangeTime)
} else {
dbgRandH = nextProvingPeriodEnd - build.PoSTChallangeTime
rand, err = vmctx.GetRandomness(nextProvingPeriodEnd - build.PoSTChallangeTime)
}
if err != nil {
@ -384,14 +388,17 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
faults := self.CurrentFaultSet.All()
log.Infof("VerifyPost; rh=%d r=%s pLen=%d", dbgRandH, base64.StdEncoding.EncodeToString(seed[:]), len(params.Proof))
if ok, lerr := sectorbuilder.VerifyPost(mi.SectorSize.Uint64(),
sectorbuilder.NewSortedSectorInfo(sectorInfos), seed, params.Proof,
faults); !ok || lerr != nil {
if lerr != nil {
// TODO: study PoST errors
log.Infof("Post Verify Error: %s", lerr)
return nil, aerrors.Absorb(lerr, 4, "PoST error")
}
if !ok {
log.Info("post verification FAILED")
return nil, aerrors.New(4, "PoST invalid")
}
}

View File

@ -77,7 +77,7 @@ func (mp *MessagePool) addLocked(m *types.SignedMessage) error {
return err
}
log.Info("mpooladd: %s", base64.StdEncoding.EncodeToString(data))
log.Infof("mpooladd: %s", base64.StdEncoding.EncodeToString(data))
if err := m.Signature.Verify(m.Message.From, data); err != nil {
return err

View File

@ -722,6 +722,7 @@ func (cs *ChainStore) GetRandomness(ctx context.Context, pts *types.TipSet, tick
mtb := nts.MinTicketBlock()
if nv < len(mtb.Tickets) {
t := mtb.Tickets[len(mtb.Tickets)-(1+nv)]
log.Infof("Returning randomness: H:%d, t:%d, mtb:%s", nts.Height(), len(mtb.Tickets)-(1+nv), mtb.Cid())
return t.VDFResult, nil
}

View File

@ -67,8 +67,10 @@ func (vmc *VMContext) Message() *types.Message {
}
func (vmc *VMContext) GetRandomness(height uint64) ([]byte, aerrors.ActorError) {
relHeight := int(vmc.BlockHeight()) - int(height)
res, err := vmc.vm.cs.GetRandomness(vmc.ctx, vmc.vm.cs.GetHeaviestTipSet(), nil, relHeight)
hts := vmc.vm.cs.GetHeaviestTipSet()
relHeight := int(hts.Height() - height)
res, err := vmc.vm.cs.GetRandomness(vmc.ctx, hts, nil, relHeight)
if err != nil {
return nil, aerrors.Escalate(err, "could not get randomness")
}

View File

@ -2,6 +2,7 @@ package storage
import (
"context"
"encoding/base64"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log"
@ -259,19 +260,19 @@ func (m *Miner) maybeDoPost(ctx context.Context, ts *types.TipSet) (<-chan error
return nil, nil, xerrors.Errorf("failed to get proving set for miner: %w", err)
}
r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(ts.Height()-ppe+build.ProvingPeriodDuration)) // TODO: review: check math
r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoSTChallangeTime))) // TODO: review: check math
if err != nil {
return nil, nil, xerrors.Errorf("failed to get chain randomness for post: %w", err)
}
sourceTs, err := m.api.ChainGetTipSetByHeight(ctx, ppe-build.ProvingPeriodDuration, ts)
sourceTs, err := m.api.ChainGetTipSetByHeight(ctx, ppe-build.PoSTChallangeTime, ts)
if err != nil {
return nil, nil, xerrors.Errorf("failed to get post start tipset: %w", err)
}
ret := make(chan error, 1)
go func() {
log.Info("running PoSt computation")
log.Infof("running PoSt computation, rh=%d r=%s, ppe=%d, h=%d", ts.Height()-(ts.Height()-ppe+build.PoSTChallangeTime), base64.StdEncoding.EncodeToString(r), ppe, ts.Height())
var faults []uint64
proof, err := m.secst.RunPoSt(ctx, sset, r, faults)
if err != nil {
@ -279,7 +280,7 @@ func (m *Miner) maybeDoPost(ctx context.Context, ts *types.TipSet) (<-chan error
return
}
log.Info("submitting PoSt")
log.Infof("submitting PoSt pLen=%d", len(proof))
params := &actors.SubmitPoStParams{
Proof: proof,