aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
diff options
context:
space:
mode:
authorbas-vk <bas-vk@users.noreply.github.com>2016-12-11 06:54:58 +0800
committerFelix Lange <fjl@users.noreply.github.com>2016-12-11 06:54:58 +0800
commit4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a (patch)
treecf54f3d14e4ac9f177b6951f92f898d8c7c9a744 /internal/ethapi/api.go
parent0fe35b907addf1c066cb4d7c717bb23f9f2e7be4 (diff)
downloaddexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.gz
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.bz2
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.lz
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.xz
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.zst
dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.zip
core: bugfix state change race condition in txpool (#3412)
The transaction pool keeps track of the current nonce in its local pendingState. When a new block comes in the pendingState is reset. During the reset it fetches multiple times the current state through the use of the currentState callback. When a second block comes in during the reset its possible that the state changes during the reset. If that block holds transactions that are currently in the pool the local pendingState that is used to determine nonces can get out of sync.
Diffstat (limited to 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index a25eff5ed..fd86b6465 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -1273,8 +1273,12 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Sig
// 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.b.GetPoolTransactions()
+func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error) {
+ pending, err := s.b.GetPoolTransactions()
+ if err != nil {
+ return nil, err
+ }
+
transactions := make([]*RPCTransaction, 0, len(pending))
for _, tx := range pending {
var signer types.Signer = types.HomesteadSigner{}
@@ -1286,13 +1290,17 @@ func (s *PublicTransactionPoolAPI) PendingTransactions() []*RPCTransaction {
transactions = append(transactions, newRPCPendingTransaction(tx))
}
}
- return transactions
+ return transactions, nil
}
// 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(ctx context.Context, tx Tx, gasPrice, gasLimit *rpc.HexNumber) (common.Hash, error) {
- pending := s.b.GetPoolTransactions()
+ pending, err := s.b.GetPoolTransactions()
+ if err != nil {
+ return common.Hash{}, err
+ }
+
for _, p := range pending {
var signer types.Signer = types.HomesteadSigner{}
if p.Protected() {