Skip to content

Commit da7d57e

Browse files
committed
core: make txpool operate on immutable state
1 parent e7408b5 commit da7d57e

10 files changed

Lines changed: 233 additions & 307 deletions

File tree

‎core/blockchain.go‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ type BlockChain struct {
8181

8282
hc *HeaderChain
8383
chainDb ethdb.Database
84-
rmTxFeed event.Feed
8584
rmLogsFeed event.Feed
8685
chainFeed event.Feed
8786
chainSideFeed event.Feed
@@ -1194,15 +1193,9 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
11941193
for _, tx := range diff {
11951194
DeleteTxLookupEntry(bc.chainDb, tx.Hash())
11961195
}
1197-
// Must be posted in a goroutine because of the transaction pool trying
1198-
// to acquire the chain manager lock
1199-
if len(diff) > 0 {
1200-
go bc.rmTxFeed.Send(RemovedTransactionEvent{diff})
1201-
}
12021196
if len(deletedLogs) > 0 {
12031197
go bc.rmLogsFeed.Send(RemovedLogsEvent{deletedLogs})
12041198
}
1205-
12061199
if len(oldChain) > 0 {
12071200
go func() {
12081201
for _, block := range oldChain {
@@ -1401,11 +1394,6 @@ func (bc *BlockChain) Config() *params.ChainConfig { return bc.config }
14011394
// Engine retrieves the blockchain's consensus engine.
14021395
func (bc *BlockChain) Engine() consensus.Engine { return bc.engine }
14031396

1404-
// SubscribeRemovedTxEvent registers a subscription of RemovedTransactionEvent.
1405-
func (bc *BlockChain) SubscribeRemovedTxEvent(ch chan<- RemovedTransactionEvent) event.Subscription {
1406-
return bc.scope.Track(bc.rmTxFeed.Subscribe(ch))
1407-
}
1408-
14091397
// SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
14101398
func (bc *BlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription {
14111399
return bc.scope.Track(bc.rmLogsFeed.Subscribe(ch))

‎core/error.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ var (
2828

2929
// ErrBlacklistedHash is returned if a block to import is on the blacklist.
3030
ErrBlacklistedHash = errors.New("blacklisted hash")
31+
32+
// ErrNonceTooHigh is returned if the nonce of a transaction is higher than the
33+
// next one expected based on the local chain.
34+
ErrNonceTooHigh = errors.New("nonce too high")
3135
)

‎core/state_transition.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package core
1818

1919
import (
2020
"errors"
21-
"fmt"
2221
"math/big"
2322

2423
"github.com/ethereum/go-ethereum/common"
@@ -197,8 +196,11 @@ func (st *StateTransition) preCheck() error {
197196

198197
// Make sure this transaction's nonce is correct
199198
if msg.CheckNonce() {
200-
if n := st.state.GetNonce(sender.Address()); n != msg.Nonce() {
201-
return fmt.Errorf("invalid nonce: have %d, expected %d", msg.Nonce(), n)
199+
nonce := st.state.GetNonce(sender.Address())
200+
if nonce < msg.Nonce() {
201+
return ErrNonceTooHigh
202+
} else if nonce > msg.Nonce() {
203+
return ErrNonceTooLow
202204
}
203205
}
204206
return st.buyGas()

‎core/tx_list.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func (l *txList) Filter(costLimit, gasLimit *big.Int) (types.Transactions, types
298298

299299
// If the list was strict, filter anything above the lowest nonce
300300
var invalids types.Transactions
301+
301302
if l.strict && len(removed) > 0 {
302303
lowest := uint64(math.MaxUint64)
303304
for _, tx := range removed {

0 commit comments

Comments
 (0)