From 3db6d5c9e98785bb870b956281732365f8acb72f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 10 Sep 2020 12:22:49 +0200 Subject: [PATCH 1/2] Remove PackingEfficiency consideration from base fee in an upgrade Signed-off-by: Jakub Sztandera --- build/params_testground.go | 2 +- chain/store/basefee.go | 18 ++++++++++++------ chain/store/basefee_test.go | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build/params_testground.go b/build/params_testground.go index 50ade70c09c..84dbdb1eefb 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -73,7 +73,7 @@ var ( UpgradeBreezeHeight abi.ChainEpoch = -1 BreezeGasTampingDuration abi.ChainEpoch = 0 - UpgradeSmokeHeight = -1 + UpgradeSmokeHeight abi.ChainEpoch = -1 DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, diff --git a/chain/store/basefee.go b/chain/store/basefee.go index 69970dd9676..4c39bb75be1 100644 --- a/chain/store/basefee.go +++ b/chain/store/basefee.go @@ -11,14 +11,20 @@ import ( "golang.org/x/xerrors" ) -func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int) types.BigInt { - // deta := 1/PackingEfficiency * gasLimitUsed/noOfBlocks - build.BlockGasTarget - // change := baseFee * deta / BlockGasTarget / BaseFeeMaxChangeDenom +func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int, epoch abi.ChainEpoch) types.BigInt { + // deta := gasLimitUsed/noOfBlocks - build.BlockGasTarget + // change := baseFee * deta / BlockGasTarget // nextBaseFee = baseFee + change // nextBaseFee = max(nextBaseFee, build.MinimumBaseFee) - delta := build.PackingEfficiencyDenom * gasLimitUsed / (int64(noOfBlocks) * build.PackingEfficiencyNum) - delta -= build.BlockGasTarget + var delta int64 + if epoch > build.UpgradeSmokeHeight { + delta = gasLimitUsed / int64(noOfBlocks) + delta -= build.BlockGasTarget + } else { + delta = build.PackingEfficiencyDenom * gasLimitUsed / (int64(noOfBlocks) * build.PackingEfficiencyNum) + delta -= build.BlockGasTarget + } // cap change at 12.5% (BaseFeeMaxChangeDenom) by capping delta if delta > build.BlockGasTarget { @@ -73,5 +79,5 @@ func (cs *ChainStore) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi } parentBaseFee := ts.Blocks()[0].ParentBaseFee - return computeNextBaseFee(parentBaseFee, totalLimit, len(ts.Blocks())), nil + return computeNextBaseFee(parentBaseFee, totalLimit, len(ts.Blocks()), ts.Height()), nil } diff --git a/chain/store/basefee_test.go b/chain/store/basefee_test.go index 7a7cae91142..3449246bbaa 100644 --- a/chain/store/basefee_test.go +++ b/chain/store/basefee_test.go @@ -27,7 +27,7 @@ func TestBaseFee(t *testing.T) { for _, test := range tests { test := test t.Run(fmt.Sprintf("%v", test), func(t *testing.T) { - output := computeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks) + output := computeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, 0) assert.Equal(t, fmt.Sprintf("%d", test.output), output.String()) }) } From 2d002349dd7ad30c85e0c5defacdcae1d073f3f7 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 10 Sep 2020 16:26:34 +0200 Subject: [PATCH 2/2] Add additional metrics Signed-off-by: Jakub Sztandera --- chain/store/basefee.go | 4 ++-- chain/store/basefee_test.go | 2 +- tools/stats/metrics.go | 32 ++++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/chain/store/basefee.go b/chain/store/basefee.go index 4c39bb75be1..45785240e5a 100644 --- a/chain/store/basefee.go +++ b/chain/store/basefee.go @@ -11,7 +11,7 @@ import ( "golang.org/x/xerrors" ) -func computeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int, epoch abi.ChainEpoch) types.BigInt { +func ComputeNextBaseFee(baseFee types.BigInt, gasLimitUsed int64, noOfBlocks int, epoch abi.ChainEpoch) types.BigInt { // deta := gasLimitUsed/noOfBlocks - build.BlockGasTarget // change := baseFee * deta / BlockGasTarget // nextBaseFee = baseFee + change @@ -79,5 +79,5 @@ func (cs *ChainStore) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi } parentBaseFee := ts.Blocks()[0].ParentBaseFee - return computeNextBaseFee(parentBaseFee, totalLimit, len(ts.Blocks()), ts.Height()), nil + return ComputeNextBaseFee(parentBaseFee, totalLimit, len(ts.Blocks()), ts.Height()), nil } diff --git a/chain/store/basefee_test.go b/chain/store/basefee_test.go index 3449246bbaa..b4757f70e1c 100644 --- a/chain/store/basefee_test.go +++ b/chain/store/basefee_test.go @@ -27,7 +27,7 @@ func TestBaseFee(t *testing.T) { for _, test := range tests { test := test t.Run(fmt.Sprintf("%v", test), func(t *testing.T) { - output := computeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, 0) + output := ComputeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, 0) assert.Equal(t, fmt.Sprintf("%d", test.output), output.String()) }) } diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index 39fecf47b8e..ae79d927362 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "math" "math/big" "strings" "time" @@ -12,6 +13,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/power" @@ -131,12 +133,6 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti p = NewPoint("chain.blocktime", tsTime.Unix()) pl.AddPoint(p) - baseFeeBig := tipset.Blocks()[0].ParentBaseFee.Copy() - baseFeeRat := new(big.Rat).SetFrac(baseFeeBig.Int, new(big.Int).SetUint64(build.FilecoinPrecision)) - baseFeeFloat, _ := baseFeeRat.Float64() - p = NewPoint("chain.basefee", baseFeeFloat) - pl.AddPoint(p) - totalGasLimit := int64(0) totalUniqGasLimit := int64(0) seen := make(map[cid.Cid]struct{}) @@ -178,6 +174,30 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti p = NewPoint("chain.gas_limit_uniq_total", totalUniqGasLimit) pl.AddPoint(p) + { + baseFeeIn := tipset.Blocks()[0].ParentBaseFee + newBaseFee := store.ComputeNextBaseFee(baseFeeIn, totalUniqGasLimit, len(tipset.Blocks()), tipset.Height()) + + baseFeeRat := new(big.Rat).SetFrac(newBaseFee.Int, new(big.Int).SetUint64(build.FilecoinPrecision)) + baseFeeFloat, _ := baseFeeRat.Float64() + p = NewPoint("chain.basefee", baseFeeFloat) + pl.AddPoint(p) + + baseFeeChange := new(big.Rat).SetFrac(newBaseFee.Int, baseFeeIn.Int) + baseFeeChangeF, _ := baseFeeChange.Float64() + p = NewPoint("chain.basefee_change_log", math.Log(baseFeeChangeF)/math.Log(1.125)) + pl.AddPoint(p) + } + { + blks := len(cids) + p = NewPoint("chain.gas_fill_ratio", float64(totalGasLimit)/float64(blks*build.BlockGasTarget)) + pl.AddPoint(p) + p = NewPoint("chain.gas_capacity_ratio", float64(totalUniqGasLimit)/float64(blks*build.BlockGasTarget)) + pl.AddPoint(p) + p = NewPoint("chain.gas_waste_ratio", float64(totalGasLimit-totalUniqGasLimit)/float64(blks*build.BlockGasTarget)) + pl.AddPoint(p) + } + return nil }