Tests that if the transaction count belonging to multiple accounts go above some hard threshold, the higher transactions are dropped to prevent DOS attacks.
(t *testing.T)
| 1010 | // some hard threshold, the higher transactions are dropped to prevent DOS |
| 1011 | // attacks. |
| 1012 | func TestTransactionPendingGlobalLimiting(t *testing.T) { |
| 1013 | t.Parallel() |
| 1014 | |
| 1015 | // Create the pool to test the limit enforcement with |
| 1016 | statedb, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase())) |
| 1017 | blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} |
| 1018 | |
| 1019 | config := testTxPoolConfig |
| 1020 | config.GlobalSlots = config.AccountSlots * 10 |
| 1021 | |
| 1022 | pool := NewTxPool(config, configs.TestChainConfig, blockchain) |
| 1023 | defer pool.Stop() |
| 1024 | |
| 1025 | // Create a number of test accounts and fund them |
| 1026 | keys := make([]*ecdsa.PrivateKey, 5) |
| 1027 | for i := 0; i < len(keys); i++ { |
| 1028 | keys[i], _ = crypto.GenerateKey() |
| 1029 | pool.currentState.AddBalance(crypto.PubkeyToAddress(keys[i].PublicKey), big.NewInt(1000000)) |
| 1030 | } |
| 1031 | // Generate and queue a batch of transactions |
| 1032 | nonces := make(map[common.Address]uint64) |
| 1033 | |
| 1034 | txs := types.Transactions{} |
| 1035 | for _, key := range keys { |
| 1036 | addr := crypto.PubkeyToAddress(key.PublicKey) |
| 1037 | for j := 0; j < int(config.GlobalSlots)/len(keys)*2; j++ { |
| 1038 | txs = append(txs, transaction(nonces[addr], 100000, key)) |
| 1039 | nonces[addr]++ |
| 1040 | } |
| 1041 | } |
| 1042 | // Import the batch and verify that limits have been enforced |
| 1043 | pool.AddRemotes(txs) |
| 1044 | |
| 1045 | pending := 0 |
| 1046 | for _, list := range pool.pending { |
| 1047 | pending += list.Len() |
| 1048 | } |
| 1049 | if pending > int(config.GlobalSlots) { |
| 1050 | t.Fatalf("total pending transactions overflow allowance: %d > %d", pending, config.GlobalSlots) |
| 1051 | } |
| 1052 | if err := validateTxPoolInternals(pool); err != nil { |
| 1053 | t.Fatalf("pool internal state corrupted: %v", err) |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | // Tests that if transactions start being capped, transactions are also removed from 'all' |
| 1058 | func TestTransactionCapClearsFromAll(t *testing.T) { |
nothing calls this directly
no test coverage detected