Merge pull request #2909 from filecoin-project/fix/mpool-bug

fix mpool bugs
This commit is contained in:
Łukasz Magiera 2020-08-08 01:32:28 +02:00 committed by GitHub
commit e65db33d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -385,6 +385,7 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
curNonce := a.Nonce curNonce := a.Nonce
balance := a.Balance.Int balance := a.Balance.Int
gasLimit := int64(0) gasLimit := int64(0)
skip := 0
i := 0 i := 0
rewards := make([]*big.Int, 0, len(msgs)) rewards := make([]*big.Int, 0, len(msgs))
for i = 0; i < len(msgs); i++ { for i = 0; i < len(msgs); i++ {
@ -393,6 +394,7 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
if m.Message.Nonce < curNonce { if m.Message.Nonce < curNonce {
log.Warnf("encountered message from actor %s with nonce (%d) less than the current nonce (%d)", log.Warnf("encountered message from actor %s with nonce (%d) less than the current nonce (%d)",
actor, m.Message.Nonce, curNonce) actor, m.Message.Nonce, curNonce)
skip++
continue continue
} }
@ -430,7 +432,7 @@ func (mp *MessagePool) createMessageChains(actor address.Address, mset map[uint6
// check we have a sane set of messages to construct the chains // check we have a sane set of messages to construct the chains
if i > 0 { if i > 0 {
msgs = msgs[:i] msgs = msgs[skip:i]
} else { } else {
return nil return nil
} }
@ -524,7 +526,6 @@ func (mc *msgChain) Before(other *msgChain) bool {
func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt, ts *types.TipSet, priority bool) { func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt, ts *types.TipSet, priority bool) {
i := len(mc.msgs) - 1 i := len(mc.msgs) - 1
for i >= 0 && (mc.gasLimit > gasLimit || (!priority && mc.gasPerf < 0)) { for i >= 0 && (mc.gasLimit > gasLimit || (!priority && mc.gasPerf < 0)) {
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)
mc.gasLimit -= mc.msgs[i].Message.GasLimit mc.gasLimit -= mc.msgs[i].Message.GasLimit