Add randomness
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
86fd132cf7
commit
54e076b6f9
@ -14,4 +14,7 @@ const DealVoucherSkewLimit = 10
|
||||
const ForkLengthThreshold = 20
|
||||
const RandomnessLookback = 20
|
||||
|
||||
const ProvingPeriodDuration = 2 * 60 // an hour, for now
|
||||
const PoSTChallangeTime = 1 * 60
|
||||
|
||||
// TODO: Move other important consts here
|
||||
|
@ -2,7 +2,9 @@ package actors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/build"
|
||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
@ -16,9 +18,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
var ProvingPeriodDuration = uint64(2 * 60) // an hour, for now
|
||||
var PoSTChallangeTime = uint64(1 * 60)
|
||||
|
||||
const POST_SECTORS_COUNT = 8192
|
||||
|
||||
type StorageMinerActor struct{}
|
||||
@ -272,7 +271,7 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
||||
if self.ProvingSetSize == 0 {
|
||||
self.ProvingSet = self.Sectors
|
||||
self.ProvingSetSize = self.SectorSetSize
|
||||
self.ProvingPeriodEnd = vmctx.BlockHeight() + ProvingPeriodDuration
|
||||
self.ProvingPeriodEnd = vmctx.BlockHeight() + build.ProvingPeriodDuration
|
||||
}
|
||||
|
||||
nstate, err := vmctx.Storage().Put(self)
|
||||
@ -310,7 +309,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
|
||||
}
|
||||
|
||||
feesRequired := types.NewInt(0)
|
||||
nextProvingPeriodEnd := self.ProvingPeriodEnd + ProvingPeriodDuration
|
||||
nextProvingPeriodEnd := self.ProvingPeriodEnd + build.ProvingPeriodDuration
|
||||
if vmctx.BlockHeight() > nextProvingPeriodEnd {
|
||||
return nil, aerrors.New(1, "PoSt submited too late")
|
||||
}
|
||||
@ -338,11 +337,22 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
|
||||
}
|
||||
|
||||
var seed [sectorbuilder.CommLen]byte
|
||||
//TODO
|
||||
{
|
||||
var rand []byte
|
||||
var err ActorError
|
||||
if !lateSubmission {
|
||||
//GetChainRandom(self.ProvingPeriodEnd-PoSTChallangeTime)
|
||||
rand, err = vmctx.GetRandomness(self.ProvingPeriodEnd - build.PoSTChallangeTime)
|
||||
} else {
|
||||
//GetChainRandom(nextProvingPeriodEnd-PoSTChallangeTime)
|
||||
rand, err = vmctx.GetRandomness(nextProvingPeriodEnd - build.PoSTChallangeTime)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, aerrors.Wrap(err, "could not get randomness for PoST")
|
||||
}
|
||||
if len(rand) < len(seed) {
|
||||
return nil, aerrors.Escalate(fmt.Errorf("randomness too small (%d < %d)",
|
||||
len(rand), len(seed)), "improper randomness")
|
||||
}
|
||||
copy(seed[:], rand)
|
||||
}
|
||||
|
||||
pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
|
||||
@ -399,8 +409,6 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
|
||||
return nil, aerrors.Escalate(err, "failed to delete sectors in done set")
|
||||
}
|
||||
|
||||
_ = ss
|
||||
//TODO: Remove done sectors from SectorSet
|
||||
self.ProvingSet, lerr = ss.Flush()
|
||||
if lerr != nil {
|
||||
return nil, aerrors.Escalate(lerr, "could not flish AMT")
|
||||
|
@ -36,6 +36,7 @@ type VMContext interface {
|
||||
StateTree() (StateTree, aerrors.ActorError)
|
||||
VerifySignature(sig *Signature, from address.Address, data []byte) aerrors.ActorError
|
||||
ChargeGas(uint64) aerrors.ActorError
|
||||
GetRandomness(height uint64) ([]byte, aerrors.ActorError)
|
||||
}
|
||||
|
||||
type storageWrapper struct {
|
||||
|
@ -66,6 +66,15 @@ func (vmc *VMContext) Message() *types.Message {
|
||||
return vmc.msg
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, aerrors.Escalate(err, "could not get randomness")
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Storage interface
|
||||
|
||||
func (vmc *VMContext) Put(i cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError) {
|
||||
|
Loading…
Reference in New Issue
Block a user