apply less nice but working fix

This commit is contained in:
whyrusleeping 2020-08-03 18:24:56 -07:00
parent 50ae04e6b7
commit 57b931b06a

View File

@ -29,7 +29,6 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
gasReward []abi.TokenAmount gasReward []abi.TokenAmount
gasLimit []int64 gasLimit []int64
gasOffset int64
msgs []*types.SignedMessage msgs []*types.SignedMessage
} }
@ -88,6 +87,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
getbal += build.Clock.Since(getBalStart) getbal += build.Clock.Since(getBalStart)
if inclBalances[from].LessThan(msg.Message.RequiredFunds()) { 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++ tooLowFundMsgs++
// todo: drop from mpool // todo: drop from mpool
continue continue
@ -156,7 +156,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
continue continue
} }
for n := range meta.msgs { for n := range meta.msgs {
if meta.gasLimit[n]-meta.gasOffset > gasLimitLeft { if meta.gasLimit[n] > gasLimitLeft {
break break
} }
@ -165,7 +165,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
} }
gasToReward, _ := new(big2.Float).SetInt(meta.gasReward[n].Int).Float64() gasToReward, _ := new(big2.Float).SetInt(meta.gasReward[n].Int).Float64()
gasToReward /= float64(meta.gasLimit[n] - meta.gasOffset) gasToReward /= float64(meta.gasLimit[n])
if gasToReward >= bestGasToReward { if gasToReward >= bestGasToReward {
bestSender = sender bestSender = sender
@ -176,18 +176,27 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
} }
if nBest == 0 { if nBest == 0 {
log.Warning("nBest is zero: ", gasLimitLeft)
break // block gas limit reached break // block gas limit reached
} }
{ {
out = append(out, outBySender[bestSender].msgs[:nBest]...) out = append(out, outBySender[bestSender].msgs[:nBest]...)
gasLimitLeft -= outBySender[bestSender].gasLimit[nBest-1] - outBySender[bestSender].gasOffset
outBySender[bestSender].gasOffset += 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].msgs = outBySender[bestSender].msgs[nBest:]
outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:] outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:]
outBySender[bestSender].gasReward = outBySender[bestSender].gasReward[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 { if len(outBySender[bestSender].msgs) == 0 {
delete(outBySender, bestSender) delete(outBySender, bestSender)
} }