Commit 795b7042 authored by Péter Szilágyi's avatar Péter Szilágyi

core, eth, miner: only retain 1 tx/nonce, remove bad ones

parent 49227f65
This diff is collapsed.
This diff is collapsed.
...@@ -149,7 +149,7 @@ func (b *EthApiBackend) Stats() (pending int, queued int) { ...@@ -149,7 +149,7 @@ func (b *EthApiBackend) Stats() (pending int, queued int) {
return b.eth.txPool.Stats() 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() b.eth.txMu.Lock()
defer b.eth.txMu.Unlock() defer b.eth.txMu.Unlock()
......
...@@ -100,32 +100,26 @@ func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI { ...@@ -100,32 +100,26 @@ func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI {
} }
// Content returns the transactions contained within the transaction pool. // Content returns the transactions contained within the transaction pool.
func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string][]*RPCTransaction { func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction {
content := map[string]map[string]map[string][]*RPCTransaction{ content := map[string]map[string]map[string]*RPCTransaction{
"pending": make(map[string]map[string][]*RPCTransaction), "pending": make(map[string]map[string]*RPCTransaction),
"queued": make(map[string]map[string][]*RPCTransaction), "queued": make(map[string]map[string]*RPCTransaction),
} }
pending, queue := s.b.TxPoolContent() pending, queue := s.b.TxPoolContent()
// Flatten the pending transactions // Flatten the pending transactions
for account, batches := range pending { for account, txs := range pending {
dump := make(map[string][]*RPCTransaction) dump := make(map[string]*RPCTransaction)
for nonce, txs := range batches { for nonce, tx := range txs {
nonce := fmt.Sprintf("%d", nonce) dump[fmt.Sprintf("%d", nonce)] = newRPCPendingTransaction(tx)
for _, tx := range txs {
dump[nonce] = append(dump[nonce], newRPCPendingTransaction(tx))
}
} }
content["pending"][account.Hex()] = dump content["pending"][account.Hex()] = dump
} }
// Flatten the queued transactions // Flatten the queued transactions
for account, batches := range queue { for account, txs := range queue {
dump := make(map[string][]*RPCTransaction) dump := make(map[string]*RPCTransaction)
for nonce, txs := range batches { for nonce, tx := range txs {
nonce := fmt.Sprintf("%d", nonce) dump[fmt.Sprintf("%d", nonce)] = newRPCPendingTransaction(tx)
for _, tx := range txs {
dump[nonce] = append(dump[nonce], newRPCPendingTransaction(tx))
}
} }
content["queued"][account.Hex()] = dump content["queued"][account.Hex()] = dump
} }
...@@ -143,10 +137,10 @@ func (s *PublicTxPoolAPI) Status() map[string]*rpc.HexNumber { ...@@ -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 // Inspect retrieves the content of the transaction pool and flattens it into an
// easily inspectable list. // easily inspectable list.
func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string][]string { func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string {
content := map[string]map[string]map[string][]string{ content := map[string]map[string]map[string]string{
"pending": make(map[string]map[string][]string), "pending": make(map[string]map[string]string),
"queued": make(map[string]map[string][]string), "queued": make(map[string]map[string]string),
} }
pending, queue := s.b.TxPoolContent() pending, queue := s.b.TxPoolContent()
...@@ -158,24 +152,18 @@ func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string][]string { ...@@ -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()) return fmt.Sprintf("contract creation: %v wei + %v × %v gas", tx.Value(), tx.Gas(), tx.GasPrice())
} }
// Flatten the pending transactions // Flatten the pending transactions
for account, batches := range pending { for account, txs := range pending {
dump := make(map[string][]string) dump := make(map[string]string)
for nonce, txs := range batches { for nonce, tx := range txs {
nonce := fmt.Sprintf("%d", nonce) dump[fmt.Sprintf("%d", nonce)] = format(tx)
for _, tx := range txs {
dump[nonce] = append(dump[nonce], format(tx))
}
} }
content["pending"][account.Hex()] = dump content["pending"][account.Hex()] = dump
} }
// Flatten the queued transactions // Flatten the queued transactions
for account, batches := range queue { for account, txs := range queue {
dump := make(map[string][]string) dump := make(map[string]string)
for nonce, txs := range batches { for nonce, tx := range txs {
nonce := fmt.Sprintf("%d", nonce) dump[fmt.Sprintf("%d", nonce)] = format(tx)
for _, tx := range txs {
dump[nonce] = append(dump[nonce], format(tx))
}
} }
content["queued"][account.Hex()] = dump content["queued"][account.Hex()] = dump
} }
......
...@@ -58,7 +58,7 @@ type Backend interface { ...@@ -58,7 +58,7 @@ type Backend interface {
GetPoolTransaction(txHash common.Hash) *types.Transaction GetPoolTransaction(txHash common.Hash) *types.Transaction
GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
Stats() (pending int, queued int) 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 { type State interface {
......
...@@ -68,12 +68,12 @@ type Work struct { ...@@ -68,12 +68,12 @@ type Work struct {
ancestors *set.Set // ancestor set (used for checking uncle parent validity) ancestors *set.Set // ancestor set (used for checking uncle parent validity)
family *set.Set // family set (used for checking uncle invalidity) family *set.Set // family set (used for checking uncle invalidity)
uncles *set.Set // uncle set uncles *set.Set // uncle set
remove *set.Set // tx which will be removed
tcount int // tx count in cycle tcount int // tx count in cycle
ignoredTransactors *set.Set ignoredTransactors *set.Set
lowGasTransactors *set.Set lowGasTransactors *set.Set
ownedAccounts *set.Set ownedAccounts *set.Set
lowGasTxs types.Transactions lowGasTxs types.Transactions
failedTxs types.Transactions
localMinedBlocks *uint64RingBuffer // the most recent block numbers that were mined locally (used to check block inclusion) localMinedBlocks *uint64RingBuffer // the most recent block numbers that were mined locally (used to check block inclusion)
Block *types.Block // the new block Block *types.Block // the new block
...@@ -383,7 +383,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error ...@@ -383,7 +383,6 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
accounts := self.eth.AccountManager().Accounts() accounts := self.eth.AccountManager().Accounts()
// Keep track of transactions which return errors so they can be removed // Keep track of transactions which return errors so they can be removed
work.remove = set.New()
work.tcount = 0 work.tcount = 0
work.ignoredTransactors = set.New() work.ignoredTransactors = set.New()
work.lowGasTransactors = set.New() work.lowGasTransactors = set.New()
...@@ -533,7 +532,9 @@ func (self *worker) commitNewWork() { ...@@ -533,7 +532,9 @@ func (self *worker) commitNewWork() {
*/ */
work.commitTransactions(self.mux, transactions, self.gasPrice, self.chain) work.commitTransactions(self.mux, transactions, self.gasPrice, self.chain)
self.eth.TxPool().RemoveTransactions(work.lowGasTxs) self.eth.TxPool().RemoveTransactions(work.lowGasTxs)
self.eth.TxPool().RemoveTransactions(work.failedTxs)
// compute uncles for the new block. // compute uncles for the new block.
var ( var (
...@@ -639,11 +640,10 @@ func (env *Work) commitTransactions(mux *event.TypeMux, transactions types.Trans ...@@ -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 // 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. // next time the worker is run, they'll be picked up again.
env.ignoredTransactors.Add(from) 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]) 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) { if glog.V(logger.Detail) {
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment