diff --git a/miner/miner_test.go b/miner/miner_test.go index c6741531b6..2c07c542e6 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -170,3 +170,74 @@ func wrapMsgs(msgs []types.Message) []*types.SignedMessage { } return out } + +func TestMessageFilteringSenderHopping(t *testing.T) { + ctx := context.TODO() + a1 := mustIDAddr(1) + a2 := mustIDAddr(2) + + actors := map[address.Address]*types.Actor{ + a1: { + Nonce: 0, + Balance: types.FromFil(1200), + }, + a2: { + Nonce: 0, + Balance: types.FromFil(1000), + }, + } + + af := func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) { + return actors[addr], nil + } + + msgs := []types.Message{ + { + From: a1, + To: a1, + Nonce: 0, + Value: types.FromFil(500), + GasLimit: 2_000_000_000, + GasPrice: types.NewInt(100), + }, + { + From: a1, + To: a1, + Nonce: 1, + Value: types.FromFil(500), + GasLimit: 2_000_000_000, + GasPrice: types.NewInt(1), + }, + { + From: a2, + To: a1, + Nonce: 0, + Value: types.FromFil(1), + GasLimit: 1_000_000_000, + GasPrice: types.NewInt(10), + }, + { + From: a2, + To: a1, + Nonce: 1, + Value: types.FromFil(1), + GasLimit: 1_000_000_000, + GasPrice: types.NewInt(1), + }, + { + From: a2, + To: a1, + Nonce: 2, + Value: types.FromFil(1), + GasLimit: 100_000_000, + GasPrice: types.NewInt(1), + }, + } + + outmsgs, err := SelectMessages(ctx, af, &types.TipSet{}, wrapMsgs(msgs)) + if err != nil { + t.Fatal(err) + } + + assert.Len(t, outmsgs, 5, "filtering didnt work as expected") +} diff --git a/miner/selectmessages.go b/miner/selectmessages.go index 65f0154cb7..834a955f2e 100644 --- a/miner/selectmessages.go +++ b/miner/selectmessages.go @@ -87,6 +87,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS getbal += build.Clock.Since(getBalStart) if inclBalances[from].LessThan(msg.Message.RequiredFunds()) { + log.Warnf("message had too low funds: %s %d %s %s %s", from, msg.Message.Nonce, inclBalances[from], msg.Message.Value, msg.Message.RequiredFunds()) tooLowFundMsgs++ // todo: drop from mpool continue @@ -175,17 +176,27 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS } if nBest == 0 { + log.Warning("nBest is zero: ", gasLimitLeft) break // block gas limit reached } { out = append(out, outBySender[bestSender].msgs[:nBest]...) - gasLimitLeft -= outBySender[bestSender].gasLimit[nBest-1] + + seqGasLimit := outBySender[bestSender].gasLimit[nBest-1] + seqGasReward := outBySender[bestSender].gasReward[nBest-1] + + gasLimitLeft -= seqGasLimit outBySender[bestSender].msgs = outBySender[bestSender].msgs[nBest:] outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:] outBySender[bestSender].gasReward = outBySender[bestSender].gasReward[nBest:] + for i := range outBySender[bestSender].gasLimit { + outBySender[bestSender].gasLimit[i] -= seqGasLimit + outBySender[bestSender].gasReward[i] = big.Sub(outBySender[bestSender].gasReward[i], seqGasReward) + } + if len(outBySender[bestSender].msgs) == 0 { delete(outBySender, bestSender) }