avoid repeatedly reallocating a big for block gas limit, more conservative failed gas estimation

This commit is contained in:
vyzo 2020-08-05 10:22:40 +03:00
parent 9f7deff512
commit 9b6d822b3e

View File

@ -15,6 +15,8 @@ import (
abig "github.com/filecoin-project/specs-actors/actors/abi/big" abig "github.com/filecoin-project/specs-actors/actors/abi/big"
) )
var bigBlockGasLimit = big.NewInt(build.BlockGasLimit)
type msgChain struct { type msgChain struct {
msgs []*types.SignedMessage msgs []*types.SignedMessage
gasReward *big.Int gasReward *big.Int
@ -124,9 +126,12 @@ func (mp *MessagePool) getGasReward(msg *types.SignedMessage, ts *types.TipSet)
} }
gasUsed, err := gasguess.GuessGasUsed(context.TODO(), types.EmptyTSK, msg, al) gasUsed, err := gasguess.GuessGasUsed(context.TODO(), types.EmptyTSK, msg, al)
if err != nil { if err != nil {
// if we start seeing this warning we may have a problem with spammers!
log.Warnf("Cannot guess gas usage for message: %s; using MaxGas=%d", err, gasguess.MaxGas)
gasUsed = int64(gasguess.MaxGas) gasUsed = int64(gasguess.MaxGas)
if gasUsed > msg.Message.GasLimit/2 {
gasUsed = msg.Message.GasLimit / 2
}
// if we start seeing this warning we may have a problem with spammers!
log.Warnf("Cannot guess gas usage for message: %s; using %d", err, gasUsed)
} }
gasReward := abig.Mul(msg.Message.GasPrice, types.NewInt(uint64(gasUsed))) gasReward := abig.Mul(msg.Message.GasPrice, types.NewInt(uint64(gasUsed)))
return gasReward.Int return gasReward.Int
@ -134,7 +139,7 @@ func (mp *MessagePool) getGasReward(msg *types.SignedMessage, ts *types.TipSet)
func (mp *MessagePool) getGasPerf(gasReward *big.Int, gasLimit int64) float64 { func (mp *MessagePool) getGasPerf(gasReward *big.Int, gasLimit int64) float64 {
// gasPerf = gasReward * build.BlockGasLimit / gasLimit // gasPerf = gasReward * build.BlockGasLimit / gasLimit
a := new(big.Rat).SetInt(new(big.Int).Mul(gasReward, big.NewInt(build.BlockGasLimit))) a := new(big.Rat).SetInt(new(big.Int).Mul(gasReward, bigBlockGasLimit))
b := big.NewRat(1, gasLimit) b := big.NewRat(1, gasLimit)
c := new(big.Rat).Mul(a, b) c := new(big.Rat).Mul(a, b)
r, _ := c.Float64() r, _ := c.Float64()