Merge pull request #483 from filecoin-project/feat/set-params

Set proving params matching the spec more closely
This commit is contained in:
Łukasz Magiera 2019-10-28 22:01:45 +01:00 committed by GitHub
commit 5ace5cdbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 61 additions and 38 deletions

View File

@ -33,19 +33,11 @@ func SupportedSectorSize(ssize uint64) bool {
// Blocks
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
// Seconds
const BlockDelay = 3
const BlockDelay = 10
// Seconds
const AllowableClockDrift = BlockDelay * 2
@ -54,19 +46,36 @@ const AllowableClockDrift = BlockDelay * 2
const ForkLengthThreshold = 100
// Blocks (e)
const BlocksPerEpoch = 1
const BlocksPerEpoch = 3
// Blocks
const Finality = 500
// /////
// Proofs / Mining
// Proofs
// 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
const ProvingPeriodDuration = 40
const SealRandomnessLookback = Finality
// /////
// Mining
// Blocks
const PoSTChallangeTime = 35
const EcRandomnessLookback = 300
const PowerCollateralProportion = 5
const PerCapitaCollateralProportion = 1

View File

@ -360,7 +360,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
var seed [sectorbuilder.CommLen]byte
{
randHeight := currentProvingPeriodEnd - build.PoSTChallangeTime
randHeight := currentProvingPeriodEnd - build.PoStChallangeTime - build.PoStRandomnessLookback
if vmctx.BlockHeight() <= randHeight {
// TODO: spec, retcode
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
}
challengeHeight := self.ProvingPeriodEnd - build.PoSTChallangeTime
challengeHeight := self.ProvingPeriodEnd - build.PoStChallangeTime
if vmctx.BlockHeight() < challengeHeight {
// TODO: optimized bitfield methods

View File

@ -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) {
r, err := a.ChainGetRandomness(ctx, ts, ticks, build.RandomnessLookback)
r, err := a.ChainGetRandomness(ctx, ts, ticks, build.EcRandomnessLookback)
if err != nil {
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 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)

View File

@ -495,7 +495,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) 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 {
return xerrors.Errorf("failed to get randomness for verifying election proof: %w", err)
}

View File

@ -3,15 +3,16 @@ package types
import (
"bytes"
"context"
"crypto/sha256"
"math/big"
block "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/minio/sha256-simd"
"github.com/multiformats/go-multihash"
"go.opencensus.io/trace"
xerrors "golang.org/x/xerrors"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/address"
)
@ -159,23 +160,30 @@ func CidArrsEqual(a, b []cid.Cid) bool {
return true
}
var blocksPerEpoch = NewInt(build.BlocksPerEpoch)
func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
/*
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)
// 2^256
rden := BigInt{big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil)}
lhs := BigFromBytes(h[:]).Int
lhs = lhs.Mul(lhs, totpow.Int)
top := BigMul(rden, mpow)
out := BigDiv(top, totpow)
// rhs = minerPower * 2^256 - minerPower
// 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 hp.LessThan(out)
return lhs.Cmp(rhs) == -1
}
func (t *Ticket) Equals(ot *Ticket) bool {

View File

@ -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)
}
// TODO: support multiple blocks in a tipset
// TODO: actually wire this up (miner is undef for now)
gasReward := types.BigMul(msg.GasPrice, gasUsed)
if err := Transfer(gasHolder, miner, gasReward); err != nil {
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 blocksPerEpoch = types.NewInt(build.BlocksPerEpoch)
// MiningReward returns correct mining reward
// 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)
res := ci.Mul(ci, build.InitialReward)
res = res.Div(res, miningRewardTotal.Int)
res = res.Div(res, blocksPerEpoch.Int)
return types.BigInt{res}
}

1
go.mod
View File

@ -61,6 +61,7 @@ require (
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/miekg/dns v1.1.16 // indirect
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/multiformats/go-base32 v0.0.3
github.com/multiformats/go-multiaddr v0.0.4

View File

@ -12,7 +12,7 @@ export class BlockLinks extends React.Component {
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>
})
}
}

View File

@ -169,7 +169,7 @@ class ChainExplorer extends React.Component {
return <div key={row} className={className}>@{h} {info}</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}
</Window>)
}

View File

@ -5,7 +5,7 @@ import Window from "./Window";
function styleForHDiff(max, act) {
switch (max - act) {
case 0:
return {background: '#00aa00'}
return {background: '#004400'}
case 1:
return {background: '#aaaa00'}
default:

View File

@ -171,7 +171,7 @@ func SealTicketGen(api api.FullNode) sector.TicketFn {
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 {
return nil, xerrors.Errorf("getting randomness for SealTicket failed: %w", err)
}
@ -182,7 +182,7 @@ func SealTicketGen(api api.FullNode) sector.TicketFn {
}
return &sectorbuilder.SealTicket{
BlockHeight: ts.Height() - build.RandomnessLookback,
BlockHeight: ts.Height() - build.SealRandomnessLookback,
TicketBytes: tkt,
}, nil
}

View File

@ -44,12 +44,12 @@ func (m *Miner) beginPosting(ctx context.Context) {
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
// TODO: Cancel post
log.Errorf("TODO: Cancel PoSt, re-run")
return nil
}, PoStConfidence, ppe-build.PoSTChallangeTime)
}, PoStConfidence, ppe-build.PoStChallangeTime)
if err != nil {
// TODO: This is BAD, figure something out
log.Errorf("scheduling PoSt failed: %s", err)
@ -82,13 +82,13 @@ func (m *Miner) scheduleNextPost(ppe uint64) {
m.schedPost = ppe
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)
err = m.events.ChainAt(m.computePost(ppe), func(ts *types.TipSet) error { // Revert
// TODO: Cancel post
log.Errorf("TODO: Cancel PoSt, re-run")
return nil
}, PoStConfidence, ppe-build.PoSTChallangeTime)
}, PoStConfidence, ppe-build.PoStChallangeTime)
if err != nil {
// TODO: This is BAD, figure something out
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)
}
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 {
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",
int64(ts.Height())-(int64(ppe)-int64(build.PoSTChallangeTime)),
int64(ts.Height())-(int64(ppe)-int64(build.PoStChallangeTime)),
"chain-random", r, "ppe", ppe, "height", ts.Height())
tsStart := time.Now()