Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2497f28a
Commit
2497f28a
authored
Aug 17, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1627 from zsfelfoldi/gpo
GPO update
parents
ff1f6fa0
49ece315
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
gasprice.go
eth/gasprice.go
+13
-10
No files found.
eth/gasprice.go
View file @
2497f28a
...
...
@@ -37,12 +37,11 @@ type blockPriceInfo struct {
type
GasPriceOracle
struct
{
eth
*
Ethereum
chain
*
core
.
ChainManager
pool
*
core
.
TxPool
events
event
.
Subscription
blocks
map
[
uint64
]
*
blockPriceInfo
firstProcessed
,
lastProcessed
uint64
lastBaseMutex
sync
.
Mutex
lastBase
*
big
.
Int
lastBase
,
minBase
*
big
.
Int
}
func
NewGasPriceOracle
(
eth
*
Ethereum
)
(
self
*
GasPriceOracle
)
{
...
...
@@ -50,13 +49,15 @@ func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) {
self
.
blocks
=
make
(
map
[
uint64
]
*
blockPriceInfo
)
self
.
eth
=
eth
self
.
chain
=
eth
.
chainManager
self
.
pool
=
eth
.
txPool
self
.
events
=
eth
.
EventMux
()
.
Subscribe
(
core
.
ChainEvent
{},
core
.
ChainSplitEvent
{},
core
.
TxPreEvent
{},
core
.
TxPostEvent
{},
)
minbase
:=
new
(
big
.
Int
)
.
Mul
(
self
.
eth
.
GpoMinGasPrice
,
big
.
NewInt
(
100
))
minbase
=
minbase
.
Div
(
minbase
,
big
.
NewInt
(
int64
(
self
.
eth
.
GpobaseCorrectionFactor
)))
self
.
minBase
=
minbase
self
.
processPastBlocks
()
go
self
.
listenLoop
()
return
...
...
@@ -93,8 +94,6 @@ func (self *GasPriceOracle) listenLoop() {
self
.
processBlock
(
ev
.
Block
)
case
core
.
ChainSplitEvent
:
self
.
processBlock
(
ev
.
Block
)
case
core
.
TxPreEvent
:
case
core
.
TxPostEvent
:
}
}
self
.
events
.
Unsubscribe
()
...
...
@@ -131,6 +130,10 @@ func (self *GasPriceOracle) processBlock(block *types.Block) {
newBase
:=
new
(
big
.
Int
)
.
Mul
(
lastBase
,
big
.
NewInt
(
1000000
+
crand
))
newBase
.
Div
(
newBase
,
big
.
NewInt
(
1000000
))
if
newBase
.
Cmp
(
self
.
minBase
)
<
0
{
newBase
=
self
.
minBase
}
bpi
:=
self
.
blocks
[
i
]
if
bpi
==
nil
{
bpi
=
&
blockPriceInfo
{}
...
...
@@ -146,7 +149,7 @@ func (self *GasPriceOracle) processBlock(block *types.Block) {
// returns the lowers possible price with which a tx was or could have been included
func
(
self
*
GasPriceOracle
)
lowestPrice
(
block
*
types
.
Block
)
*
big
.
Int
{
gasUsed
:=
new
(
big
.
Int
)
gasUsed
:=
big
.
NewInt
(
0
)
receipts
:=
self
.
eth
.
BlockProcessor
()
.
GetBlockReceipts
(
block
.
Hash
())
if
len
(
receipts
)
>
0
{
...
...
@@ -158,12 +161,12 @@ func (self *GasPriceOracle) lowestPrice(block *types.Block) *big.Int {
if
new
(
big
.
Int
)
.
Mul
(
gasUsed
,
big
.
NewInt
(
100
))
.
Cmp
(
new
(
big
.
Int
)
.
Mul
(
block
.
GasLimit
(),
big
.
NewInt
(
int64
(
self
.
eth
.
GpoFullBlockRatio
))))
<
0
{
// block is not full, could have posted a tx with MinGasPrice
return
self
.
eth
.
GpoMinGasPrice
return
big
.
NewInt
(
0
)
}
txs
:=
block
.
Transactions
()
if
len
(
txs
)
==
0
{
return
self
.
eth
.
GpoMinGasPrice
return
big
.
NewInt
(
0
)
}
// block is full, find smallest gasPrice
minPrice
:=
txs
[
0
]
.
GasPrice
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment