@@ -719,6 +719,12 @@ func testTransactionLimitingEquivalency(t *testing.T, origin uint64) {
719
719
txns = append (txns , transaction (origin + i , big .NewInt (100000 ), key2 ))
720
720
}
721
721
pool2 .AddBatch (txns )
722
+ if err := pool2 .validateInternals (); err != nil {
723
+ t .Error (err )
724
+ }
725
+ if err := pool1 .validateInternals (); err != nil {
726
+ t .Error (err )
727
+ }
722
728
723
729
// Ensure the batch optimization honors the same pool mechanics
724
730
if len (pool1 .pending ) != len (pool2 .pending ) {
@@ -769,6 +775,9 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
769
775
// Import the batch and verify that limits have been enforced
770
776
pool .AddBatch (txs )
771
777
778
+ if err := pool .validateInternals (); err != nil {
779
+ t .Error (err )
780
+ }
772
781
pending := 0
773
782
for _ , list := range pool .pending {
774
783
pending += list .Len ()
@@ -778,6 +787,42 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
778
787
}
779
788
}
780
789
790
+ // Tests that if transactions start being capped, transasctions are also removed from 'all'
791
+ func TestTransactionCapClearsFromAll (t * testing.T ) {
792
+ // Reduce the queue limits to shorten test time
793
+ defer func (old uint64 ) { DefaultTxPoolConfig .GlobalSlots = old }(DefaultTxPoolConfig .GlobalSlots )
794
+ DefaultTxPoolConfig .AccountSlots = 2
795
+ DefaultTxPoolConfig .AccountQueue = 2
796
+ DefaultTxPoolConfig .GlobalSlots = 8
797
+
798
+ // Create the pool to test the limit enforcement with
799
+ db , _ := ethdb .NewMemDatabase ()
800
+ statedb , _ := state .New (common.Hash {}, db )
801
+
802
+ pool := NewTxPool (DefaultTxPoolConfig , params .TestChainConfig , new (event.TypeMux ), func () (* state.StateDB , error ) { return statedb , nil }, func () * big.Int { return big .NewInt (1000000 ) })
803
+ pool .resetState ()
804
+
805
+ // Create a number of test accounts and fund them
806
+ state , _ := pool .currentState ()
807
+
808
+ key , _ := crypto .GenerateKey ()
809
+ addr := crypto .PubkeyToAddress (key .PublicKey )
810
+ state .AddBalance (addr , big .NewInt (1000000 ))
811
+
812
+ txs := types.Transactions {}
813
+ nonce := uint64 (0 )
814
+ for j := 0 ; j < int (DefaultTxPoolConfig .GlobalSlots )* 2 ; j ++ {
815
+ tx := transaction (nonce , big .NewInt (100000 ), key )
816
+ txs = append (txs , tx )
817
+ nonce ++
818
+ }
819
+ // Import the batch and verify that limits have been enforced
820
+ pool .AddBatch (txs )
821
+ if err := pool .validateInternals (); err != nil {
822
+ t .Error (err )
823
+ }
824
+ }
825
+
781
826
// Tests that if the transaction count belonging to multiple accounts go above
782
827
// some hard threshold, if they are under the minimum guaranteed slot count then
783
828
// the transactions are still kept.
@@ -815,6 +860,10 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
815
860
// Import the batch and verify that limits have been enforced
816
861
pool .AddBatch (txs )
817
862
863
+ if err := pool .validateInternals (); err != nil {
864
+ t .Error (err )
865
+ }
866
+
818
867
for addr , list := range pool .pending {
819
868
if list .Len () != int (DefaultTxPoolConfig .AccountSlots ) {
820
869
t .Errorf ("addr %x: total pending transactions mismatch: have %d, want %d" , addr , list .Len (), DefaultTxPoolConfig .AccountSlots )
@@ -860,6 +909,10 @@ func TestTransactionPoolRepricing(t *testing.T) {
860
909
// Import the batch and that both pending and queued transactions match up
861
910
pool .AddBatch (txs )
862
911
912
+ if err := pool .validateInternals (); err != nil {
913
+ t .Error (err )
914
+ }
915
+
863
916
pending , queued := pool .stats ()
864
917
if pending != 4 {
865
918
t .Fatalf ("pending transactions mismatched: have %d, want %d" , pending , 4 )
@@ -894,6 +947,10 @@ func TestTransactionPoolRepricing(t *testing.T) {
894
947
if pending , _ = pool .stats (); pending != 3 {
895
948
t .Fatalf ("pending transactions mismatched: have %d, want %d" , pending , 3 )
896
949
}
950
+ if err := pool .validateInternals (); err != nil {
951
+ t .Error (err )
952
+ }
953
+
897
954
}
898
955
899
956
// Tests that when the pool reaches its global transaction limit, underpriced
@@ -937,6 +994,9 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
937
994
938
995
// Import the batch and that both pending and queued transactions match up
939
996
pool .AddBatch (txs )
997
+ if err := pool .validateInternals (); err != nil {
998
+ t .Error (err )
999
+ }
940
1000
941
1001
pending , queued := pool .stats ()
942
1002
if pending != 3 {
@@ -980,6 +1040,9 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
980
1040
if queued != 2 {
981
1041
t .Fatalf ("queued transactions mismatched: have %d, want %d" , queued , 2 )
982
1042
}
1043
+ if err := pool .validateInternals (); err != nil {
1044
+ t .Error (err )
1045
+ }
983
1046
}
984
1047
985
1048
// Tests that the pool rejects replacement transactions that don't meet the minimum
@@ -1041,6 +1104,9 @@ func TestTransactionReplacement(t *testing.T) {
1041
1104
if err := pool .Add (pricedTransaction (2 , big .NewInt (100000 ), big .NewInt (threshold + 1 ), key )); err != nil {
1042
1105
t .Fatalf ("failed to replace original queued transaction: %v" , err )
1043
1106
}
1107
+ if err := pool .validateInternals (); err != nil {
1108
+ t .Error (err )
1109
+ }
1044
1110
}
1045
1111
1046
1112
// Benchmarks the speed of validating the contents of the pending queue of the
0 commit comments