From 97489f8bf9d70130a9899089a91f25ffc9e2b823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 13 Aug 2020 09:40:19 +0200 Subject: [PATCH 1/8] config: Set lower default max commit maxfee --- node/config/def.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)), }, From 536b2ad9d73f0f9a263c39a73860179a8c61ac4c Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Thu, 13 Aug 2020 10:14:11 -0400 Subject: [PATCH 2/8] fix: paych - bug with allocating lane --- paychmgr/paych_test.go | 106 +++++++++++++++++++++++++++++++++-------- paychmgr/state.go | 14 ++---- 2 files changed, 90 insertions(+), 30 deletions(-) diff --git a/paychmgr/paych_test.go b/paychmgr/paych_test.go index 56aa9ebb2..126e73702 100644 --- a/paychmgr/paych_test.go +++ b/paychmgr/paych_test.go @@ -507,6 +507,15 @@ func TestAddVoucherNextLane(t *testing.T) { require.NoError(t, err) require.EqualValues(t, ci.NextLane, 3) + // Allocate a lane (should be lane 3) + lane, err := mgr.AllocateLane(ch) + require.NoError(t, err) + require.EqualValues(t, lane, 3) + + ci, err = mgr.GetChannelInfo(ch) + require.NoError(t, err) + require.EqualValues(t, ci.NextLane, 4) + // Add a voucher in lane 1 voucherLane = uint64(1) sv = testCreateVoucher(t, ch, voucherLane, nonce, voucherAmount, fromKeyPrivate) @@ -515,17 +524,89 @@ func TestAddVoucherNextLane(t *testing.T) { ci, err = mgr.GetChannelInfo(ch) require.NoError(t, err) - require.EqualValues(t, ci.NextLane, 3) + require.EqualValues(t, ci.NextLane, 4) - // Add a voucher in lane 5 - voucherLane = uint64(5) + // Add a voucher in lane 7 + voucherLane = uint64(7) sv = testCreateVoucher(t, ch, voucherLane, nonce, voucherAmount, fromKeyPrivate) _, err = mgr.AddVoucher(ctx, ch, sv, nil, minDelta) require.NoError(t, err) ci, err = mgr.GetChannelInfo(ch) require.NoError(t, err) - require.EqualValues(t, ci.NextLane, 6) + require.EqualValues(t, ci.NextLane, 8) +} + +func TestAllocateLane(t *testing.T) { + ctx := context.Background() + + // Set up a manager with a single payment channel + mgr, ch, _ := testSetupMgrWithChannel(ctx, t) + + // First lane should be 0 + lane, err := mgr.AllocateLane(ch) + require.NoError(t, err) + require.EqualValues(t, lane, 0) + + // Next lane should be 1 + lane, err = mgr.AllocateLane(ch) + require.NoError(t, err) + require.EqualValues(t, lane, 1) +} + +func TestAllocateLaneWithExistingLaneState(t *testing.T) { + ctx := context.Background() + + _, fromKeyPublic := testGenerateKeyPair(t) + + ch := tutils.NewIDAddr(t, 100) + from := tutils.NewSECP256K1Addr(t, string(fromKeyPublic)) + to := tutils.NewSECP256K1Addr(t, "secpTo") + fromAcct := tutils.NewActorAddr(t, "fromAct") + toAcct := tutils.NewActorAddr(t, "toAct") + + mock := newMockManagerAPI() + mock.setAccountState(fromAcct, account.State{Address: from}) + mock.setAccountState(toAcct, account.State{Address: to}) + + store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) + + actorBalance := big.NewInt(10) + toSend := big.NewInt(1) + laneStates := map[uint64]paych.LaneState{ + 2: { + Nonce: 1, + Redeemed: big.NewInt(4), + }, + } + + act := &types.Actor{ + Code: builtin.AccountActorCodeID, + Head: cid.Cid{}, + Nonce: 0, + Balance: actorBalance, + } + + lsCid, err := mock.storeLaneStates(laneStates) + require.NoError(t, err) + mock.setPaychState(ch, act, paych.State{ + From: fromAcct, + To: toAcct, + ToSend: toSend, + SettlingAt: abi.ChainEpoch(0), + MinSettleHeight: abi.ChainEpoch(0), + LaneStates: lsCid, + }) + + mgr, err := newManager(store, mock) + require.NoError(t, err) + + err = mgr.TrackInboundChannel(ctx, ch) + require.NoError(t, err) + + lane, err := mgr.AllocateLane(ch) + require.NoError(t, err) + require.EqualValues(t, 3, lane) } func TestAddVoucherProof(t *testing.T) { @@ -575,23 +656,6 @@ func TestAddVoucherProof(t *testing.T) { require.Len(t, ci.Vouchers[0].Proof, 1) } -func TestAllocateLane(t *testing.T) { - ctx := context.Background() - - // Set up a manager with a single payment channel - mgr, ch, _ := testSetupMgrWithChannel(ctx, t) - - // First lane should be 0 - lane, err := mgr.AllocateLane(ch) - require.NoError(t, err) - require.EqualValues(t, lane, 0) - - // Next lane should be 1 - lane, err = mgr.AllocateLane(ch) - require.NoError(t, err) - require.EqualValues(t, lane, 1) -} - func TestNextNonceForLane(t *testing.T) { ctx := context.Background() diff --git a/paychmgr/state.go b/paychmgr/state.go index 015479913..db1b8ded2 100644 --- a/paychmgr/state.go +++ b/paychmgr/state.go @@ -2,7 +2,6 @@ package paychmgr import ( "context" - "errors" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -78,18 +77,15 @@ func (ca *stateAccessor) nextLaneFromState(ctx context.Context, st *paych.State) return 0, nil } - nextID := int64(0) - stopErr := errors.New("stop") + maxID := int64(0) if err := laneStates.ForEach(nil, func(i int64) error { - if nextID < i { - // We've found a hole. Stop here. - return stopErr + if i > maxID { + maxID = i } - nextID++ return nil - }); err != nil && err != stopErr { + }); err != nil { return 0, err } - return uint64(nextID), nil + return uint64(maxID + 1), nil } From dd619e85ff2f88282c8bb973f084159d39682e49 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 13 Aug 2020 16:48:29 +0200 Subject: [PATCH 3/8] Add total gas limit to stats Signed-off-by: Jakub Sztandera --- tools/stats/metrics.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index 15c28039d..728570c02 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" @@ -135,6 +136,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 +148,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 } From 3198d2d1e51c39813de9ad42e2ec2b890e42df71 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 13 Aug 2020 16:55:12 +0200 Subject: [PATCH 4/8] Add total gas used Signed-off-by: Jakub Sztandera --- tools/stats/metrics.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index 728570c02..ab7b876bc 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -105,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 } @@ -301,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()) From 2eff03fa1f747b77e7f8003b364b043fae0ac046 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 13 Aug 2020 19:49:07 +0300 Subject: [PATCH 5/8] small fixes in optimal selection 1. Remove noop updates from the previous dependencies 2. Update subsequent dependencies, which was the intention --- chain/messagepool/selection.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From ff7e441c82fa0cec55c57ab8bc1172b9cac4c492 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 13 Aug 2020 18:57:06 +0200 Subject: [PATCH 6/8] Add noise to GasPremium calculation to help out message selection Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 49f07b271..9f7d8907d 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,26 @@ 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) + } } + + 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< Date: Thu, 13 Aug 2020 20:02:08 +0300 Subject: [PATCH 7/8] make selection2 test less touchy --- chain/messagepool/selection_test.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) 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) } } From a6d79b26e449143be17866526ac1fc61e535e916 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 13 Aug 2020 19:27:31 +0200 Subject: [PATCH 8/8] Add comments Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 9f7d8907d..d501af2f7 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -138,6 +138,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, } } + // 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