@@ -1202,28 +1202,33 @@ func TestAllowedTxSize(t *testing.T) {
1202
1202
account := crypto .PubkeyToAddress (key .PublicKey )
1203
1203
testAddBalance (pool , account , big .NewInt (1000000000 ))
1204
1204
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
1212
1217
// 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 )
1214
1219
if err := pool .addRemoteSync (tx ); err != nil {
1215
1220
t .Fatalf ("failed to add transaction of size %d, close to maximal: %v" , int (tx .Size ()), err )
1216
1221
}
1217
1222
// 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 {
1219
1224
t .Fatalf ("failed to add transaction of random allowed size: %v" , err )
1220
1225
}
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 {
1223
1228
t .Fatalf ("expected rejection on slightly oversize transaction" )
1224
1229
}
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 {
1227
1232
t .Fatalf ("expected rejection on oversize transaction" )
1228
1233
}
1229
1234
// Run some sanity checks on the pool internals
0 commit comments