@@ -24,18 +24,20 @@ import (
2424
2525 "github.com/ethereum/go-ethereum/common"
2626 "github.com/ethereum/go-ethereum/core/types"
27+ "github.com/ethereum/go-ethereum/log"
2728 "github.com/ethereum/go-ethereum/params"
2829 "github.com/ethereum/go-ethereum/rpc"
2930)
3031
3132const sampleNumber = 3 // Number of transactions sampled in a block
3233
33- var maxPrice = big .NewInt (500 * params .GWei )
34+ var DefaultMaxPrice = big .NewInt (500 * params .GWei )
3435
3536type Config struct {
3637 Blocks int
3738 Percentile int
3839 Default * big.Int `toml:",omitempty"`
40+ MaxPrice * big.Int `toml:",omitempty"`
3941}
4042
4143// OracleBackend includes all necessary background APIs for oracle.
@@ -51,6 +53,7 @@ type Oracle struct {
5153 backend OracleBackend
5254 lastHead common.Hash
5355 lastPrice * big.Int
56+ maxPrice * big.Int
5457 cacheLock sync.RWMutex
5558 fetchLock sync.Mutex
5659
@@ -64,17 +67,26 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
6467 blocks := params .Blocks
6568 if blocks < 1 {
6669 blocks = 1
70+ log .Warn ("Sanitizing invalid gasprice oracle sample blocks" , "provided" , params .Blocks , "updated" , blocks )
6771 }
6872 percent := params .Percentile
6973 if percent < 0 {
7074 percent = 0
75+ log .Warn ("Sanitizing invalid gasprice oracle sample percentile" , "provided" , params .Percentile , "updated" , percent )
7176 }
7277 if percent > 100 {
7378 percent = 100
79+ log .Warn ("Sanitizing invalid gasprice oracle sample percentile" , "provided" , params .Percentile , "updated" , percent )
80+ }
81+ maxPrice := params .MaxPrice
82+ if maxPrice == nil || maxPrice .Int64 () <= 0 {
83+ maxPrice = DefaultMaxPrice
84+ log .Warn ("Sanitizing invalid gasprice oracle price cap" , "provided" , params .MaxPrice , "updated" , maxPrice )
7485 }
7586 return & Oracle {
7687 backend : backend ,
7788 lastPrice : params .Default ,
89+ maxPrice : maxPrice ,
7890 checkBlocks : blocks ,
7991 percentile : percent ,
8092 }
@@ -146,8 +158,8 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
146158 sort .Sort (bigIntArray (txPrices ))
147159 price = txPrices [(len (txPrices )- 1 )* gpo .percentile / 100 ]
148160 }
149- if price .Cmp (maxPrice ) > 0 {
150- price = new (big.Int ).Set (maxPrice )
161+ if price .Cmp (gpo . maxPrice ) > 0 {
162+ price = new (big.Int ).Set (gpo . maxPrice )
151163 }
152164 gpo .cacheLock .Lock ()
153165 gpo .lastHead = headHash
0 commit comments