Skip to content

Commit

Permalink
Merge pull request ethereum#16 from yihuang/release/v1.11.x
Browse files Browse the repository at this point in the history
Problem: Transaction not re-usable in core msg
  • Loading branch information
yihuang authored Apr 25, 2024
2 parents 43cf32d + a1e4ed7 commit ebb0950
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 2 additions & 8 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io"
"math/big"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand All @@ -49,8 +48,7 @@ const (

// Transaction is an Ethereum transaction.
type Transaction struct {
inner TxData // Consensus contents of a transaction
time time.Time // Time first seen locally (spam avoidance)
inner TxData // Consensus contents of a transaction

// caches
hash atomic.Value
Expand Down Expand Up @@ -200,7 +198,6 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
// setDecoded sets the inner transaction and size after decoding.
func (tx *Transaction) setDecoded(inner TxData, size uint64) {
tx.inner = inner
tx.time = time.Now()
if size > 0 {
tx.size.Store(size)
}
Expand Down Expand Up @@ -406,7 +403,7 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e
}
cpy := tx.inner.copy()
cpy.setSignatureValues(signer.ChainID(), v, r, s)
return &Transaction{inner: cpy, time: tx.time}, nil
return &Transaction{inner: cpy}, nil
}

// Transactions implements DerivableList for transactions.
Expand Down Expand Up @@ -501,9 +498,6 @@ func (s TxByPriceAndTime) Less(i, j int) bool {
// If the prices are equal, use the time the transaction was first seen for
// deterministic sorting
cmp := s[i].minerFee.Cmp(s[j].minerFee)
if cmp == 0 {
return s[i].tx.time.Before(s[j].tx.time)
}
return cmp > 0
}
func (s TxByPriceAndTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
Expand Down
10 changes: 5 additions & 5 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"math/rand"
"reflect"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -360,6 +359,8 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) {
// Tests that if multiple transactions have the same price, the ones seen earlier
// are prioritized to avoid network spam attacks aiming for a specific ordering.
func TestTransactionTimeSort(t *testing.T) {
t.Skip("time field is removed")

// Generate a batch of accounts to start with
keys := make([]*ecdsa.PrivateKey, 5)
for i := 0; i < len(keys); i++ {
Expand All @@ -369,11 +370,10 @@ func TestTransactionTimeSort(t *testing.T) {

// Generate a batch of transactions with overlapping prices, but different creation times
groups := map[common.Address]Transactions{}
for start, key := range keys {
for _, key := range keys {
addr := crypto.PubkeyToAddress(key.PublicKey)

tx, _ := SignTx(NewTransaction(0, common.Address{}, big.NewInt(100), 100, big.NewInt(1), nil), signer, key)
tx.time = time.Unix(0, int64(len(keys)-start))

groups[addr] = append(groups[addr], tx)
}
Expand All @@ -398,8 +398,8 @@ func TestTransactionTimeSort(t *testing.T) {
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", i, fromi[:4], txi.GasPrice(), i+1, fromNext[:4], next.GasPrice())
}
// Make sure time order is ascending if the txs have the same gas price
if txi.GasPrice().Cmp(next.GasPrice()) == 0 && txi.time.After(next.time) {
t.Errorf("invalid received time ordering: tx #%d (A=%x T=%v) > tx #%d (A=%x T=%v)", i, fromi[:4], txi.time, i+1, fromNext[:4], next.time)
if txi.GasPrice().Cmp(next.GasPrice()) == 0 {
t.Errorf("invalid received time ordering: tx #%d (A=%x) > tx #%d (A=%x)", i, fromi[:4], i+1, fromNext[:4])
}
}
}
Expand Down

0 comments on commit ebb0950

Please sign in to comment.