Skip to content

Commit

Permalink
Make TxPool ordering deterministic (#2892)
Browse files Browse the repository at this point in the history
* Roll back validator list when block is reverted

* fix error check

* Make TxPool ordering deterministic
  • Loading branch information
rlan35 authored Apr 28, 2020
1 parent 69ff3b5 commit 918dec8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion core/types/tx_pool.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package types

import (
"bytes"
"container/heap"
"io"
"math/big"
"sort"

"github.com/pkg/errors"

Expand Down Expand Up @@ -142,8 +144,19 @@ type PoolTransactionsByPriceAndNonce struct {
// if after providing it to the constructor.
func NewPoolTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]PoolTransactions) *PoolTransactionsByPriceAndNonce {
// Initialize a price based heap with the head transactions
sortedAddrs := []common.Address{}

for from := range txs {
sortedAddrs = append(sortedAddrs, from)
}

sort.SliceStable(sortedAddrs, func(i, j int) bool {
return bytes.Compare(sortedAddrs[i].Bytes(), sortedAddrs[j].Bytes()) < 0
})

heads := make(PoolTxByPrice, 0, len(txs))
for from, accTxs := range txs {
for _, from := range sortedAddrs {
accTxs := txs[from]
heads = append(heads, accTxs[0])
// Ensure the sender address is from the signer
var acc common.Address
Expand Down
2 changes: 1 addition & 1 deletion node/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (w *Worker) CommitTransactions(

// Check whether the tx is replay protected. If we're not in the EIP155 hf
// phase, start ignoring the sender until we do.
if tx.Protected() && !w.config.IsEIP155(w.current.header.Number()) {
if tx.Protected() && !w.config.IsEIP155(w.current.header.Epoch()) {
utils.Logger().Info().Str("hash", tx.Hash().Hex()).Str("eip155Epoch", w.config.EIP155Epoch.String()).Msg("Ignoring reply protected transaction")
txs.Pop()
continue
Expand Down

0 comments on commit 918dec8

Please sign in to comment.