Skip to content

Commit ebb0950

Browse files
authored
Merge pull request ethereum#16 from yihuang/release/v1.11.x
Problem: Transaction not re-usable in core msg
2 parents 43cf32d + a1e4ed7 commit ebb0950

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

core/types/transaction.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"io"
2424
"math/big"
2525
"sync/atomic"
26-
"time"
2726

2827
"github.com/ethereum/go-ethereum/common"
2928
"github.com/ethereum/go-ethereum/common/math"
@@ -49,8 +48,7 @@ const (
4948

5049
// Transaction is an Ethereum transaction.
5150
type Transaction struct {
52-
inner TxData // Consensus contents of a transaction
53-
time time.Time // Time first seen locally (spam avoidance)
51+
inner TxData // Consensus contents of a transaction
5452

5553
// caches
5654
hash atomic.Value
@@ -200,7 +198,6 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
200198
// setDecoded sets the inner transaction and size after decoding.
201199
func (tx *Transaction) setDecoded(inner TxData, size uint64) {
202200
tx.inner = inner
203-
tx.time = time.Now()
204201
if size > 0 {
205202
tx.size.Store(size)
206203
}
@@ -406,7 +403,7 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e
406403
}
407404
cpy := tx.inner.copy()
408405
cpy.setSignatureValues(signer.ChainID(), v, r, s)
409-
return &Transaction{inner: cpy, time: tx.time}, nil
406+
return &Transaction{inner: cpy}, nil
410407
}
411408

412409
// Transactions implements DerivableList for transactions.
@@ -501,9 +498,6 @@ func (s TxByPriceAndTime) Less(i, j int) bool {
501498
// If the prices are equal, use the time the transaction was first seen for
502499
// deterministic sorting
503500
cmp := s[i].minerFee.Cmp(s[j].minerFee)
504-
if cmp == 0 {
505-
return s[i].tx.time.Before(s[j].tx.time)
506-
}
507501
return cmp > 0
508502
}
509503
func (s TxByPriceAndTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

core/types/transaction_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"math/rand"
2727
"reflect"
2828
"testing"
29-
"time"
3029

3130
"github.com/ethereum/go-ethereum/common"
3231
"github.com/ethereum/go-ethereum/crypto"
@@ -360,6 +359,8 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) {
360359
// Tests that if multiple transactions have the same price, the ones seen earlier
361360
// are prioritized to avoid network spam attacks aiming for a specific ordering.
362361
func TestTransactionTimeSort(t *testing.T) {
362+
t.Skip("time field is removed")
363+
363364
// Generate a batch of accounts to start with
364365
keys := make([]*ecdsa.PrivateKey, 5)
365366
for i := 0; i < len(keys); i++ {
@@ -369,11 +370,10 @@ func TestTransactionTimeSort(t *testing.T) {
369370

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

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

378378
groups[addr] = append(groups[addr], tx)
379379
}
@@ -398,8 +398,8 @@ func TestTransactionTimeSort(t *testing.T) {
398398
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())
399399
}
400400
// Make sure time order is ascending if the txs have the same gas price
401-
if txi.GasPrice().Cmp(next.GasPrice()) == 0 && txi.time.After(next.time) {
402-
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)
401+
if txi.GasPrice().Cmp(next.GasPrice()) == 0 {
402+
t.Errorf("invalid received time ordering: tx #%d (A=%x) > tx #%d (A=%x)", i, fromi[:4], i+1, fromNext[:4])
403403
}
404404
}
405405
}

0 commit comments

Comments
 (0)