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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
c1740e45
Commit
c1740e45
authored
Sep 7, 2017
by
Mark
Committed by
Felix Lange
Sep 7, 2017
Browse files
Options
Downloads
Patches
Plain Diff
core/types, miner: avoid tx sender miscaching (#14773)
parent
e3db1236
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/types/transaction.go
+12
-10
12 additions, 10 deletions
core/types/transaction.go
core/types/transaction_test.go
+1
-1
1 addition, 1 deletion
core/types/transaction_test.go
miner/worker.go
+2
-2
2 additions, 2 deletions
miner/worker.go
with
15 additions
and
13 deletions
core/types/transaction.go
+
12
−
10
View file @
c1740e45
...
...
@@ -383,18 +383,21 @@ func (s *TxByPrice) Pop() interface{} {
type
TransactionsByPriceAndNonce
struct
{
txs
map
[
common
.
Address
]
Transactions
// Per account nonce-sorted list of transactions
heads
TxByPrice
// Next transaction for each unique account (price heap)
signer
Signer
// Signer for the set of transactions
}
// NewTransactionsByPriceAndNonce creates a transaction set that can retrieve
// price sorted transactions in a nonce-honouring way.
//
// Note, the input map is reowned so the caller should not interact any more with
// if after providng it to the constructor.
func
NewTransactionsByPriceAndNonce
(
txs
map
[
common
.
Address
]
Transactions
)
*
TransactionsByPriceAndNonce
{
// if after provid
i
ng it to the constructor.
func
NewTransactionsByPriceAndNonce
(
signer
Signer
,
txs
map
[
common
.
Address
]
Transactions
)
*
TransactionsByPriceAndNonce
{
// Initialize a price based heap with the head transactions
heads
:=
make
(
TxByPrice
,
0
,
len
(
txs
))
for
acc
,
accTxs
:=
range
txs
{
for
_
,
accTxs
:=
range
txs
{
heads
=
append
(
heads
,
accTxs
[
0
])
// Ensure the sender address is from the signer
acc
,
_
:=
Sender
(
signer
,
accTxs
[
0
])
txs
[
acc
]
=
accTxs
[
1
:
]
}
heap
.
Init
(
&
heads
)
...
...
@@ -403,6 +406,7 @@ func NewTransactionsByPriceAndNonce(txs map[common.Address]Transactions) *Transa
return
&
TransactionsByPriceAndNonce
{
txs
:
txs
,
heads
:
heads
,
signer
:
signer
,
}
}
...
...
@@ -416,9 +420,7 @@ func (t *TransactionsByPriceAndNonce) Peek() *Transaction {
// Shift replaces the current best head with the next one from the same account.
func
(
t
*
TransactionsByPriceAndNonce
)
Shift
()
{
signer
:=
deriveSigner
(
t
.
heads
[
0
]
.
data
.
V
)
// derive signer but don't cache.
acc
,
_
:=
Sender
(
signer
,
t
.
heads
[
0
])
// we only sort valid txs so this cannot fail
acc
,
_
:=
Sender
(
t
.
signer
,
t
.
heads
[
0
])
if
txs
,
ok
:=
t
.
txs
[
acc
];
ok
&&
len
(
txs
)
>
0
{
t
.
heads
[
0
],
t
.
txs
[
acc
]
=
txs
[
0
],
txs
[
1
:
]
heap
.
Fix
(
&
t
.
heads
,
0
)
...
...
This diff is collapsed.
Click to expand it.
core/types/transaction_test.go
+
1
−
1
View file @
c1740e45
...
...
@@ -143,7 +143,7 @@ func TestTransactionPriceNonceSort(t *testing.T) {
}
}
// Sort the transactions and cross check the nonce ordering
txset
:=
NewTransactionsByPriceAndNonce
(
groups
)
txset
:=
NewTransactionsByPriceAndNonce
(
signer
,
groups
)
txs
:=
Transactions
{}
for
{
...
...
This diff is collapsed.
Click to expand it.
miner/worker.go
+
2
−
2
View file @
c1740e45
...
...
@@ -268,7 +268,7 @@ func (self *worker) update() {
self
.
currentMu
.
Lock
()
acc
,
_
:=
types
.
Sender
(
self
.
current
.
signer
,
ev
.
Tx
)
txs
:=
map
[
common
.
Address
]
types
.
Transactions
{
acc
:
{
ev
.
Tx
}}
txset
:=
types
.
NewTransactionsByPriceAndNonce
(
txs
)
txset
:=
types
.
NewTransactionsByPriceAndNonce
(
self
.
current
.
signer
,
txs
)
self
.
current
.
commitTransactions
(
self
.
mux
,
txset
,
self
.
chain
,
self
.
coinbase
)
self
.
currentMu
.
Unlock
()
...
...
@@ -471,7 +471,7 @@ func (self *worker) commitNewWork() {
log
.
Error
(
"Failed to fetch pending transactions"
,
"err"
,
err
)
return
}
txs
:=
types
.
NewTransactionsByPriceAndNonce
(
pending
)
txs
:=
types
.
NewTransactionsByPriceAndNonce
(
self
.
current
.
signer
,
pending
)
work
.
commitTransactions
(
self
.
mux
,
txs
,
self
.
chain
,
self
.
coinbase
)
// compute uncles for the new block.
...
...
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