From ff7e441c82fa0cec55c57ab8bc1172b9cac4c492 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 13 Aug 2020 18:57:06 +0200 Subject: [PATCH 1/2] Add noise to GasPremium calculation to help out message selection Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 49f07b271..9f7d8907d 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -3,6 +3,7 @@ package full import ( "context" "math" + "math/rand" "sort" "github.com/filecoin-project/lotus/build" @@ -26,7 +27,7 @@ type GasAPI struct { Mpool *messagepool.MessagePool } -const MinGasPremium = 10e3 +const MinGasPremium = 100e3 const MaxSpendOnFeeDenom = 100 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 prev := big.Zero() + premium := big.Zero() for _, price := range prices { at -= price.limit if at > 0 { @@ -122,17 +124,26 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, 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 { - case 1: - return types.NewInt(2 * MinGasPremium), nil - case 2: - return types.NewInt(1.5 * MinGasPremium), nil - default: - return types.NewInt(MinGasPremium), nil + if types.BigCmp(premium, big.Zero()) == 0 { + switch nblocksincl { + case 1: + premium = types.NewInt(2 * MinGasPremium) + case 2: + premium = types.NewInt(1.5 * MinGasPremium) + default: + premium = types.NewInt(MinGasPremium) + } } + + 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< Date: Thu, 13 Aug 2020 19:27:31 +0200 Subject: [PATCH 2/2] Add comments Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 9f7d8907d..d501af2f7 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -138,6 +138,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, } } + // 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