Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
2497f28a
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2497f28a
编写于
8月 17, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1627 from zsfelfoldi/gpo
GPO update
上级
ff1f6fa0
49ece315
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
10 deletion
+13
-10
eth/gasprice.go
eth/gasprice.go
+13
-10
未找到文件。
eth/gasprice.go
浏览文件 @
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
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录