Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/txpool/locals/tx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ type TxTracker struct {

// New creates a new TxTracker
func New(journalPath string, journalTime time.Duration, chainConfig *params.ChainConfig, next *txpool.TxPool) *TxTracker {
pool := &TxTracker{
tracker := &TxTracker{
all: make(map[common.Hash]*types.Transaction),
byAddr: make(map[common.Address]*legacypool.SortedMap),
signer: types.LatestSigner(chainConfig),
shutdownCh: make(chan struct{}),
pool: next,
}
if journalPath != "" {
pool.journal = newTxJournal(journalPath)
pool.rejournal = journalTime
tracker.journal = newTxJournal(journalPath)
tracker.rejournal = journalTime
}
return pool
return tracker
}

// HasTx checks if TxTracker has this tx already.
func (tracker *TxTracker) HasTx(hash common.Hash) bool {
return tracker.all[hash] != nil
}

// Track adds a transaction to the tracked set.
Expand Down
22 changes: 14 additions & 8 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package eth
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/log"
"math/big"
"time"

Expand Down Expand Up @@ -274,18 +275,23 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
locals := b.eth.localTxTracker
if locals != nil {
// If tx tracker already has the tx, that indicates
// the transaction has been submitted once.
// So local tracker should make sure the transaction
// submitted in the end. Just return nil error to inform
// the rpc client that tx has been received.
if locals.HasTx(signedTx.Hash()) {
log.Trace("Tx tracker has transaction and no need to add it to tx-pool", "hash", signedTx.Hash().Hex())
return nil
}
// Transaction won't be tracked if tracker already has it
if err := locals.Track(signedTx); err != nil {
return err
}
}
// No error will be returned to user if the transaction fails stateful
// validation (e.g., no available slot), as the locally submitted transactions
// may be resubmitted later via the local tracker.
err := b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0]
if err != nil && locals == nil {
return err
}
return nil
// The rpc client needs to be informed if there is
// stateful validation problems.
return b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0]
}

func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
Expand Down