@@ -32,12 +32,14 @@ import (
3232const sampleNumber = 3 // Number of transactions sampled in a block
3333
3434var DefaultMaxPrice = big .NewInt (500 * params .GWei )
35+ var DefaultIgnorePrice = big .NewInt (2 * params .Wei )
3536
3637type Config struct {
37- Blocks int
38- Percentile int
39- Default * big.Int `toml:",omitempty"`
40- MaxPrice * big.Int `toml:",omitempty"`
38+ Blocks int
39+ Percentile int
40+ Default * big.Int `toml:",omitempty"`
41+ MaxPrice * big.Int `toml:",omitempty"`
42+ IgnorePrice * big.Int `toml:",omitempty"`
4143}
4244
4345// OracleBackend includes all necessary background APIs for oracle.
@@ -50,12 +52,13 @@ type OracleBackend interface {
5052// Oracle recommends gas prices based on the content of recent
5153// blocks. Suitable for both light and full clients.
5254type Oracle struct {
53- backend OracleBackend
54- lastHead common.Hash
55- lastPrice * big.Int
56- maxPrice * big.Int
57- cacheLock sync.RWMutex
58- fetchLock sync.Mutex
55+ backend OracleBackend
56+ lastHead common.Hash
57+ lastPrice * big.Int
58+ maxPrice * big.Int
59+ ignorePrice * big.Int
60+ cacheLock sync.RWMutex
61+ fetchLock sync.Mutex
5962
6063 checkBlocks int
6164 percentile int
@@ -83,10 +86,18 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
8386 maxPrice = DefaultMaxPrice
8487 log .Warn ("Sanitizing invalid gasprice oracle price cap" , "provided" , params .MaxPrice , "updated" , maxPrice )
8588 }
89+ ignorePrice := params .IgnorePrice
90+ if ignorePrice == nil || ignorePrice .Int64 () <= 0 {
91+ ignorePrice = DefaultIgnorePrice
92+ log .Warn ("Sanitizing invalid gasprice oracle ignore price" , "provided" , params .IgnorePrice , "updated" , ignorePrice )
93+ } else if ignorePrice .Int64 () > 0 {
94+ log .Info ("Gasprice oracle is ignoring threshold set" , "threshold" , ignorePrice )
95+ }
8696 return & Oracle {
8797 backend : backend ,
8898 lastPrice : params .Default ,
8999 maxPrice : maxPrice ,
100+ ignorePrice : ignorePrice ,
90101 checkBlocks : blocks ,
91102 percentile : percent ,
92103 }
@@ -122,7 +133,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
122133 txPrices []* big.Int
123134 )
124135 for sent < gpo .checkBlocks && number > 0 {
125- go gpo .getBlockPrices (ctx , types .MakeSigner (gpo .backend .ChainConfig (), big .NewInt (int64 (number ))), number , sampleNumber , result , quit )
136+ go gpo .getBlockPrices (ctx , types .MakeSigner (gpo .backend .ChainConfig (), big .NewInt (int64 (number ))), number , sampleNumber , gpo . ignorePrice , result , quit )
126137 sent ++
127138 exp ++
128139 number --
@@ -145,7 +156,7 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
145156 // meaningful returned, try to query more blocks. But the maximum
146157 // is 2*checkBlocks.
147158 if len (res .prices ) == 1 && len (txPrices )+ 1 + exp < gpo .checkBlocks * 2 && number > 0 {
148- go gpo .getBlockPrices (ctx , types .MakeSigner (gpo .backend .ChainConfig (), big .NewInt (int64 (number ))), number , sampleNumber , result , quit )
159+ go gpo .getBlockPrices (ctx , types .MakeSigner (gpo .backend .ChainConfig (), big .NewInt (int64 (number ))), number , sampleNumber , gpo . ignorePrice , result , quit )
149160 sent ++
150161 exp ++
151162 number --
@@ -189,7 +200,7 @@ func (t transactionsByGasPrice) Less(i, j int) bool { return t[i].GasPriceCmp(t[
189200// and sends it to the result channel. If the block is empty or all transactions
190201// are sent by the miner itself(it doesn't make any sense to include this kind of
191202// transaction prices for sampling), nil gasprice is returned.
192- func (gpo * Oracle ) getBlockPrices (ctx context.Context , signer types.Signer , blockNum uint64 , limit int , result chan getBlockPricesResult , quit chan struct {}) {
203+ func (gpo * Oracle ) getBlockPrices (ctx context.Context , signer types.Signer , blockNum uint64 , limit int , ignoreUnder * big. Int , result chan getBlockPricesResult , quit chan struct {}) {
193204 block , err := gpo .backend .BlockByNumber (ctx , rpc .BlockNumber (blockNum ))
194205 if block == nil {
195206 select {
@@ -205,7 +216,7 @@ func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, bloc
205216
206217 var prices []* big.Int
207218 for _ , tx := range txs {
208- if tx .GasPrice ().Cmp (common . Big1 ) <= 0 {
219+ if ignoreUnder != nil && tx .GasPrice ().Cmp (ignoreUnder ) == - 1 {
209220 continue
210221 }
211222 sender , err := types .Sender (signer , tx )
0 commit comments