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
da7d57e0
Unverified
Commit
da7d57e0
authored
Sep 04, 2017
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: make txpool operate on immutable state
parent
e7408b55
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
233 additions
and
307 deletions
+233
-307
blockchain.go
core/blockchain.go
+0
-12
error.go
core/error.go
+4
-0
state_transition.go
core/state_transition.go
+5
-3
tx_list.go
core/tx_list.go
+1
-0
tx_pool.go
core/tx_pool.go
+114
-89
tx_pool_test.go
core/tx_pool_test.go
+95
-186
api_backend.go
eth/api_backend.go
+0
-8
api.go
internal/ethapi/api.go
+0
-1
backend.go
internal/ethapi/backend.go
+0
-1
worker.go
miner/worker.go
+14
-7
No files found.
core/blockchain.go
View file @
da7d57e0
...
...
@@ -81,7 +81,6 @@ type BlockChain struct {
hc
*
HeaderChain
chainDb
ethdb
.
Database
rmTxFeed
event
.
Feed
rmLogsFeed
event
.
Feed
chainFeed
event
.
Feed
chainSideFeed
event
.
Feed
...
...
@@ -1194,15 +1193,9 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
for
_
,
tx
:=
range
diff
{
DeleteTxLookupEntry
(
bc
.
chainDb
,
tx
.
Hash
())
}
// Must be posted in a goroutine because of the transaction pool trying
// to acquire the chain manager lock
if
len
(
diff
)
>
0
{
go
bc
.
rmTxFeed
.
Send
(
RemovedTransactionEvent
{
diff
})
}
if
len
(
deletedLogs
)
>
0
{
go
bc
.
rmLogsFeed
.
Send
(
RemovedLogsEvent
{
deletedLogs
})
}
if
len
(
oldChain
)
>
0
{
go
func
()
{
for
_
,
block
:=
range
oldChain
{
...
...
@@ -1401,11 +1394,6 @@ func (bc *BlockChain) Config() *params.ChainConfig { return bc.config }
// Engine retrieves the blockchain's consensus engine.
func
(
bc
*
BlockChain
)
Engine
()
consensus
.
Engine
{
return
bc
.
engine
}
// SubscribeRemovedTxEvent registers a subscription of RemovedTransactionEvent.
func
(
bc
*
BlockChain
)
SubscribeRemovedTxEvent
(
ch
chan
<-
RemovedTransactionEvent
)
event
.
Subscription
{
return
bc
.
scope
.
Track
(
bc
.
rmTxFeed
.
Subscribe
(
ch
))
}
// SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
func
(
bc
*
BlockChain
)
SubscribeRemovedLogsEvent
(
ch
chan
<-
RemovedLogsEvent
)
event
.
Subscription
{
return
bc
.
scope
.
Track
(
bc
.
rmLogsFeed
.
Subscribe
(
ch
))
...
...
core/error.go
View file @
da7d57e0
...
...
@@ -28,4 +28,8 @@ var (
// ErrBlacklistedHash is returned if a block to import is on the blacklist.
ErrBlacklistedHash
=
errors
.
New
(
"blacklisted hash"
)
// ErrNonceTooHigh is returned if the nonce of a transaction is higher than the
// next one expected based on the local chain.
ErrNonceTooHigh
=
errors
.
New
(
"nonce too high"
)
)
core/state_transition.go
View file @
da7d57e0
...
...
@@ -18,7 +18,6 @@ package core
import
(
"errors"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -197,8 +196,11 @@ func (st *StateTransition) preCheck() error {
// Make sure this transaction's nonce is correct
if
msg
.
CheckNonce
()
{
if
n
:=
st
.
state
.
GetNonce
(
sender
.
Address
());
n
!=
msg
.
Nonce
()
{
return
fmt
.
Errorf
(
"invalid nonce: have %d, expected %d"
,
msg
.
Nonce
(),
n
)
nonce
:=
st
.
state
.
GetNonce
(
sender
.
Address
())
if
nonce
<
msg
.
Nonce
()
{
return
ErrNonceTooHigh
}
else
if
nonce
>
msg
.
Nonce
()
{
return
ErrNonceTooLow
}
}
return
st
.
buyGas
()
...
...
core/tx_list.go
View file @
da7d57e0
...
...
@@ -298,6 +298,7 @@ func (l *txList) Filter(costLimit, gasLimit *big.Int) (types.Transactions, types
// If the list was strict, filter anything above the lowest nonce
var
invalids
types
.
Transactions
if
l
.
strict
&&
len
(
removed
)
>
0
{
lowest
:=
uint64
(
math
.
MaxUint64
)
for
_
,
tx
:=
range
removed
{
...
...
core/tx_pool.go
View file @
da7d57e0
This diff is collapsed.
Click to expand it.
core/tx_pool_test.go
View file @
da7d57e0
This diff is collapsed.
Click to expand it.
eth/api_backend.go
View file @
da7d57e0
...
...
@@ -115,10 +115,6 @@ func (b *EthApiBackend) GetEVM(ctx context.Context, msg core.Message, state *sta
return
vm
.
NewEVM
(
context
,
state
,
b
.
eth
.
chainConfig
,
vmCfg
),
vmError
,
nil
}
func
(
b
*
EthApiBackend
)
SubscribeRemovedTxEvent
(
ch
chan
<-
core
.
RemovedTransactionEvent
)
event
.
Subscription
{
return
b
.
eth
.
BlockChain
()
.
SubscribeRemovedTxEvent
(
ch
)
}
func
(
b
*
EthApiBackend
)
SubscribeRemovedLogsEvent
(
ch
chan
<-
core
.
RemovedLogsEvent
)
event
.
Subscription
{
return
b
.
eth
.
BlockChain
()
.
SubscribeRemovedLogsEvent
(
ch
)
}
...
...
@@ -143,10 +139,6 @@ func (b *EthApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
return
b
.
eth
.
txPool
.
AddLocal
(
signedTx
)
}
func
(
b
*
EthApiBackend
)
RemoveTx
(
txHash
common
.
Hash
)
{
b
.
eth
.
txPool
.
Remove
(
txHash
)
}
func
(
b
*
EthApiBackend
)
GetPoolTransactions
()
(
types
.
Transactions
,
error
)
{
pending
,
err
:=
b
.
eth
.
txPool
.
Pending
()
if
err
!=
nil
{
...
...
internal/ethapi/api.go
View file @
da7d57e0
...
...
@@ -1265,7 +1265,6 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxAr
if
err
!=
nil
{
return
common
.
Hash
{},
err
}
s
.
b
.
RemoveTx
(
p
.
Hash
())
if
err
=
s
.
b
.
SendTx
(
ctx
,
signedTx
);
err
!=
nil
{
return
common
.
Hash
{},
err
}
...
...
internal/ethapi/backend.go
View file @
da7d57e0
...
...
@@ -59,7 +59,6 @@ type Backend interface {
// TxPool API
SendTx
(
ctx
context
.
Context
,
signedTx
*
types
.
Transaction
)
error
RemoveTx
(
txHash
common
.
Hash
)
GetPoolTransactions
()
(
types
.
Transactions
,
error
)
GetPoolTransaction
(
txHash
common
.
Hash
)
*
types
.
Transaction
GetPoolNonce
(
ctx
context
.
Context
,
addr
common
.
Address
)
(
uint64
,
error
)
...
...
miner/worker.go
View file @
da7d57e0
...
...
@@ -71,7 +71,6 @@ type Work struct {
family
*
set
.
Set
// family set (used for checking uncle invalidity)
uncles
*
set
.
Set
// uncle set
tcount
int
// tx count in cycle
failedTxs
types
.
Transactions
Block
*
types
.
Block
// the new block
...
...
@@ -477,8 +476,6 @@ func (self *worker) commitNewWork() {
txs
:=
types
.
NewTransactionsByPriceAndNonce
(
pending
)
work
.
commitTransactions
(
self
.
mux
,
txs
,
self
.
chain
,
self
.
coinbase
)
self
.
eth
.
TxPool
()
.
RemoveBatch
(
work
.
failedTxs
)
// compute uncles for the new block.
var
(
uncles
[]
*
types
.
Header
...
...
@@ -563,6 +560,16 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
log
.
Trace
(
"Gas limit exceeded for current block"
,
"sender"
,
from
)
txs
.
Pop
()
case
core
.
ErrNonceTooLow
:
// New head notification data race between the transaction pool and miner, shift
log
.
Trace
(
"Skipping transaction with low nonce"
,
"sender"
,
from
,
"nonce"
,
tx
.
Nonce
())
txs
.
Shift
()
case
core
.
ErrNonceTooHigh
:
// Reorg notification data race between the transaction pool and miner, skip account =
log
.
Trace
(
"Skipping account with hight nonce"
,
"sender"
,
from
,
"nonce"
,
tx
.
Nonce
())
txs
.
Pop
()
case
nil
:
// Everything ok, collect the logs and shift in the next transaction from the same account
coalescedLogs
=
append
(
coalescedLogs
,
logs
...
)
...
...
@@ -570,10 +577,10 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
txs
.
Shift
()
default
:
//
Pop the current failed transaction without shifting in the next from the account
log
.
Trace
(
"Transaction failed, will be removed"
,
"hash"
,
tx
.
Hash
(),
"err"
,
err
)
env
.
failedTxs
=
append
(
env
.
failedTxs
,
tx
)
txs
.
Pop
()
//
Strange error, discard the transaction and get the next in line (note, the
// nonce-too-high clause will prevent us from executing in vain).
log
.
Debug
(
"Transaction failed, account skipped"
,
"hash"
,
tx
.
Hash
(),
"err"
,
err
)
txs
.
Shift
()
}
}
...
...
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