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
795b7042
Commit
795b7042
authored
Jun 27, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, eth, miner: only retain 1 tx/nonce, remove bad ones
parent
49227f65
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
282 additions
and
207 deletions
+282
-207
tx_pool.go
core/tx_pool.go
+158
-124
tx_pool_test.go
core/tx_pool_test.go
+93
-40
api_backend.go
eth/api_backend.go
+1
-1
api.go
internal/ethapi/api.go
+24
-36
backend.go
internal/ethapi/backend.go
+1
-1
worker.go
miner/worker.go
+5
-5
No files found.
core/tx_pool.go
View file @
795b7042
This diff is collapsed.
Click to expand it.
core/tx_pool_test.go
View file @
795b7042
This diff is collapsed.
Click to expand it.
eth/api_backend.go
View file @
795b7042
...
...
@@ -149,7 +149,7 @@ func (b *EthApiBackend) Stats() (pending int, queued int) {
return
b
.
eth
.
txPool
.
Stats
()
}
func
(
b
*
EthApiBackend
)
TxPoolContent
()
(
map
[
common
.
Address
]
map
[
uint64
][]
*
types
.
Transaction
,
map
[
common
.
Address
]
map
[
uint64
][]
*
types
.
Transaction
)
{
func
(
b
*
EthApiBackend
)
TxPoolContent
()
(
map
[
common
.
Address
]
core
.
TxList
,
map
[
common
.
Address
]
core
.
TxList
)
{
b
.
eth
.
txMu
.
Lock
()
defer
b
.
eth
.
txMu
.
Unlock
()
...
...
internal/ethapi/api.go
View file @
795b7042
...
...
@@ -100,32 +100,26 @@ func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI {
}
// Content returns the transactions contained within the transaction pool.
func
(
s
*
PublicTxPoolAPI
)
Content
()
map
[
string
]
map
[
string
]
map
[
string
]
[]
*
RPCTransaction
{
content
:=
map
[
string
]
map
[
string
]
map
[
string
]
[]
*
RPCTransaction
{
"pending"
:
make
(
map
[
string
]
map
[
string
]
[]
*
RPCTransaction
),
"queued"
:
make
(
map
[
string
]
map
[
string
]
[]
*
RPCTransaction
),
func
(
s
*
PublicTxPoolAPI
)
Content
()
map
[
string
]
map
[
string
]
map
[
string
]
*
RPCTransaction
{
content
:=
map
[
string
]
map
[
string
]
map
[
string
]
*
RPCTransaction
{
"pending"
:
make
(
map
[
string
]
map
[
string
]
*
RPCTransaction
),
"queued"
:
make
(
map
[
string
]
map
[
string
]
*
RPCTransaction
),
}
pending
,
queue
:=
s
.
b
.
TxPoolContent
()
// Flatten the pending transactions
for
account
,
batches
:=
range
pending
{
dump
:=
make
(
map
[
string
][]
*
RPCTransaction
)
for
nonce
,
txs
:=
range
batches
{
nonce
:=
fmt
.
Sprintf
(
"%d"
,
nonce
)
for
_
,
tx
:=
range
txs
{
dump
[
nonce
]
=
append
(
dump
[
nonce
],
newRPCPendingTransaction
(
tx
))
}
for
account
,
txs
:=
range
pending
{
dump
:=
make
(
map
[
string
]
*
RPCTransaction
)
for
nonce
,
tx
:=
range
txs
{
dump
[
fmt
.
Sprintf
(
"%d"
,
nonce
)]
=
newRPCPendingTransaction
(
tx
)
}
content
[
"pending"
][
account
.
Hex
()]
=
dump
}
// Flatten the queued transactions
for
account
,
batches
:=
range
queue
{
dump
:=
make
(
map
[
string
][]
*
RPCTransaction
)
for
nonce
,
txs
:=
range
batches
{
nonce
:=
fmt
.
Sprintf
(
"%d"
,
nonce
)
for
_
,
tx
:=
range
txs
{
dump
[
nonce
]
=
append
(
dump
[
nonce
],
newRPCPendingTransaction
(
tx
))
}
for
account
,
txs
:=
range
queue
{
dump
:=
make
(
map
[
string
]
*
RPCTransaction
)
for
nonce
,
tx
:=
range
txs
{
dump
[
fmt
.
Sprintf
(
"%d"
,
nonce
)]
=
newRPCPendingTransaction
(
tx
)
}
content
[
"queued"
][
account
.
Hex
()]
=
dump
}
...
...
@@ -143,10 +137,10 @@ func (s *PublicTxPoolAPI) Status() map[string]*rpc.HexNumber {
// Inspect retrieves the content of the transaction pool and flattens it into an
// easily inspectable list.
func
(
s
*
PublicTxPoolAPI
)
Inspect
()
map
[
string
]
map
[
string
]
map
[
string
]
[]
string
{
content
:=
map
[
string
]
map
[
string
]
map
[
string
]
[]
string
{
"pending"
:
make
(
map
[
string
]
map
[
string
]
[]
string
),
"queued"
:
make
(
map
[
string
]
map
[
string
]
[]
string
),
func
(
s
*
PublicTxPoolAPI
)
Inspect
()
map
[
string
]
map
[
string
]
map
[
string
]
string
{
content
:=
map
[
string
]
map
[
string
]
map
[
string
]
string
{
"pending"
:
make
(
map
[
string
]
map
[
string
]
string
),
"queued"
:
make
(
map
[
string
]
map
[
string
]
string
),
}
pending
,
queue
:=
s
.
b
.
TxPoolContent
()
...
...
@@ -158,24 +152,18 @@ func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string][]string {
return
fmt
.
Sprintf
(
"contract creation: %v wei + %v × %v gas"
,
tx
.
Value
(),
tx
.
Gas
(),
tx
.
GasPrice
())
}
// Flatten the pending transactions
for
account
,
batches
:=
range
pending
{
dump
:=
make
(
map
[
string
][]
string
)
for
nonce
,
txs
:=
range
batches
{
nonce
:=
fmt
.
Sprintf
(
"%d"
,
nonce
)
for
_
,
tx
:=
range
txs
{
dump
[
nonce
]
=
append
(
dump
[
nonce
],
format
(
tx
))
}
for
account
,
txs
:=
range
pending
{
dump
:=
make
(
map
[
string
]
string
)
for
nonce
,
tx
:=
range
txs
{
dump
[
fmt
.
Sprintf
(
"%d"
,
nonce
)]
=
format
(
tx
)
}
content
[
"pending"
][
account
.
Hex
()]
=
dump
}
// Flatten the queued transactions
for
account
,
batches
:=
range
queue
{
dump
:=
make
(
map
[
string
][]
string
)
for
nonce
,
txs
:=
range
batches
{
nonce
:=
fmt
.
Sprintf
(
"%d"
,
nonce
)
for
_
,
tx
:=
range
txs
{
dump
[
nonce
]
=
append
(
dump
[
nonce
],
format
(
tx
))
}
for
account
,
txs
:=
range
queue
{
dump
:=
make
(
map
[
string
]
string
)
for
nonce
,
tx
:=
range
txs
{
dump
[
fmt
.
Sprintf
(
"%d"
,
nonce
)]
=
format
(
tx
)
}
content
[
"queued"
][
account
.
Hex
()]
=
dump
}
...
...
internal/ethapi/backend.go
View file @
795b7042
...
...
@@ -58,7 +58,7 @@ type Backend interface {
GetPoolTransaction
(
txHash
common
.
Hash
)
*
types
.
Transaction
GetPoolNonce
(
ctx
context
.
Context
,
addr
common
.
Address
)
(
uint64
,
error
)
Stats
()
(
pending
int
,
queued
int
)
TxPoolContent
()
(
map
[
common
.
Address
]
map
[
uint64
][]
*
types
.
Transaction
,
map
[
common
.
Address
]
map
[
uint64
][]
*
types
.
Transaction
)
TxPoolContent
()
(
map
[
common
.
Address
]
core
.
TxList
,
map
[
common
.
Address
]
core
.
TxList
)
}
type
State
interface
{
...
...
miner/worker.go
View file @
795b7042
...
...
@@ -68,12 +68,12 @@ type Work struct {
ancestors
*
set
.
Set
// ancestor set (used for checking uncle parent validity)
family
*
set
.
Set
// family set (used for checking uncle invalidity)
uncles
*
set
.
Set
// uncle set
remove
*
set
.
Set
// tx which will be removed
tcount
int
// tx count in cycle
ignoredTransactors
*
set
.
Set
lowGasTransactors
*
set
.
Set
ownedAccounts
*
set
.
Set
lowGasTxs
types
.
Transactions
failedTxs
types
.
Transactions
localMinedBlocks
*
uint64RingBuffer
// the most recent block numbers that were mined locally (used to check block inclusion)
Block
*
types
.
Block
// the new block
...
...
@@ -383,7 +383,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
accounts
:=
self
.
eth
.
AccountManager
()
.
Accounts
()
// Keep track of transactions which return errors so they can be removed
work
.
remove
=
set
.
New
()
work
.
tcount
=
0
work
.
ignoredTransactors
=
set
.
New
()
work
.
lowGasTransactors
=
set
.
New
()
...
...
@@ -533,7 +532,9 @@ func (self *worker) commitNewWork() {
*/
work
.
commitTransactions
(
self
.
mux
,
transactions
,
self
.
gasPrice
,
self
.
chain
)
self
.
eth
.
TxPool
()
.
RemoveTransactions
(
work
.
lowGasTxs
)
self
.
eth
.
TxPool
()
.
RemoveTransactions
(
work
.
failedTxs
)
// compute uncles for the new block.
var
(
...
...
@@ -639,11 +640,10 @@ func (env *Work) commitTransactions(mux *event.TypeMux, transactions types.Trans
// ignore the transactor so no nonce errors will be thrown for this account
// next time the worker is run, they'll be picked up again.
env
.
ignoredTransactors
.
Add
(
from
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Gas limit reached for (%x) in this block. Continue to try smaller txs
\n
"
,
from
[
:
4
])
case
err
!=
nil
:
env
.
remove
.
Add
(
tx
.
Hash
())
case
err
!=
nil
:
env
.
failedTxs
=
append
(
env
.
failedTxs
,
tx
)
if
glog
.
V
(
logger
.
Detail
)
{
glog
.
Infof
(
"TX (%x) failed, will be removed: %v
\n
"
,
tx
.
Hash
()
.
Bytes
()[
:
4
],
err
)
}
...
...
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