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
26f83879
Commit
26f83879
authored
9 years ago
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1583 from obscuren/miner-price-order
miner, core: sort txs by price, nonce
parents
f12e0161
35f271b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
transaction.go
core/types/transaction.go
+19
-0
worker.go
miner/worker.go
+34
-1
No files found.
core/types/transaction.go
View file @
26f83879
...
...
@@ -289,3 +289,22 @@ type TxByNonce struct{ Transactions }
func
(
s
TxByNonce
)
Less
(
i
,
j
int
)
bool
{
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
}
This diff is collapsed.
Click to expand it.
miner/worker.go
View file @
26f83879
...
...
@@ -457,9 +457,42 @@ func (self *worker) commitNewWork() {
self
.
makeCurrent
(
parent
,
header
)
work
:=
self
.
current
/
/ commit transactions for this run.
/
* //approach 1
transactions := self.eth.TxPool().GetTransactions()
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
.
commitTransactions
(
transactions
,
self
.
gasPrice
,
self
.
proc
)
self
.
eth
.
TxPool
()
.
RemoveTransactions
(
work
.
lowGasTxs
)
...
...
This diff is collapsed.
Click to expand it.
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