@@ -1051,9 +1051,7 @@ func TestReorg(t *testing.T) {
1051
1051
1052
1052
// This test chain imports the mined blocks.
1053
1053
b .genesis .MustCommit (db )
1054
- chain , _ := core .NewBlockChain (db , nil , b .chain .Config (), engine , vm.Config {
1055
- Debug : true ,
1056
- Tracer : vm .NewStructLogger (& vm.LogConfig {EnableMemory : true , EnableReturnData : true })}, nil , nil )
1054
+ chain , _ := core .NewBlockChain (db , nil , b .chain .Config (), engine , vm.Config {}, nil , nil )
1057
1055
defer chain .Stop ()
1058
1056
1059
1057
// Insert local tx
@@ -1093,13 +1091,53 @@ firstReorg:
1093
1091
}
1094
1092
1095
1093
require .Equal (t , oldBlock .NumberU64 (), newBlock .NumberU64 ())
1096
- require .Equal (t , oldBlock .Transactions ()[:1 ], newBlock .Transactions ())
1094
+ // should skip second txn
1095
+ require .Equal (t , oldBlock .Transactions ()[:1 ].Len (), newBlock .Transactions ().Len ())
1096
+ for i := 0 ; i < newBlock .Transactions ().Len (); i ++ {
1097
+ require .Equal (t , oldBlock .Transactions ()[:1 ][i ].Hash (), newBlock .Transactions ()[i ].Hash ())
1098
+ }
1099
+
1100
+ time .Sleep (time .Second * 5 )
1101
+
1102
+ const secondReorgHeight = 15
1103
+ w .asyncChecker .ScheduleError (secondReorgHeight , 0 )
1104
+
1105
+ sub .Unsubscribe ()
1097
1106
1098
- w .asyncChecker .ScheduleError (25 , 1 )
1099
1107
// Insert local tx
1100
- for i := 0 ; i < 40 ; i ++ {
1108
+ for i := 0 ; i < 20 ; i ++ {
1101
1109
b .txPool .AddLocal (b .newRandomTx (true ))
1102
1110
}
1103
- time .Sleep (time .Second * 5 )
1104
1111
1112
+ // resubscribe
1113
+ sub = w .mux .Subscribe (core.NewMinedBlockEvent {})
1114
+ defer sub .Unsubscribe ()
1115
+
1116
+ oldBlock = nil
1117
+ newBlock = nil
1118
+
1119
+ secondReorg:
1120
+ for {
1121
+ select {
1122
+ case ev := <- sub .Chan ():
1123
+ block := ev .Data .(core.NewMinedBlockEvent ).Block
1124
+ if block .NumberU64 () == secondReorgHeight {
1125
+ if oldBlock == nil {
1126
+ oldBlock = block
1127
+ } else {
1128
+ newBlock = block
1129
+ break secondReorg
1130
+ }
1131
+ }
1132
+ case <- time .After (3 * time .Second ): // Worker needs 1s to include new changes.
1133
+ t .Fatalf ("timeout" )
1134
+ }
1135
+ }
1136
+
1137
+ require .Equal (t , oldBlock .NumberU64 (), newBlock .NumberU64 ())
1138
+ // should skip first txn and the next txn will fail nonce check
1139
+ require .Equal (t , 0 , newBlock .Transactions ().Len ())
1140
+ for i := 0 ; i < newBlock .Transactions ().Len (); i ++ {
1141
+ require .Equal (t , oldBlock .Transactions ()[1 :][i ].Hash (), newBlock .Transactions ()[i ].Hash ())
1142
+ }
1105
1143
}
0 commit comments