Correctly account for gas of included messages

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-08-04 02:36:16 +02:00
parent cd8537e76f
commit 3e23b3653b
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -29,6 +29,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
gasReward []abi.TokenAmount
gasLimit []int64
gasOffset int64
msgs []*types.SignedMessage
}
@ -155,7 +156,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
continue
}
for n := range meta.msgs {
if meta.gasLimit[n] > gasLimitLeft {
if meta.gasLimit[n]-meta.gasOffset > gasLimitLeft {
break
}
@ -164,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 /= float64(meta.gasLimit[n])
gasToReward /= float64(meta.gasLimit[n] - meta.gasOffset)
if gasToReward >= bestGasToReward {
bestSender = sender
@ -180,8 +181,9 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
{
out = append(out, outBySender[bestSender].msgs[:nBest]...)
gasLimitLeft -= outBySender[bestSender].gasLimit[nBest-1]
gasLimitLeft -= outBySender[bestSender].gasLimit[nBest-1] - outBySender[bestSender].gasOffset
outBySender[bestSender].gasOffset += outBySender[bestSender].gasLimit[nBest-1]
outBySender[bestSender].msgs = outBySender[bestSender].msgs[nBest:]
outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:]
outBySender[bestSender].gasReward = outBySender[bestSender].gasReward[nBest:]