From f35c8fe4268e2e8d8aeddc631a10db0fe10782bf Mon Sep 17 00:00:00 2001 From: steven004 Date: Thu, 31 Oct 2019 18:11:57 +0800 Subject: [PATCH 1/3] No AdjustmentPeriod anyu more --- build/params.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/build/params.go b/build/params.go index e810ff45f..699a21399 100644 --- a/build/params.go +++ b/build/params.go @@ -97,9 +97,6 @@ const FilecoinPrecision = 1000000000000000000 // Blocks const HalvingPeriodBlocks = 6 * 365 * 24 * 60 * 2 -// Blocks -const AdjustmentPeriod = 7 * 24 * 60 * 2 - // TODO: Move other important consts here func init() { From a917ffee16d8e1efde4134bab447c1208745bccf Mon Sep 17 00:00:00 2001 From: steven004 Date: Thu, 31 Oct 2019 18:54:13 +0800 Subject: [PATCH 2/3] minor code change, no function impact --- build/params.go | 5 +++++ chain/store/weight.go | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build/params.go b/build/params.go index 699a21399..d6453f6f5 100644 --- a/build/params.go +++ b/build/params.go @@ -97,6 +97,11 @@ const FilecoinPrecision = 1000000000000000000 // Blocks const HalvingPeriodBlocks = 6 * 365 * 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 func init() { diff --git a/chain/store/weight.go b/chain/store/weight.go index 7c1f80ceb..3f52112cb 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -11,6 +11,8 @@ import ( ) var zero = types.NewInt(0) +var wRatio_num = build.WRatioNum +var wRatio_den = build.WRatioDen func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) { if ts == nil { @@ -37,17 +39,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. 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())) * wRatio_num) << 8) + eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch * wRatio_den))) out.Add(out, eWeight) return types.BigInt{Int: out}, nil From dd8642c43cf8488a86117f02d56d833d0b67abf3 Mon Sep 17 00:00:00 2001 From: steven004 Date: Fri, 1 Nov 2019 09:43:22 +0800 Subject: [PATCH 3/3] Omit double delaration --- chain/store/weight.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/chain/store/weight.go b/chain/store/weight.go index 3f52112cb..999166f89 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -11,8 +11,6 @@ import ( ) var zero = types.NewInt(0) -var wRatio_num = build.WRatioNum -var wRatio_den = build.WRatioDen func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) { if ts == nil { @@ -41,15 +39,15 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn log2P = int64(tpow.BitLen() - 1) } else { // Not really expect to be here ... - return types.EmptyInt, xerrors.Errorf("All power in the net is gone. The net is dead!") + 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)) // (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) - eWeight := big.NewInt((log2P * int64(len(ts.Blocks())) * wRatio_num) << 8) - eWeight.Div(eWeight, big.NewInt(int64(build.BlocksPerEpoch * wRatio_den))) + 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