bugfix, pending transaction was resend with new gas price/limit but not removed from transaction pool

This commit is contained in:
Bas van Kervel 2015-07-10 11:35:15 +02:00
parent 5a810758db
commit 7e31df3987
4 changed files with 23 additions and 10 deletions

View File

@ -356,11 +356,12 @@ func (self *TxPool) RemoveTransactions(txs types.Transactions) {
self.mu.Lock() self.mu.Lock()
defer self.mu.Unlock() defer self.mu.Unlock()
for _, tx := range txs { for _, tx := range txs {
self.removeTx(tx.Hash()) self.RemoveTx(tx.Hash())
} }
} }
func (pool *TxPool) removeTx(hash common.Hash) { // RemoveTx removes the transaction with the given hash from the pool.
func (pool *TxPool) RemoveTx(hash common.Hash) {
// delete from pending pool // delete from pending pool
delete(pool.pending, hash) delete(pool.pending, hash)
// delete from queue // delete from queue

View File

@ -130,7 +130,7 @@ func TestRemoveTx(t *testing.T) {
t.Error("expected txs to be 1, got", len(pool.pending)) t.Error("expected txs to be 1, got", len(pool.pending))
} }
pool.removeTx(tx.Hash()) pool.RemoveTx(tx.Hash())
if len(pool.queue) > 0 { if len(pool.queue) > 0 {
t.Error("expected queue to be 0, got", len(pool.queue)) t.Error("expected queue to be 0, got", len(pool.queue))

View File

@ -21,8 +21,9 @@ import (
"encoding/json" "encoding/json"
"math/big" "math/big"
"fmt"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/rpc/shared"
@ -578,14 +579,17 @@ func (self *ethApi) Resend(req *shared.Request) (interface{}, error) {
return nil, shared.NewDecodeParamError(err.Error()) return nil, shared.NewDecodeParamError(err.Error())
} }
ret, err := self.xeth.Transact(args.Tx.From, args.Tx.To, args.Tx.Nonce, args.Tx.Value, args.GasLimit, args.GasPrice, args.Tx.Data) from := common.HexToAddress(args.Tx.From)
if err != nil {
return nil, err pending := self.ethereum.TxPool().GetTransactions()
for _, p := range pending {
if pFrom, err := p.From(); err == nil && pFrom == from && p.SigHash() == args.Tx.tx.SigHash() {
self.ethereum.TxPool().RemoveTx(common.HexToHash(args.Tx.Hash))
return self.xeth.Transact(args.Tx.From, args.Tx.To, args.Tx.Nonce, args.Tx.Value, args.GasLimit, args.GasPrice, args.Tx.Data)
}
} }
self.ethereum.TxPool().RemoveTransactions(types.Transactions{args.Tx.tx}) return nil, fmt.Errorf("Transaction %s not found", args.Tx.Hash)
return ret, nil
} }
func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error) { func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error) {

View File

@ -888,6 +888,7 @@ type tx struct {
Data string Data string
GasLimit string GasLimit string
GasPrice string GasPrice string
Hash string
} }
func newTx(t *types.Transaction) *tx { func newTx(t *types.Transaction) *tx {
@ -906,6 +907,7 @@ func newTx(t *types.Transaction) *tx {
Data: "0x" + common.Bytes2Hex(t.Data()), Data: "0x" + common.Bytes2Hex(t.Data()),
GasLimit: t.Gas().String(), GasLimit: t.Gas().String(),
GasPrice: t.GasPrice().String(), GasPrice: t.GasPrice().String(),
Hash: t.Hash().Hex(),
} }
} }
@ -931,6 +933,12 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) {
contractCreation = true contractCreation = true
) )
if val, found := fields["Hash"]; found {
if hashVal, ok := val.(string); ok {
tx.Hash = hashVal
}
}
if val, found := fields["To"]; found { if val, found := fields["To"]; found {
if strVal, ok := val.(string); ok && len(strVal) > 0 { if strVal, ok := val.(string); ok && len(strVal) > 0 {
tx.To = strVal tx.To = strVal