Merge pull request #2891 from filecoin-project/feat/mpool-negative-chain-pruning

some small improvements in the handling of non-performing chains
This commit is contained in:
Łukasz Magiera 2020-08-07 10:14:09 +02:00 committed by GitHub
commit 5a50d293b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,6 +52,7 @@ func (mp *MessagePool) selectMessages(curTs, ts *types.TipSet) ([]*types.SignedM
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(pending) == 0 { if len(pending) == 0 {
return nil, nil return nil, nil
} }
@ -72,11 +73,9 @@ func (mp *MessagePool) selectMessages(curTs, ts *types.TipSet) ([]*types.SignedM
sort.Slice(chains, func(i, j int) bool { sort.Slice(chains, func(i, j int) bool {
return chains[i].Before(chains[j]) return chains[i].Before(chains[j])
}) })
if len(chains) != 0 && chains[0].gasPerf < 0 {
log.Warnw("all messages in mpool have negative has performance", "bestGasPerf", chains[0].gasPerf) if len(chains) != 0 && chains[0].gasPerf <= 0 {
//for i, m := range chains[0].msgs { log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
//log.Warnf("msg %d %+v", i, m.Message)
//}
return nil, nil return nil, nil
} }
@ -94,6 +93,11 @@ func (mp *MessagePool) selectMessages(curTs, ts *types.TipSet) ([]*types.SignedM
continue continue
} }
// did we run out of performing chains?
if chain.gasPerf <= 0 {
break
}
// we can't fit this chain because of block gasLimit -- we are at the edge // we can't fit this chain because of block gasLimit -- we are at the edge
last = i last = i
break break
@ -132,6 +136,12 @@ tailLoop:
result = append(result, chain.msgs...) result = append(result, chain.msgs...)
continue continue
} }
// if gasPerf <= 0 we have no more profitable chains
if chain.gasPerf <= 0 {
break tailLoop
}
// this chain needs to be trimmed // this chain needs to be trimmed
last += i last += i
continue tailLoop continue tailLoop
@ -427,7 +437,7 @@ func (mc *msgChain) Before(other *msgChain) bool {
func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt, ts *types.TipSet) { func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt, ts *types.TipSet) {
i := len(mc.msgs) - 1 i := len(mc.msgs) - 1
for i >= 0 && mc.gasLimit > gasLimit { for i >= 0 && (mc.gasLimit > gasLimit || mc.gasPerf < 0) {
gasLimit -= mc.msgs[i].Message.GasLimit gasLimit -= mc.msgs[i].Message.GasLimit
gasReward := mp.getGasReward(mc.msgs[i], baseFee, ts) gasReward := mp.getGasReward(mc.msgs[i], baseFee, ts)
mc.gasReward = new(big.Int).Sub(mc.gasReward, gasReward) mc.gasReward = new(big.Int).Sub(mc.gasReward, gasReward)