Tests that if the transaction count belonging to a single account goes above some threshold, the higher transactions are dropped to prevent DOS attacks.
(t *testing.T)
| 723 | // Tests that if the transaction count belonging to a single account goes above |
| 724 | // some threshold, the higher transactions are dropped to prevent DOS attacks. |
| 725 | func TestTransactionQueueAccountLimiting(t *testing.T) { |
| 726 | t.Parallel() |
| 727 | |
| 728 | // Create a test account and fund it |
| 729 | pool, key := setupTxPool() |
| 730 | defer pool.Stop() |
| 731 | |
| 732 | account, _ := deriveSender(transaction(0, 0, key)) |
| 733 | pool.currentState.AddBalance(account, big.NewInt(1000000)) |
| 734 | |
| 735 | // Keep queuing up transactions and make sure all above a limit are dropped |
| 736 | for i := uint64(1); i <= testTxPoolConfig.AccountQueue+5; i++ { |
| 737 | if err := pool.AddRemote(transaction(i, 100000, key)); err != nil { |
| 738 | t.Fatalf("tx %d: failed to add transaction: %v", i, err) |
| 739 | } |
| 740 | if len(pool.pending) != 0 { |
| 741 | t.Errorf("tx %d: pending pool size mismatch: have %d, want %d", i, len(pool.pending), 0) |
| 742 | } |
| 743 | if i <= testTxPoolConfig.AccountQueue { |
| 744 | if pool.queue[account].Len() != int(i) { |
| 745 | t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, pool.queue[account].Len(), i) |
| 746 | } |
| 747 | } else { |
| 748 | if pool.queue[account].Len() != int(testTxPoolConfig.AccountQueue) { |
| 749 | t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, pool.queue[account].Len(), testTxPoolConfig.AccountQueue) |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | if pool.all.Count() != int(testTxPoolConfig.AccountQueue) { |
| 754 | t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue) |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | // Tests that if the transaction count belonging to multiple accounts go above |
| 759 | // some threshold, the higher transactions are dropped to prevent DOS attacks. |
nothing calls this directly
no test coverage detected