@@ -732,7 +732,7 @@ func testRPCDynamicTxGasPriceWithoutState(t *testing.T, afterGingerbread, altern
732732 gasTipCap := big .NewInt (0 ).Mul (suggestedGasPrice , big .NewInt (2 ))
733733
734734 // Send one celo from external account 0 to 1 via node 0.
735- tx , err := accounts [0 ].SendValueWithDynamicFee (ctx , accounts [1 ].Address , 1 , feeCurrency , gasFeeCap , gasTipCap , network [0 ])
735+ tx , err := accounts [0 ].SendValueWithDynamicFee (ctx , accounts [1 ].Address , 1 , feeCurrency , gasFeeCap , gasTipCap , network [0 ], 0 )
736736 require .NoError (t , err )
737737
738738 // Wait for the whole network to process the transaction.
@@ -1044,3 +1044,66 @@ func TestGetFinalizedBlock(t *testing.T) {
10441044 // Check latest and finalzed block are the same
10451045 require .Equal (t , h .Hash (), h2 .Hash ())
10461046}
1047+
1048+ // TestManyFeeCurrencyTransactions is intended to test that we don't have race conditions in the tx pool when handling
1049+ // fee currency transactions. It does this by submitting many fee currency transactions from 3 different goroutines over
1050+ // a period of roughly 5 seconds which with the configured block time of 1 second means that the transactions should
1051+ // span multiple block boundaries with the goal of ensuring that both runReorg and AddRemotes are being called
1052+ // concurrently in the txPool. This issue https://github.com/celo-org/celo-blockchain/issues/2318 is occurring somewhat
1053+ // randomly and could be the result of some race condition in tx pool handling for fee currency transactions. However
1054+ // this test seems to run fairly reliably with the race flag enabled, which seems to indicate that the problem is not a
1055+ // result of racy behavior in the tx pool.
1056+ func TestManyFeeCurrencyTransactions (t * testing.T ) {
1057+ ac := test .AccountConfig (3 , 3 )
1058+ gingerbreadBlock := common .Big0
1059+ gc , ec , err := test .BuildConfig (ac , gingerbreadBlock , nil )
1060+ require .NoError (t , err )
1061+ ec .Istanbul .BlockPeriod = 1
1062+ network , shutdown , err := test .NewNetwork (ac , gc , ec )
1063+ require .NoError (t , err )
1064+ defer shutdown ()
1065+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 200 )
1066+ defer cancel ()
1067+
1068+ cUSD := common .HexToAddress ("0x000000000000000000000000000000000000d008" )
1069+ cEUR := common .HexToAddress ("0x000000000000000000000000000000000000D024" )
1070+ cREAL := common .HexToAddress ("0x000000000000000000000000000000000000d026" )
1071+
1072+ accounts := test .Accounts (ac .DeveloperAccounts (), gc .ChainConfig ())
1073+
1074+ time .Sleep (2 * time .Second )
1075+ txsChan := make (chan []* types.Transaction , 3 )
1076+ for nodeIndex := 0 ; nodeIndex < len (network ); nodeIndex ++ {
1077+ go func (nodeIndex int ) {
1078+ txs := make ([]* types.Transaction , 0 , 3000 )
1079+ for i := 0 ; i < 100 ; i ++ {
1080+ for _ , feeCurrency := range []* common.Address {& cUSD , & cEUR , & cREAL } {
1081+ baseFee , err := network [nodeIndex ].WsClient .SuggestGasPriceInCurrency (ctx , feeCurrency )
1082+ require .NoError (t , err )
1083+ tip , err := network [nodeIndex ].WsClient .SuggestGasTipCapInCurrency (ctx , feeCurrency )
1084+ require .NoError (t , err )
1085+
1086+ // Send one celo from external account 0 to 1 via node 0.
1087+ tx , err := accounts [nodeIndex ].SendValueWithDynamicFee (ctx , accounts [nodeIndex ].Address , 1 , feeCurrency , baseFee .Add (baseFee , tip ), tip , network [nodeIndex ], 71000 )
1088+ require .NoError (t , err )
1089+ txs = append (txs , tx )
1090+ time .Sleep (16 * time .Millisecond )
1091+ }
1092+ }
1093+ txsChan <- txs
1094+ }(nodeIndex )
1095+ }
1096+
1097+ allTxs := make ([]* types.Transaction , 0 , 3000 * len (network ))
1098+ count := 0
1099+ for txs := range txsChan {
1100+ allTxs = append (allTxs , txs ... )
1101+ count ++
1102+ if count == len (network ) {
1103+ break
1104+ }
1105+ }
1106+
1107+ err = network .AwaitTransactions (ctx , allTxs ... )
1108+ require .NoError (t , err )
1109+ }
0 commit comments