diff --git a/build/params.go b/build/params.go index 41d832b5c..39aadaaa1 100644 --- a/build/params.go +++ b/build/params.go @@ -103,8 +103,10 @@ const FilecoinPrecision = 1_000_000_000_000_000_000 // Blocks const HalvingPeriodBlocks = 6 * 365 * 24 * 60 * 2 -// Blocks -const AdjustmentPeriod = 7 * 24 * 60 * 2 +// constants for Weight calculation +// The ratio of weight contributed by short-term vs long-term factors in a given round +const WRatioNum = int64(1) +const WRatioDen = 2 // TODO: Move other important consts here diff --git a/chain/store/weight.go b/chain/store/weight.go index 7c1f80ceb..999166f89 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -37,17 +37,17 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn tpow := types.BigFromBytes(ret.Return) if tpow.GreaterThan(zero) { log2P = int64(tpow.BitLen() - 1) + } else { + // 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*256)) + out.Add(out, big.NewInt(log2P << 8)) // (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) - wRatioNum := int64(1) - wRatioDen := 2 - - eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * wRatioNum) << 8) - eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch*wRatioDen))) + eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * build.WRatioNum) << 8) + eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch * build.WRatioDen))) out.Add(out, eWeight) return types.BigInt{Int: out}, nil