Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
26f83879
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,体验更适合开发者的 AI 搜索 >>
提交
26f83879
编写于
8月 05, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1583 from obscuren/miner-price-order
miner, core: sort txs by price, nonce
上级
f12e0161
35f271b2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
1 deletion
+53
-1
core/types/transaction.go
core/types/transaction.go
+19
-0
miner/worker.go
miner/worker.go
+34
-1
未找到文件。
core/types/transaction.go
浏览文件 @
26f83879
...
@@ -289,3 +289,22 @@ type TxByNonce struct{ Transactions }
...
@@ -289,3 +289,22 @@ type TxByNonce struct{ Transactions }
func
(
s
TxByNonce
)
Less
(
i
,
j
int
)
bool
{
func
(
s
TxByNonce
)
Less
(
i
,
j
int
)
bool
{
return
s
.
Transactions
[
i
]
.
data
.
AccountNonce
<
s
.
Transactions
[
j
]
.
data
.
AccountNonce
return
s
.
Transactions
[
i
]
.
data
.
AccountNonce
<
s
.
Transactions
[
j
]
.
data
.
AccountNonce
}
}
type
TxByPrice
struct
{
Transactions
}
func
(
s
TxByPrice
)
Less
(
i
,
j
int
)
bool
{
return
s
.
Transactions
[
i
]
.
data
.
Price
.
Cmp
(
s
.
Transactions
[
j
]
.
data
.
Price
)
>
0
}
type
TxByPriceAndNonce
struct
{
Transactions
}
func
(
s
TxByPriceAndNonce
)
Less
(
i
,
j
int
)
bool
{
// we can ignore the error here. Sorting shouldn't care about validness
ifrom
,
_
:=
s
.
Transactions
[
i
]
.
From
()
jfrom
,
_
:=
s
.
Transactions
[
j
]
.
From
()
// favour nonce if they are from the same recipient
if
ifrom
==
jfrom
{
return
s
.
Transactions
[
i
]
.
data
.
AccountNonce
<
s
.
Transactions
[
j
]
.
data
.
AccountNonce
}
return
s
.
Transactions
[
i
]
.
data
.
Price
.
Cmp
(
s
.
Transactions
[
j
]
.
data
.
Price
)
>
0
}
miner/worker.go
浏览文件 @
26f83879
...
@@ -457,9 +457,42 @@ func (self *worker) commitNewWork() {
...
@@ -457,9 +457,42 @@ func (self *worker) commitNewWork() {
self
.
makeCurrent
(
parent
,
header
)
self
.
makeCurrent
(
parent
,
header
)
work
:=
self
.
current
work
:=
self
.
current
/
/ commit transactions for this run.
/
* //approach 1
transactions := self.eth.TxPool().GetTransactions()
transactions := self.eth.TxPool().GetTransactions()
sort.Sort(types.TxByNonce{transactions})
sort.Sort(types.TxByNonce{transactions})
*/
//approach 2
transactions
:=
self
.
eth
.
TxPool
()
.
GetTransactions
()
sort
.
Sort
(
types
.
TxByPriceAndNonce
{
transactions
})
/* // approach 3
// commit transactions for this run.
txPerOwner := make(map[common.Address]types.Transactions)
// Sort transactions by owner
for _, tx := range self.eth.TxPool().GetTransactions() {
from, _ := tx.From() // we can ignore the sender error
txPerOwner[from] = append(txPerOwner[from], tx)
}
var (
singleTxOwner types.Transactions
multiTxOwner types.Transactions
)
// Categorise transactions by
// 1. 1 owner tx per block
// 2. multi txs owner per block
for _, txs := range txPerOwner {
if len(txs) == 1 {
singleTxOwner = append(singleTxOwner, txs[0])
} else {
multiTxOwner = append(multiTxOwner, txs...)
}
}
sort.Sort(types.TxByPrice{singleTxOwner})
sort.Sort(types.TxByNonce{multiTxOwner})
transactions := append(singleTxOwner, multiTxOwner...)
*/
work
.
coinbase
.
SetGasLimit
(
header
.
GasLimit
)
work
.
coinbase
.
SetGasLimit
(
header
.
GasLimit
)
work
.
commitTransactions
(
transactions
,
self
.
gasPrice
,
self
.
proc
)
work
.
commitTransactions
(
transactions
,
self
.
gasPrice
,
self
.
proc
)
self
.
eth
.
TxPool
()
.
RemoveTransactions
(
work
.
lowGasTxs
)
self
.
eth
.
TxPool
()
.
RemoveTransactions
(
work
.
lowGasTxs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录