diff --git a/chain/messagepool/selection.go b/chain/messagepool/selection.go index 10ccf6b99..aeb80d53d 100644 --- a/chain/messagepool/selection.go +++ b/chain/messagepool/selection.go @@ -177,16 +177,16 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64 for i := len(chainDeps) - 1; i >= 0; i-- { curChain := chainDeps[i] curChain.merged = true - // adjust the next chain for the parent, which is being merged - if next := curChain.next; next != nil && next.effPerf > 0 { - next.effPerf += next.parentOffset - } result = append(result, curChain.msgs...) } chain.merged = true + // adjust the effective pefromance for all subsequent chains if next := chain.next; next != nil && next.effPerf > 0 { next.effPerf += next.parentOffset + for next = next.next; next != nil && next.effPerf > 0; next = next.next { + next.setEffPerf() + } } result = append(result, chain.msgs...) gasLimit -= chainGasLimit diff --git a/chain/messagepool/selection_test.go b/chain/messagepool/selection_test.go index 0d82c09d8..ff93577c0 100644 --- a/chain/messagepool/selection_test.go +++ b/chain/messagepool/selection_test.go @@ -771,16 +771,26 @@ func TestOptimalMessageSelection2(t *testing.T) { t.Fatalf("expected %d messages, but got %d", expectedMsgs, len(msgs)) } - nextNonce := uint64(0) + var nFrom1, nFrom2 int + var nextNonce1, nextNonce2 uint64 for _, m := range msgs { - if m.Message.From != a2 { - t.Fatal("expected message from a2") + if m.Message.From == a1 { + if m.Message.Nonce != nextNonce1 { + t.Fatalf("expected nonce %d but got %d", nextNonce1, m.Message.Nonce) + } + nextNonce1++ + nFrom1++ + } else { + if m.Message.Nonce != nextNonce2 { + t.Fatalf("expected nonce %d but got %d", nextNonce2, m.Message.Nonce) + } + nextNonce2++ + nFrom2++ } + } - if m.Message.Nonce != nextNonce { - t.Fatalf("expected nonce %d but got %d", nextNonce, m.Message.Nonce) - } - nextNonce++ + if nFrom1 > nFrom2 { + t.Fatalf("expected more messages from a2 than a1; nFrom1=%d nFrom2=%d", nFrom1, nFrom2) } } diff --git a/node/config/def.go b/node/config/def.go index 4fd5a5bd2..2e1243e5b 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -154,8 +154,8 @@ func DefaultStorageMiner() *StorageMiner { }, Fees: MinerFeeConfig{ - MaxPreCommitGasFee: types.FIL(types.FromFil(1)), - MaxCommitGasFee: types.FIL(types.FromFil(1)), + MaxPreCommitGasFee: types.FIL(types.BigDiv(types.FromFil(1), types.NewInt(20))), // 0.05 + MaxCommitGasFee: types.FIL(types.BigDiv(types.FromFil(1), types.NewInt(20))), MaxWindowPoStGasFee: types.FIL(types.FromFil(50)), }, diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 49f07b271..d501af2f7 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -3,6 +3,7 @@ package full import ( "context" "math" + "math/rand" "sort" "github.com/filecoin-project/lotus/build" @@ -26,7 +27,7 @@ type GasAPI struct { Mpool *messagepool.MessagePool } -const MinGasPremium = 10e3 +const MinGasPremium = 100e3 const MaxSpendOnFeeDenom = 100 func (a *GasAPI) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64, @@ -111,6 +112,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, at := build.BlockGasTarget * int64(blocks) / 2 prev := big.Zero() + premium := big.Zero() for _, price := range prices { at -= price.limit if at > 0 { @@ -122,17 +124,27 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, return types.BigAdd(price.price, big.NewInt(1)), nil } - return types.BigAdd(big.Div(types.BigAdd(price.price, prev), types.NewInt(2)), big.NewInt(1)), nil + premium = types.BigAdd(big.Div(types.BigAdd(price.price, prev), types.NewInt(2)), big.NewInt(1)) } - switch nblocksincl { - case 1: - return types.NewInt(2 * MinGasPremium), nil - case 2: - return types.NewInt(1.5 * MinGasPremium), nil - default: - return types.NewInt(MinGasPremium), nil + if types.BigCmp(premium, big.Zero()) == 0 { + switch nblocksincl { + case 1: + premium = types.NewInt(2 * MinGasPremium) + case 2: + premium = types.NewInt(1.5 * MinGasPremium) + default: + premium = types.NewInt(MinGasPremium) + } } + + // add some noise to normalize behaviour of message selection + const precision = 32 + // mean 1, stddev 0.005 => 95% within +-1% + noise := 1 + rand.NormFloat64()*0.005 + premium = types.BigMul(premium, types.NewInt(uint64(noise*(1< maxID { + maxID = i } - nextID++ return nil - }); err != nil && err != stopErr { + }); err != nil { return 0, err } - return uint64(nextID), nil + return uint64(maxID + 1), nil } diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index 15c28039d..ab7b876bc 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/util/adt" + "golang.org/x/xerrors" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" @@ -104,7 +105,8 @@ func InfluxNewBatch() (client.BatchPoints, error) { } func NewPoint(name string, value interface{}) models.Point { - pt, _ := models.NewPoint(name, models.Tags{}, map[string]interface{}{"value": value}, build.Clock.Now()) + pt, _ := models.NewPoint(name, models.Tags{}, + map[string]interface{}{"value": value}, build.Clock.Now().UTC()) return pt } @@ -135,6 +137,7 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti p = NewPoint("chain.basefee", baseFeeFloat) pl.AddPoint(p) + totalGasLimit := int64(0) for _, blockheader := range tipset.Blocks() { bs, err := blockheader.Serialize() if err != nil { @@ -146,7 +149,20 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti p = NewPoint("chain.blockheader_size", len(bs)) pl.AddPoint(p) + + msgs, err := api.ChainGetBlockMessages(ctx, blockheader.Cid()) + if err != nil { + return xerrors.Errorf("ChainGetBlockMessages failed: %w", msgs) + } + for _, m := range msgs.BlsMessages { + totalGasLimit += m.GasLimit + } + for _, m := range msgs.SecpkMessages { + totalGasLimit += m.Message.GasLimit + } } + p = NewPoint("chain.gas_limit_total", totalGasLimit) + pl.AddPoint(p) return nil } @@ -286,8 +302,16 @@ func RecordTipsetMessagesPoints(ctx context.Context, api api.FullNode, pl *Point msgn := make(map[msgTag][]cid.Cid) + totalGasUsed := int64(0) + for _, r := range recp { + totalGasUsed += r.GasUsed + } + p := NewPoint("chain.gas_used_total", totalGasUsed) + pl.AddPoint(p) + for i, msg := range msgs { // FIXME: use float so this doesn't overflow + // FIXME: this doesn't work as time points get overriden p := NewPoint("chain.message_gaspremium", msg.Message.GasPremium.Int64()) pl.AddPoint(p) p = NewPoint("chain.message_gasfeecap", msg.Message.GasFeeCap.Int64())