This commit is contained in:
Łukasz Magiera 2019-11-09 01:18:32 +01:00
parent 3b6c079014
commit 814e01cc05
2 changed files with 5 additions and 5 deletions

View File

@ -38,16 +38,16 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn
if tpow.GreaterThan(zero) {
log2P = int64(tpow.BitLen() - 1)
} else {
// Not really expect to be here ...
// Not really expect to be here ...
return types.EmptyInt, xerrors.Errorf("All power in the net is gone. You network might be disconnected, or the net is dead!")
}
out.Add(out, big.NewInt(log2P << 8))
out.Add(out, big.NewInt(log2P<<8))
// (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den)
eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * build.WRatioNum) << 8)
eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch * build.WRatioDen)))
eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*build.WRatioDen)))
out.Add(out, eWeight)
return types.BigInt{Int: out}, nil

View File

@ -170,7 +170,7 @@ func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
max(h) == 2^256-1
which in terms of integer math means:
(h(vrfout) + 1) * totalPower <= e * minerPower * 2^256
in 2^256 space, it is equivalent to:
in 2^256 space, it is equivalent to:
h(vrfout) * totalPower < e * minerPower * 2^256
*/
@ -183,7 +183,7 @@ func PowerCmp(eproof ElectionProof, mpow, totpow BigInt) bool {
// rhs = minerPower << 256
rhs := new(big.Int).Lsh(mpow.Int, 256)
rhs = rhs.Mul(rhs, blocksPerEpoch.Int)
// h(vrfout) * totalPower < e * minerPower * 2^256?
return lhs.Cmp(rhs) == -1
}