Skip to content

Commit 340c9b8

Browse files
authored
Revert "Revert "core/txpool/legacypool: fix flaky test TestAllowedTxSize (ethereum#30975)"
This reverts commit fcf5204."
1 parent 0edbd70 commit 340c9b8

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

cmd/evm/testdata/evmrun/3.out.1.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"root": "b444481d1367188172f8c6091e948aaa68bae763fd26d6b9e994306a66bf69f9",
33
"accounts": {
4-
"0x0000000000000000000000007265636569766572": {
4+
"pre(0x30d7a0694cb29af31b982480e11d7ebb003a3fca4026939149071f014689b142)": {
55
"balance": "0",
66
"nonce": 0,
77
"root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
88
"codeHash": "0x3e48ef54b89079a075f3b8fc253c657a86b110a7aed3568c1517b10edf2c3eb6",
99
"code": "0x6040",
10-
"address": "0x0000000000000000000000007265636569766572",
1110
"key": "0x30d7a0694cb29af31b982480e11d7ebb003a3fca4026939149071f014689b142"
1211
}
1312
}

cmd/evm/testdata/evmrun/4.out.1.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"root": "b444481d1367188172f8c6091e948aaa68bae763fd26d6b9e994306a66bf69f9",
33
"accounts": {
4-
"0x0000000000000000000000007265636569766572": {
4+
"pre(0x30d7a0694cb29af31b982480e11d7ebb003a3fca4026939149071f014689b142)": {
55
"balance": "0",
66
"nonce": 0,
77
"root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
88
"codeHash": "0x3e48ef54b89079a075f3b8fc253c657a86b110a7aed3568c1517b10edf2c3eb6",
99
"code": "0x6040",
10-
"address": "0x0000000000000000000000007265636569766572",
1110
"key": "0x30d7a0694cb29af31b982480e11d7ebb003a3fca4026939149071f014689b142"
1211
}
1312
}

core/txpool/legacypool/legacypool_test.go

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

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
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+
12171212
// Try adding a transaction with maximal allowed size
1218-
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(1), key, dataSize)
1213+
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(1), key, maxTxDataLength)
12191214
if err := pool.addRemoteSync(tx); err != nil {
12201215
t.Fatalf("failed to add transaction of size %d, close to maximal: %v", int(tx.Size()), err)
12211216
}
12221217
// Try adding a transaction with random allowed size
1223-
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, big.NewInt(1), key, uint64(rand.Intn(int(dataSize))))); err != nil {
1218+
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, big.NewInt(1), key, uint64(rand.Intn(int(maxTxDataLength+1))))); err != nil {
12241219
t.Fatalf("failed to add transaction of random allowed size: %v", err)
12251220
}
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 {
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 {
12281223
t.Fatalf("expected rejection on slightly oversize transaction")
12291224
}
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 {
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 {
12321227
t.Fatalf("expected rejection on oversize transaction")
12331228
}
12341229
// Run some sanity checks on the pool internals

trie/secure_trie.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ func (t *StateTrie) Copy() *StateTrie {
275275
trie: *t.trie.Copy(),
276276
db: t.db,
277277
secKeyCache: t.secKeyCache,
278-
preimages: t.preimages,
279278
}
280279
}
281280

0 commit comments

Comments
 (0)