Merge pull request #3036 from filecoin-project/feat/noise-gas-premium
Add noise to GasPremium calculation to help out message selection
This commit is contained in:
commit
15a81707b4
@ -3,6 +3,7 @@ package full
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
@ -26,7 +27,7 @@ type GasAPI struct {
|
|||||||
Mpool *messagepool.MessagePool
|
Mpool *messagepool.MessagePool
|
||||||
}
|
}
|
||||||
|
|
||||||
const MinGasPremium = 10e3
|
const MinGasPremium = 100e3
|
||||||
const MaxSpendOnFeeDenom = 100
|
const MaxSpendOnFeeDenom = 100
|
||||||
|
|
||||||
func (a *GasAPI) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64,
|
func (a *GasAPI) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64,
|
||||||
@ -111,6 +112,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64,
|
|||||||
at := build.BlockGasTarget * int64(blocks) / 2
|
at := build.BlockGasTarget * int64(blocks) / 2
|
||||||
prev := big.Zero()
|
prev := big.Zero()
|
||||||
|
|
||||||
|
premium := big.Zero()
|
||||||
for _, price := range prices {
|
for _, price := range prices {
|
||||||
at -= price.limit
|
at -= price.limit
|
||||||
if at > 0 {
|
if at > 0 {
|
||||||
@ -122,17 +124,27 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64,
|
|||||||
return types.BigAdd(price.price, big.NewInt(1)), nil
|
return types.BigAdd(price.price, big.NewInt(1)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.BigAdd(big.Div(types.BigAdd(price.price, prev), types.NewInt(2)), big.NewInt(1)), nil
|
premium = types.BigAdd(big.Div(types.BigAdd(price.price, prev), types.NewInt(2)), big.NewInt(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch nblocksincl {
|
if types.BigCmp(premium, big.Zero()) == 0 {
|
||||||
case 1:
|
switch nblocksincl {
|
||||||
return types.NewInt(2 * MinGasPremium), nil
|
case 1:
|
||||||
case 2:
|
premium = types.NewInt(2 * MinGasPremium)
|
||||||
return types.NewInt(1.5 * MinGasPremium), nil
|
case 2:
|
||||||
default:
|
premium = types.NewInt(1.5 * MinGasPremium)
|
||||||
return types.NewInt(MinGasPremium), nil
|
default:
|
||||||
|
premium = types.NewInt(MinGasPremium)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add some noise to normalize behaviour of message selection
|
||||||
|
const precision = 32
|
||||||
|
// mean 1, stddev 0.005 => 95% within +-1%
|
||||||
|
noise := 1 + rand.NormFloat64()*0.005
|
||||||
|
premium = types.BigMul(premium, types.NewInt(uint64(noise*(1<<precision))))
|
||||||
|
premium = types.BigDiv(premium, types.NewInt(1<<precision))
|
||||||
|
return premium, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, _ types.TipSetKey) (int64, error) {
|
func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, _ types.TipSetKey) (int64, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user