Skip to content

Commit a7705fc

Browse files
committed
miner: moved gasprice to non-method
1 parent 13ddf20 commit a7705fc

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

miner/worker.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@ func (w *worker) setGasPrice(p *big.Int) {
247247
w.gasPrice = p
248248
}
249249

250-
func (w *worker) gasprice(pct int64) *big.Int {
251-
p := new(big.Int).Set(w.gasPrice)
252-
p.Div(p, big.NewInt(100))
253-
p.Mul(p, big.NewInt(pct))
254-
return p
255-
}
256-
257250
func (self *worker) commitNewWork() {
258251
self.mu.Lock()
259252
defer self.mu.Unlock()
@@ -274,8 +267,9 @@ func (self *worker) commitNewWork() {
274267
ignoredTransactors = set.New()
275268
)
276269

277-
var pct int64 = 90
278-
minprice := self.gasprice(pct)
270+
const pct = int64(90)
271+
// calculate the minimal gas price the miner accepts when sorting out transactions.
272+
minprice := gasprice(self.gasPrice, pct)
279273
for _, tx := range transactions {
280274
// We can skip err. It has already been validated in the tx pool
281275
from, _ := tx.From()
@@ -411,3 +405,12 @@ func (self *worker) HashRate() int64 {
411405

412406
return tot
413407
}
408+
409+
// gasprice calculates a reduced gas price based on the pct
410+
// XXX Use big.Rat?
411+
func gasprice(price *big.Int, pct int64) *big.Int {
412+
p := new(big.Int).Set(price)
413+
p.Div(p, big.NewInt(100))
414+
p.Mul(p, big.NewInt(pct))
415+
return p
416+
}

0 commit comments

Comments
 (0)