Skip to content

Commit a52f2ad

Browse files
authored
Revert "core/txpool/legacypool: fix flaky test TestAllowedTxSize (ethereum#30975)"
This reverts commit fcf5204.
1 parent 58f65c6 commit a52f2ad

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

core/txpool/legacypool/legacypool_test.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,28 +1202,33 @@ func TestAllowedTxSize(t *testing.T) {
12021202
account := crypto.PubkeyToAddress(key.PublicKey)
12031203
testAddBalance(pool, account, big.NewInt(1000000000))
12041204

1205-
// Find the maximum data length for the kind of transaction which will
1206-
// be generated in the pool.addRemoteSync calls below.
1207-
const largeDataLength = txMaxSize - 200 // enough to have a 5 bytes RLP encoding of the data length number
1208-
txWithLargeData := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(1), key, largeDataLength)
1209-
maxTxLengthWithoutData := txWithLargeData.Size() - largeDataLength // 103 bytes
1210-
maxTxDataLength := txMaxSize - maxTxLengthWithoutData // 131072 - 103 = 130953 bytes
1211-
1205+
// Compute maximal data size for transactions (lower bound).
1206+
//
1207+
// It is assumed the fields in the transaction (except of the data) are:
1208+
// - nonce <= 32 bytes
1209+
// - gasTip <= 32 bytes
1210+
// - gasLimit <= 32 bytes
1211+
// - recipient == 20 bytes
1212+
// - value <= 32 bytes
1213+
// - signature == 65 bytes
1214+
// All those fields are summed up to at most 213 bytes.
1215+
baseSize := uint64(213)
1216+
dataSize := txMaxSize - baseSize
12121217
// Try adding a transaction with maximal allowed size
1213-
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(1), key, maxTxDataLength)
1218+
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(1), key, dataSize)
12141219
if err := pool.addRemoteSync(tx); err != nil {
12151220
t.Fatalf("failed to add transaction of size %d, close to maximal: %v", int(tx.Size()), err)
12161221
}
12171222
// Try adding a transaction with random allowed size
1218-
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, big.NewInt(1), key, uint64(rand.Intn(int(maxTxDataLength+1))))); err != nil {
1223+
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, big.NewInt(1), key, uint64(rand.Intn(int(dataSize))))); err != nil {
12191224
t.Fatalf("failed to add transaction of random allowed size: %v", err)
12201225
}
1221-
// Try adding a transaction above maximum size by one
1222-
if err := pool.addRemoteSync(pricedDataTransaction(2, pool.currentHead.Load().GasLimit, big.NewInt(1), key, maxTxDataLength+1)); err == nil {
1226+
// Try adding a transaction of minimal not allowed size
1227+
if err := pool.addRemoteSync(pricedDataTransaction(2, pool.currentHead.Load().GasLimit, big.NewInt(1), key, txMaxSize)); err == nil {
12231228
t.Fatalf("expected rejection on slightly oversize transaction")
12241229
}
1225-
// Try adding a transaction above maximum size by more than one
1226-
if err := pool.addRemoteSync(pricedDataTransaction(2, pool.currentHead.Load().GasLimit, big.NewInt(1), key, maxTxDataLength+1+uint64(rand.Intn(10*txMaxSize)))); err == nil {
1230+
// Try adding a transaction of random not allowed size
1231+
if err := pool.addRemoteSync(pricedDataTransaction(2, pool.currentHead.Load().GasLimit, big.NewInt(1), key, dataSize+1+uint64(rand.Intn(10*txMaxSize)))); err == nil {
12271232
t.Fatalf("expected rejection on oversize transaction")
12281233
}
12291234
// Run some sanity checks on the pool internals

0 commit comments

Comments
 (0)