-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR: add recommend gas price (#940)
* add recommend gas price * update gpIndex flag * use global var to store gas price index instand of watchdb * default to support gasprice suggest * update flag name * update default of gas-limit-buffer to 50 Co-authored-by: MengXiangJian <[email protected]> Co-authored-by: evan.han <[email protected]>
- Loading branch information
1 parent
d999c96
commit 904281e
Showing
5 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app | ||
|
||
import ( | ||
"math" | ||
"math/big" | ||
"sort" | ||
) | ||
|
||
type GasPriceIndex struct { | ||
Min *big.Int `json:"min"` | ||
Q1 *big.Int `json:"q1"` | ||
Q2 *big.Int `json:"q2"` | ||
Q3 *big.Int `json:"q3"` | ||
Max *big.Int `json:"max"` | ||
} | ||
|
||
func CalBlockGasPriceIndex(blockGasPrice []*big.Int) GasPriceIndex { | ||
num := len(blockGasPrice) | ||
if num == 0 { | ||
return GasPriceIndex{} | ||
} | ||
|
||
sort.SliceStable(blockGasPrice, func(i, j int) bool { | ||
return blockGasPrice[i].Cmp(blockGasPrice[j]) < 0 | ||
}) | ||
|
||
gpIndex := GasPriceIndex{ | ||
Min: blockGasPrice[0], | ||
Q1: blockGasPrice[0], | ||
Q2: blockGasPrice[0], | ||
Q3: blockGasPrice[0], | ||
Max: blockGasPrice[num-1], | ||
} | ||
|
||
if q1 := int(math.Round(float64(num) * 0.25)); q1 > 0 { | ||
gpIndex.Q1 = blockGasPrice[q1-1] | ||
} | ||
|
||
if q2 := int(math.Round(float64(num) * 0.5)); q2 > 0 { | ||
gpIndex.Q2 = blockGasPrice[q2-1] | ||
} | ||
|
||
if q3 := int(math.Round(float64(num) * 0.75)); q3 > 0 { | ||
gpIndex.Q3 = blockGasPrice[q3-1] | ||
} | ||
|
||
return gpIndex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters