Merge pull request #3580 from filecoin-project/fix/mpool-selection-bug
fix selection bug; priority messages were not included if other chains were negative
This commit is contained in:
commit
5e97e29f95
@ -34,6 +34,8 @@ type testMpoolAPI struct {
|
|||||||
tipsets []*types.TipSet
|
tipsets []*types.TipSet
|
||||||
|
|
||||||
published int
|
published int
|
||||||
|
|
||||||
|
baseFee types.BigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestMpoolAPI() *testMpoolAPI {
|
func newTestMpoolAPI() *testMpoolAPI {
|
||||||
@ -41,6 +43,7 @@ func newTestMpoolAPI() *testMpoolAPI {
|
|||||||
bmsgs: make(map[cid.Cid][]*types.SignedMessage),
|
bmsgs: make(map[cid.Cid][]*types.SignedMessage),
|
||||||
statenonce: make(map[address.Address]uint64),
|
statenonce: make(map[address.Address]uint64),
|
||||||
balance: make(map[address.Address]types.BigInt),
|
balance: make(map[address.Address]types.BigInt),
|
||||||
|
baseFee: types.NewInt(100),
|
||||||
}
|
}
|
||||||
genesis := mock.MkBlock(nil, 1, 1)
|
genesis := mock.MkBlock(nil, 1, 1)
|
||||||
tma.tipsets = append(tma.tipsets, mock.TipSet(genesis))
|
tma.tipsets = append(tma.tipsets, mock.TipSet(genesis))
|
||||||
@ -182,7 +185,7 @@ func (tma *testMpoolAPI) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolAPI) ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
func (tma *testMpoolAPI) ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
||||||
return types.NewInt(100), nil
|
return tma.baseFee, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertNonce(t *testing.T, mp *MessagePool, addr address.Address, val uint64) {
|
func assertNonce(t *testing.T, mp *MessagePool, addr address.Address, val uint64) {
|
||||||
|
@ -102,7 +102,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
|
|||||||
|
|
||||||
if len(chains) != 0 && chains[0].gasPerf < 0 {
|
if len(chains) != 0 && chains[0].gasPerf < 0 {
|
||||||
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
|
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
|
||||||
return nil, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Parition chains into blocks (without trimming)
|
// 3. Parition chains into blocks (without trimming)
|
||||||
@ -351,7 +351,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
|
|||||||
|
|
||||||
if len(chains) != 0 && chains[0].gasPerf < 0 {
|
if len(chains) != 0 && chains[0].gasPerf < 0 {
|
||||||
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
|
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
|
||||||
return nil, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Merge the head chains to produce the list of messages selected for inclusion, subject to
|
// 3. Merge the head chains to produce the list of messages selected for inclusion, subject to
|
||||||
|
@ -728,6 +728,100 @@ func TestPriorityMessageSelection2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPriorityMessageSelection3(t *testing.T) {
|
||||||
|
mp, tma := makeTestMpool()
|
||||||
|
|
||||||
|
// the actors
|
||||||
|
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a1, err := w1.GenerateKey(crypto.SigTypeSecp256k1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a2, err := w2.GenerateKey(crypto.SigTypeSecp256k1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
block := tma.nextBlock()
|
||||||
|
ts := mock.TipSet(block)
|
||||||
|
tma.applyBlock(t, block)
|
||||||
|
|
||||||
|
gasLimit := gasguess.Costs[gasguess.CostKey{Code: builtin.StorageMarketActorCodeID, M: 2}]
|
||||||
|
|
||||||
|
tma.setBalance(a1, 1) // in FIL
|
||||||
|
tma.setBalance(a2, 1) // in FIL
|
||||||
|
|
||||||
|
mp.cfg.PriorityAddrs = []address.Address{a1}
|
||||||
|
|
||||||
|
tma.baseFee = types.NewInt(1000)
|
||||||
|
nMessages := 10
|
||||||
|
for i := 0; i < nMessages; i++ {
|
||||||
|
bias := (nMessages - i) / 3
|
||||||
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(1000+i%3+bias))
|
||||||
|
mustAdd(t, mp, m)
|
||||||
|
// messages from a2 have negative performance
|
||||||
|
m = makeTestMessage(w2, a2, a1, uint64(i), gasLimit, 100)
|
||||||
|
mustAdd(t, mp, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// test greedy selection
|
||||||
|
msgs, err := mp.SelectMessages(ts, 1.0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedMsgs := 10
|
||||||
|
if len(msgs) != expectedMsgs {
|
||||||
|
t.Fatalf("expected %d messages but got %d", expectedMsgs, len(msgs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// all messages must be from a1
|
||||||
|
nextNonce := uint64(0)
|
||||||
|
for _, m := range msgs {
|
||||||
|
if m.Message.From != a1 {
|
||||||
|
t.Fatal("expected messages from a1 before messages from a2")
|
||||||
|
}
|
||||||
|
if m.Message.Nonce != nextNonce {
|
||||||
|
t.Fatalf("expected nonce %d but got %d", nextNonce, m.Message.Nonce)
|
||||||
|
}
|
||||||
|
nextNonce++
|
||||||
|
}
|
||||||
|
|
||||||
|
// test optimal selection
|
||||||
|
msgs, err = mp.SelectMessages(ts, 0.1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedMsgs = 10
|
||||||
|
if len(msgs) != expectedMsgs {
|
||||||
|
t.Fatalf("expected %d messages but got %d", expectedMsgs, len(msgs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// all messages must be from a1
|
||||||
|
nextNonce = uint64(0)
|
||||||
|
for _, m := range msgs {
|
||||||
|
if m.Message.From != a1 {
|
||||||
|
t.Fatal("expected messages from a1 before messages from a2")
|
||||||
|
}
|
||||||
|
if m.Message.Nonce != nextNonce {
|
||||||
|
t.Fatalf("expected nonce %d but got %d", nextNonce, m.Message.Nonce)
|
||||||
|
}
|
||||||
|
nextNonce++
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestOptimalMessageSelection1(t *testing.T) {
|
func TestOptimalMessageSelection1(t *testing.T) {
|
||||||
// this test uses just a single actor sending messages with a low tq
|
// this test uses just a single actor sending messages with a low tq
|
||||||
// the chain depenent merging algorithm should pick messages from the actor
|
// the chain depenent merging algorithm should pick messages from the actor
|
||||||
|
Loading…
Reference in New Issue
Block a user