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