Merge pull request #483 from filecoin-project/feat/set-params
Set proving params matching the spec more closely
This commit is contained in:
commit
5ace5cdbc2
@ -33,19 +33,11 @@ func SupportedSectorSize(ssize uint64) bool {
|
|||||||
// Blocks
|
// Blocks
|
||||||
const PaymentChannelClosingDelay = 6 * 60 * 2 // six hours
|
const PaymentChannelClosingDelay = 6 * 60 * 2 // six hours
|
||||||
|
|
||||||
// Blocks
|
|
||||||
const DealVoucherSkewLimit = 10
|
|
||||||
|
|
||||||
// Blocks
|
|
||||||
const MinDealVoucherIncrement = ProvingPeriodDuration
|
|
||||||
|
|
||||||
const MaxVouchersPerDeal = 768 // roughly one voucher per 10h over a year
|
|
||||||
|
|
||||||
// /////
|
// /////
|
||||||
// Consensus / Network
|
// Consensus / Network
|
||||||
|
|
||||||
// Seconds
|
// Seconds
|
||||||
const BlockDelay = 3
|
const BlockDelay = 10
|
||||||
|
|
||||||
// Seconds
|
// Seconds
|
||||||
const AllowableClockDrift = BlockDelay * 2
|
const AllowableClockDrift = BlockDelay * 2
|
||||||
@ -54,19 +46,36 @@ const AllowableClockDrift = BlockDelay * 2
|
|||||||
const ForkLengthThreshold = 100
|
const ForkLengthThreshold = 100
|
||||||
|
|
||||||
// Blocks (e)
|
// Blocks (e)
|
||||||
const BlocksPerEpoch = 1
|
const BlocksPerEpoch = 3
|
||||||
|
|
||||||
|
// Blocks
|
||||||
|
const Finality = 500
|
||||||
|
|
||||||
// /////
|
// /////
|
||||||
// Proofs / Mining
|
// Proofs
|
||||||
|
|
||||||
// Blocks
|
// Blocks
|
||||||
const RandomnessLookback = 20
|
const ProvingPeriodDuration = 60
|
||||||
|
|
||||||
|
// PoStChallangeTime sets the window in which post computation should happen
|
||||||
|
// Blocks
|
||||||
|
const PoStChallangeTime = ProvingPeriodDuration - 6
|
||||||
|
|
||||||
|
// PoStRandomnessLookback is additional randomness lookback for PoSt computation
|
||||||
|
// To compute randomness epoch in a given proving period:
|
||||||
|
// RandH = PPE - PoStChallangeTime - PoStRandomnessLookback
|
||||||
|
//
|
||||||
|
// Blocks
|
||||||
|
const PoStRandomnessLookback = 1
|
||||||
|
|
||||||
// Blocks
|
// Blocks
|
||||||
const ProvingPeriodDuration = 40
|
const SealRandomnessLookback = Finality
|
||||||
|
|
||||||
|
// /////
|
||||||
|
// Mining
|
||||||
|
|
||||||
// Blocks
|
// Blocks
|
||||||
const PoSTChallangeTime = 35
|
const EcRandomnessLookback = 300
|
||||||
|
|
||||||
const PowerCollateralProportion = 5
|
const PowerCollateralProportion = 5
|
||||||
const PerCapitaCollateralProportion = 1
|
const PerCapitaCollateralProportion = 1
|
||||||
|
@ -360,7 +360,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
|
|||||||
|
|
||||||
var seed [sectorbuilder.CommLen]byte
|
var seed [sectorbuilder.CommLen]byte
|
||||||
{
|
{
|
||||||
randHeight := currentProvingPeriodEnd - build.PoSTChallangeTime
|
randHeight := currentProvingPeriodEnd - build.PoStChallangeTime - build.PoStRandomnessLookback
|
||||||
if vmctx.BlockHeight() <= randHeight {
|
if vmctx.BlockHeight() <= randHeight {
|
||||||
// TODO: spec, retcode
|
// TODO: spec, retcode
|
||||||
return nil, aerrors.Newf(1, "submit PoSt called outside submission window (%d < %d)", vmctx.BlockHeight(), randHeight)
|
return nil, aerrors.Newf(1, "submit PoSt called outside submission window (%d < %d)", vmctx.BlockHeight(), randHeight)
|
||||||
@ -658,7 +658,7 @@ func (sma StorageMinerActor) AddFaults(act *types.Actor, vmctx types.VMContext,
|
|||||||
return nil, aerr
|
return nil, aerr
|
||||||
}
|
}
|
||||||
|
|
||||||
challengeHeight := self.ProvingPeriodEnd - build.PoSTChallangeTime
|
challengeHeight := self.ProvingPeriodEnd - build.PoStChallangeTime
|
||||||
|
|
||||||
if vmctx.BlockHeight() < challengeHeight {
|
if vmctx.BlockHeight() < challengeHeight {
|
||||||
// TODO: optimized bitfield methods
|
// TODO: optimized bitfield methods
|
||||||
|
@ -399,7 +399,7 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsRoundWinner(ctx context.Context, ts *types.TipSet, ticks []*types.Ticket, miner address.Address, a MiningCheckAPI) (bool, types.ElectionProof, error) {
|
func IsRoundWinner(ctx context.Context, ts *types.TipSet, ticks []*types.Ticket, miner address.Address, a MiningCheckAPI) (bool, types.ElectionProof, error) {
|
||||||
r, err := a.ChainGetRandomness(ctx, ts, ticks, build.RandomnessLookback)
|
r, err := a.ChainGetRandomness(ctx, ts, ticks, build.EcRandomnessLookback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, xerrors.Errorf("chain get randomness: %w", err)
|
return false, nil, xerrors.Errorf("chain get randomness: %w", err)
|
||||||
}
|
}
|
||||||
@ -419,7 +419,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, ticks []*types.Ticket,
|
|||||||
return false, nil, xerrors.Errorf("failed to check power: %w", err)
|
return false, nil, xerrors.Errorf("failed to check power: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.PowerCmp(vrfout, types.BigMul(pow.MinerPower, types.NewInt(build.BlocksPerEpoch)), pow.TotalPower), vrfout, nil
|
return types.PowerCmp(vrfout, pow.MinerPower, pow.TotalPower), vrfout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignFunc func(context.Context, address.Address, []byte) (*types.Signature, error)
|
type SignFunc func(context.Context, address.Address, []byte) (*types.Signature, error)
|
||||||
|
@ -495,7 +495,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
|||||||
return xerrors.Errorf("validating block tickets failed: %w", err)
|
return xerrors.Errorf("validating block tickets failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), h.Tickets, build.RandomnessLookback)
|
rand, err := syncer.sm.ChainStore().GetRandomness(ctx, baseTs.Cids(), h.Tickets, build.EcRandomnessLookback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err)
|
return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,16 @@ package types
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
block "github.com/ipfs/go-block-format"
|
block "github.com/ipfs/go-block-format"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
|
"github.com/minio/sha256-simd"
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/address"
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -159,23 +160,30 @@ func CidArrsEqual(a, b []cid.Cid) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var blocksPerEpoch = NewInt(build.BlocksPerEpoch)
|
||||||
|
|
||||||
func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
|
func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Need to check that
|
Need to check that
|
||||||
h(vrfout) / 2^256 < minerPower / totalPower
|
h(vrfout) / max(h) < e * minerPower / totalPower
|
||||||
|
max(h) == 2^256-1
|
||||||
|
which in terms of integer math means:
|
||||||
|
h(vrfout) * totalPower < e * minerPower * (2^256-1)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
h := sha256.Sum256(eproof)
|
h := sha256.Sum256(eproof)
|
||||||
|
|
||||||
// 2^256
|
lhs := BigFromBytes(h[:]).Int
|
||||||
rden := BigInt{big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil)}
|
lhs = lhs.Mul(lhs, totpow.Int)
|
||||||
|
|
||||||
top := BigMul(rden, mpow)
|
// rhs = minerPower * 2^256 - minerPower
|
||||||
out := BigDiv(top, totpow)
|
// rhs = minerPower << 256 - minerPower
|
||||||
|
rhs := new(big.Int).Lsh(mpow.Int, 256)
|
||||||
|
rhs = rhs.Mul(rhs, blocksPerEpoch.Int)
|
||||||
|
rhs = rhs.Sub(rhs, mpow.Int)
|
||||||
|
|
||||||
hp := BigFromBytes(h[:])
|
return lhs.Cmp(rhs) == -1
|
||||||
return hp.LessThan(out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Ticket) Equals(ot *Ticket) bool {
|
func (t *Ticket) Equals(ot *Ticket) bool {
|
||||||
|
@ -488,6 +488,9 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
return nil, xerrors.Errorf("getting block miner actor (%s) failed: %w", vm.blockMiner, err)
|
return nil, xerrors.Errorf("getting block miner actor (%s) failed: %w", vm.blockMiner, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: support multiple blocks in a tipset
|
||||||
|
// TODO: actually wire this up (miner is undef for now)
|
||||||
gasReward := types.BigMul(msg.GasPrice, gasUsed)
|
gasReward := types.BigMul(msg.GasPrice, gasUsed)
|
||||||
if err := Transfer(gasHolder, miner, gasReward); err != nil {
|
if err := Transfer(gasHolder, miner, gasReward); err != nil {
|
||||||
return nil, xerrors.Errorf("failed to give miner gas reward: %w", err)
|
return nil, xerrors.Errorf("failed to give miner gas reward: %w", err)
|
||||||
@ -630,6 +633,7 @@ func depositFunds(act *types.Actor, amt types.BigInt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var miningRewardTotal = types.FromFil(build.MiningRewardTotal)
|
var miningRewardTotal = types.FromFil(build.MiningRewardTotal)
|
||||||
|
var blocksPerEpoch = types.NewInt(build.BlocksPerEpoch)
|
||||||
|
|
||||||
// MiningReward returns correct mining reward
|
// MiningReward returns correct mining reward
|
||||||
// coffer is amount of FIL in NetworkAddress
|
// coffer is amount of FIL in NetworkAddress
|
||||||
@ -637,5 +641,6 @@ func MiningReward(remainingReward types.BigInt) types.BigInt {
|
|||||||
ci := big.NewInt(0).Set(remainingReward.Int)
|
ci := big.NewInt(0).Set(remainingReward.Int)
|
||||||
res := ci.Mul(ci, build.InitialReward)
|
res := ci.Mul(ci, build.InitialReward)
|
||||||
res = res.Div(res, miningRewardTotal.Int)
|
res = res.Div(res, miningRewardTotal.Int)
|
||||||
|
res = res.Div(res, blocksPerEpoch.Int)
|
||||||
return types.BigInt{res}
|
return types.BigInt{res}
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -61,6 +61,7 @@ require (
|
|||||||
github.com/mattn/go-runewidth v0.0.4 // indirect
|
github.com/mattn/go-runewidth v0.0.4 // indirect
|
||||||
github.com/miekg/dns v1.1.16 // indirect
|
github.com/miekg/dns v1.1.16 // indirect
|
||||||
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
|
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
|
||||||
|
github.com/minio/sha256-simd v0.1.0
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/multiformats/go-base32 v0.0.3
|
github.com/multiformats/go-base32 v0.0.3
|
||||||
github.com/multiformats/go-multiaddr v0.0.4
|
github.com/multiformats/go-multiaddr v0.0.4
|
||||||
|
@ -12,7 +12,7 @@ export class BlockLinks extends React.Component {
|
|||||||
block = this.props.blocks[k]
|
block = this.props.blocks[k]
|
||||||
}
|
}
|
||||||
|
|
||||||
return <BlockLink key={c + '-' + k} block={block} conn={this.props.conn} cid={c} mountWindow={this.props.mountWindow}/>
|
return <span><BlockLink key={c + '-' + k} block={block} conn={this.props.conn} cid={c} mountWindow={this.props.mountWindow}/> </span>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class ChainExplorer extends React.Component {
|
|||||||
return <div key={row} className={className}>@{h} {info}</div>
|
return <div key={row} className={className}>@{h} {info}</div>
|
||||||
})}</div>
|
})}</div>
|
||||||
|
|
||||||
return (<Window onClose={this.props.onClose} title={`Chain Explorer ${this.state.follow ? '(Following)' : ''}`}>
|
return (<Window initialSize={{width: 800}} onClose={this.props.onClose} title={`Chain Explorer ${this.state.follow ? '(Following)' : ''}`}>
|
||||||
{content}
|
{content}
|
||||||
</Window>)
|
</Window>)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import Window from "./Window";
|
|||||||
function styleForHDiff(max, act) {
|
function styleForHDiff(max, act) {
|
||||||
switch (max - act) {
|
switch (max - act) {
|
||||||
case 0:
|
case 0:
|
||||||
return {background: '#00aa00'}
|
return {background: '#004400'}
|
||||||
case 1:
|
case 1:
|
||||||
return {background: '#aaaa00'}
|
return {background: '#aaaa00'}
|
||||||
default:
|
default:
|
||||||
|
@ -171,7 +171,7 @@ func SealTicketGen(api api.FullNode) sector.TicketFn {
|
|||||||
return nil, xerrors.Errorf("getting head ts for SealTicket failed: %w", err)
|
return nil, xerrors.Errorf("getting head ts for SealTicket failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := api.ChainGetRandomness(ctx, ts, nil, build.RandomnessLookback)
|
r, err := api.ChainGetRandomness(ctx, ts, nil, build.SealRandomnessLookback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err)
|
return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ func SealTicketGen(api api.FullNode) sector.TicketFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return §orbuilder.SealTicket{
|
return §orbuilder.SealTicket{
|
||||||
BlockHeight: ts.Height() - build.RandomnessLookback,
|
BlockHeight: ts.Height() - build.SealRandomnessLookback,
|
||||||
TicketBytes: tkt,
|
TicketBytes: tkt,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,12 @@ func (m *Miner) beginPosting(ctx context.Context) {
|
|||||||
|
|
||||||
m.schedLk.Unlock()
|
m.schedLk.Unlock()
|
||||||
|
|
||||||
log.Infof("Scheduling post at height %d", ppe-build.PoSTChallangeTime)
|
log.Infof("Scheduling post at height %d", ppe-build.PoStChallangeTime)
|
||||||
err = m.events.ChainAt(m.computePost(m.schedPost), func(ts *types.TipSet) error { // Revert
|
err = m.events.ChainAt(m.computePost(m.schedPost), func(ts *types.TipSet) error { // Revert
|
||||||
// TODO: Cancel post
|
// TODO: Cancel post
|
||||||
log.Errorf("TODO: Cancel PoSt, re-run")
|
log.Errorf("TODO: Cancel PoSt, re-run")
|
||||||
return nil
|
return nil
|
||||||
}, PoStConfidence, ppe-build.PoSTChallangeTime)
|
}, PoStConfidence, ppe-build.PoStChallangeTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: This is BAD, figure something out
|
// TODO: This is BAD, figure something out
|
||||||
log.Errorf("scheduling PoSt failed: %s", err)
|
log.Errorf("scheduling PoSt failed: %s", err)
|
||||||
@ -82,13 +82,13 @@ func (m *Miner) scheduleNextPost(ppe uint64) {
|
|||||||
m.schedPost = ppe
|
m.schedPost = ppe
|
||||||
m.schedLk.Unlock()
|
m.schedLk.Unlock()
|
||||||
|
|
||||||
log.Infow("scheduling PoSt", "post-height", ppe-build.PoSTChallangeTime,
|
log.Infow("scheduling PoSt", "post-height", ppe-build.PoStChallangeTime,
|
||||||
"height", ts.Height(), "ppe", ppe, "proving-period", provingPeriod)
|
"height", ts.Height(), "ppe", ppe, "proving-period", provingPeriod)
|
||||||
err = m.events.ChainAt(m.computePost(ppe), func(ts *types.TipSet) error { // Revert
|
err = m.events.ChainAt(m.computePost(ppe), func(ts *types.TipSet) error { // Revert
|
||||||
// TODO: Cancel post
|
// TODO: Cancel post
|
||||||
log.Errorf("TODO: Cancel PoSt, re-run")
|
log.Errorf("TODO: Cancel PoSt, re-run")
|
||||||
return nil
|
return nil
|
||||||
}, PoStConfidence, ppe-build.PoSTChallangeTime)
|
}, PoStConfidence, ppe-build.PoStChallangeTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: This is BAD, figure something out
|
// TODO: This is BAD, figure something out
|
||||||
log.Errorf("scheduling PoSt failed: %+v", err)
|
log.Errorf("scheduling PoSt failed: %+v", err)
|
||||||
@ -113,13 +113,13 @@ func (m *Miner) computePost(ppe uint64) func(ts *types.TipSet, curH uint64) erro
|
|||||||
return xerrors.Errorf("failed to get proving set for miner: %w", err)
|
return xerrors.Errorf("failed to get proving set for miner: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoSTChallangeTime))) // TODO: review: check math
|
r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoStChallangeTime)+int64(build.PoStRandomnessLookback))) // TODO: review: check math
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to get chain randomness for post (ts=%d; ppe=%d): %w", ts.Height(), ppe, err)
|
return xerrors.Errorf("failed to get chain randomness for post (ts=%d; ppe=%d): %w", ts.Height(), ppe, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infow("running PoSt", "delayed-by",
|
log.Infow("running PoSt", "delayed-by",
|
||||||
int64(ts.Height())-(int64(ppe)-int64(build.PoSTChallangeTime)),
|
int64(ts.Height())-(int64(ppe)-int64(build.PoStChallangeTime)),
|
||||||
"chain-random", r, "ppe", ppe, "height", ts.Height())
|
"chain-random", r, "ppe", ppe, "height", ts.Height())
|
||||||
|
|
||||||
tsStart := time.Now()
|
tsStart := time.Now()
|
||||||
|
Loading…
Reference in New Issue
Block a user