[release/1.4.17] core, eth, internal, miner: optimize txpool for quick ops

(cherry picked from commit 0ef327bbee)
This commit is contained in:
Péter Szilágyi
2016-07-01 18:59:55 +03:00
committed by Felix Lange
parent df64a9f5ef
commit ff697e82dc
13 changed files with 812 additions and 452 deletions

View File

@ -979,7 +979,7 @@ func getTransaction(chainDb ethdb.Database, txPool *core.TxPool, txHash common.H
}
} else {
// pending transaction?
tx = txPool.GetTransaction(txHash)
tx = txPool.Get(txHash)
isPending = true
}
@ -1391,12 +1391,13 @@ func (s *PublicTransactionPoolAPI) SignTransaction(args SignTransactionArgs) (*S
// PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of
// the accounts this node manages.
func (s *PublicTransactionPoolAPI) PendingTransactions() []*RPCTransaction {
pending := s.txPool.GetTransactions()
pending := s.txPool.Pending()
transactions := make([]*RPCTransaction, 0, len(pending))
for _, tx := range pending {
from, _ := tx.FromFrontier()
if s.am.HasAddress(from) {
transactions = append(transactions, newRPCPendingTransaction(tx))
for addr, txs := range pending {
if s.am.HasAddress(addr) {
for _, tx := range txs {
transactions = append(transactions, newRPCPendingTransaction(tx))
}
}
}
return transactions
@ -1430,35 +1431,36 @@ func (s *PublicTransactionPoolAPI) NewPendingTransactions(ctx context.Context) (
// Resend accepts an existing transaction and a new gas price and limit. It will remove the given transaction from the
// pool and reinsert it with the new gas price and limit.
func (s *PublicTransactionPoolAPI) Resend(tx Tx, gasPrice, gasLimit *rpc.HexNumber) (common.Hash, error) {
pending := s.txPool.Pending()
for addr, txs := range pending {
for _, p := range txs {
if addr == tx.From && p.SigHash() == tx.tx.SigHash() {
if gasPrice == nil {
gasPrice = rpc.NewHexNumber(tx.tx.GasPrice())
}
if gasLimit == nil {
gasLimit = rpc.NewHexNumber(tx.tx.Gas())
}
pending := s.txPool.GetTransactions()
for _, p := range pending {
if pFrom, err := p.FromFrontier(); err == nil && pFrom == tx.From && p.SigHash() == tx.tx.SigHash() {
if gasPrice == nil {
gasPrice = rpc.NewHexNumber(tx.tx.GasPrice())
}
if gasLimit == nil {
gasLimit = rpc.NewHexNumber(tx.tx.Gas())
}
var newTx *types.Transaction
if tx.tx.To() == nil {
newTx = types.NewContractCreation(tx.tx.Nonce(), tx.tx.Value(), gasPrice.BigInt(), gasLimit.BigInt(), tx.tx.Data())
} else {
newTx = types.NewTransaction(tx.tx.Nonce(), *tx.tx.To(), tx.tx.Value(), gasPrice.BigInt(), gasLimit.BigInt(), tx.tx.Data())
}
var newTx *types.Transaction
if tx.tx.To() == nil {
newTx = types.NewContractCreation(tx.tx.Nonce(), tx.tx.Value(), gasPrice.BigInt(), gasLimit.BigInt(), tx.tx.Data())
} else {
newTx = types.NewTransaction(tx.tx.Nonce(), *tx.tx.To(), tx.tx.Value(), gasPrice.BigInt(), gasLimit.BigInt(), tx.tx.Data())
}
signedTx, err := s.sign(tx.From, newTx)
if err != nil {
return common.Hash{}, err
}
signedTx, err := s.sign(tx.From, newTx)
if err != nil {
return common.Hash{}, err
}
s.txPool.Remove(tx.Hash)
if err = s.txPool.Add(signedTx); err != nil {
return common.Hash{}, err
}
s.txPool.RemoveTx(tx.Hash)
if err = s.txPool.Add(signedTx); err != nil {
return common.Hash{}, err
return signedTx.Hash(), nil
}
return signedTx.Hash(), nil
}
}