good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
49ece315
Commit
49ece315
authored
9 years ago
by
Zsolt Felföldi
Browse files
Options
Downloads
Patches
Plain Diff
GPO update
parent
1cbd53ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eth/gasprice.go
+13
-10
13 additions, 10 deletions
eth/gasprice.go
with
13 additions
and
10 deletions
eth/gasprice.go
+
13
−
10
View file @
49ece315
...
@@ -37,12 +37,11 @@ type blockPriceInfo struct {
...
@@ -37,12 +37,11 @@ type blockPriceInfo struct {
type
GasPriceOracle
struct
{
type
GasPriceOracle
struct
{
eth
*
Ethereum
eth
*
Ethereum
chain
*
core
.
ChainManager
chain
*
core
.
ChainManager
pool
*
core
.
TxPool
events
event
.
Subscription
events
event
.
Subscription
blocks
map
[
uint64
]
*
blockPriceInfo
blocks
map
[
uint64
]
*
blockPriceInfo
firstProcessed
,
lastProcessed
uint64
firstProcessed
,
lastProcessed
uint64
lastBaseMutex
sync
.
Mutex
lastBaseMutex
sync
.
Mutex
lastBase
*
big
.
Int
lastBase
,
minBase
*
big
.
Int
}
}
func
NewGasPriceOracle
(
eth
*
Ethereum
)
(
self
*
GasPriceOracle
)
{
func
NewGasPriceOracle
(
eth
*
Ethereum
)
(
self
*
GasPriceOracle
)
{
...
@@ -50,13 +49,15 @@ func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) {
...
@@ -50,13 +49,15 @@ func NewGasPriceOracle(eth *Ethereum) (self *GasPriceOracle) {
self
.
blocks
=
make
(
map
[
uint64
]
*
blockPriceInfo
)
self
.
blocks
=
make
(
map
[
uint64
]
*
blockPriceInfo
)
self
.
eth
=
eth
self
.
eth
=
eth
self
.
chain
=
eth
.
chainManager
self
.
chain
=
eth
.
chainManager
self
.
pool
=
eth
.
txPool
self
.
events
=
eth
.
EventMux
()
.
Subscribe
(
self
.
events
=
eth
.
EventMux
()
.
Subscribe
(
core
.
ChainEvent
{},
core
.
ChainEvent
{},
core
.
ChainSplitEvent
{},
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
()
self
.
processPastBlocks
()
go
self
.
listenLoop
()
go
self
.
listenLoop
()
return
return
...
@@ -93,8 +94,6 @@ func (self *GasPriceOracle) listenLoop() {
...
@@ -93,8 +94,6 @@ func (self *GasPriceOracle) listenLoop() {
self
.
processBlock
(
ev
.
Block
)
self
.
processBlock
(
ev
.
Block
)
case
core
.
ChainSplitEvent
:
case
core
.
ChainSplitEvent
:
self
.
processBlock
(
ev
.
Block
)
self
.
processBlock
(
ev
.
Block
)
case
core
.
TxPreEvent
:
case
core
.
TxPostEvent
:
}
}
}
}
self
.
events
.
Unsubscribe
()
self
.
events
.
Unsubscribe
()
...
@@ -131,6 +130,10 @@ func (self *GasPriceOracle) processBlock(block *types.Block) {
...
@@ -131,6 +130,10 @@ func (self *GasPriceOracle) processBlock(block *types.Block) {
newBase
:=
new
(
big
.
Int
)
.
Mul
(
lastBase
,
big
.
NewInt
(
1000000
+
crand
))
newBase
:=
new
(
big
.
Int
)
.
Mul
(
lastBase
,
big
.
NewInt
(
1000000
+
crand
))
newBase
.
Div
(
newBase
,
big
.
NewInt
(
1000000
))
newBase
.
Div
(
newBase
,
big
.
NewInt
(
1000000
))
if
newBase
.
Cmp
(
self
.
minBase
)
<
0
{
newBase
=
self
.
minBase
}
bpi
:=
self
.
blocks
[
i
]
bpi
:=
self
.
blocks
[
i
]
if
bpi
==
nil
{
if
bpi
==
nil
{
bpi
=
&
blockPriceInfo
{}
bpi
=
&
blockPriceInfo
{}
...
@@ -146,7 +149,7 @@ func (self *GasPriceOracle) processBlock(block *types.Block) {
...
@@ -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
// returns the lowers possible price with which a tx was or could have been included
func
(
self
*
GasPriceOracle
)
lowestPrice
(
block
*
types
.
Block
)
*
big
.
Int
{
func
(
self
*
GasPriceOracle
)
lowestPrice
(
block
*
types
.
Block
)
*
big
.
Int
{
gasUsed
:=
new
(
big
.
Int
)
gasUsed
:=
big
.
New
Int
(
0
)
receipts
:=
self
.
eth
.
BlockProcessor
()
.
GetBlockReceipts
(
block
.
Hash
())
receipts
:=
self
.
eth
.
BlockProcessor
()
.
GetBlockReceipts
(
block
.
Hash
())
if
len
(
receipts
)
>
0
{
if
len
(
receipts
)
>
0
{
...
@@ -158,12 +161,12 @@ func (self *GasPriceOracle) lowestPrice(block *types.Block) *big.Int {
...
@@ -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
(),
if
new
(
big
.
Int
)
.
Mul
(
gasUsed
,
big
.
NewInt
(
100
))
.
Cmp
(
new
(
big
.
Int
)
.
Mul
(
block
.
GasLimit
(),
big
.
NewInt
(
int64
(
self
.
eth
.
GpoFullBlockRatio
))))
<
0
{
big
.
NewInt
(
int64
(
self
.
eth
.
GpoFullBlockRatio
))))
<
0
{
// block is not full, could have posted a tx with MinGasPrice
// block is not full, could have posted a tx with MinGasPrice
return
self
.
eth
.
GpoMinGasPrice
return
big
.
NewInt
(
0
)
}
}
txs
:=
block
.
Transactions
()
txs
:=
block
.
Transactions
()
if
len
(
txs
)
==
0
{
if
len
(
txs
)
==
0
{
return
self
.
eth
.
GpoMinGasPrice
return
big
.
NewInt
(
0
)
}
}
// block is full, find smallest gasPrice
// block is full, find smallest gasPrice
minPrice
:=
txs
[
0
]
.
GasPrice
()
minPrice
:=
txs
[
0
]
.
GasPrice
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment