From 56235aee90a4e8e3bb1e81cbd79dc9955218e032 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 31 Aug 2020 18:12:06 +0200 Subject: [PATCH 1/2] Fix GasEstimateGasPremium when there is only one message on chain Signed-off-by: Jakub Sztandera --- node/impl/full/gas.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index b4124ed913f..267d7e4cafc 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -109,27 +109,22 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, return prices[i].price.GreaterThan(prices[j].price) }) - // todo: account for how full blocks are - at := build.BlockGasTarget * int64(blocks) / 2 - prev := big.Zero() - - premium := big.Zero() + prev1, prev2 := big.Zero(), big.Zero() for _, price := range prices { + prev1, prev2 = price.price, prev1 at -= price.limit if at > 0 { - prev = price.price continue } + } - if prev.Equals(big.Zero()) { - return types.BigAdd(price.price, big.NewInt(1)), nil - } - - premium = types.BigAdd(big.Div(types.BigAdd(price.price, prev), types.NewInt(2)), big.NewInt(1)) + premium := prev1 + if types.BigCmp(prev2, big.Zero()) != 0 { + premium = big.Div(types.BigAdd(prev1, prev2), types.NewInt(2)) } - if types.BigCmp(premium, big.Zero()) == 0 { + if types.BigCmp(premium, types.NewInt(MinGasPremium)) < 0 { switch nblocksincl { case 1: premium = types.NewInt(2 * MinGasPremium) @@ -144,7 +139,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, 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: Mon, 31 Aug 2020 18:53:14 -0400 Subject: [PATCH 2/2] Use Sign() to check zero-equality --- node/impl/full/gas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 267d7e4cafc..6ee79c93a33 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -120,7 +120,7 @@ func (a *GasAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, } premium := prev1 - if types.BigCmp(prev2, big.Zero()) != 0 { + if prev2.Sign() != 0 { premium = big.Div(types.BigAdd(prev1, prev2), types.NewInt(2)) }