@@ -166,9 +166,15 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
166166 // Create a new state based on the parent's root (e.g., create copy)
167167 state := state .New (parent .Root (), sm .db )
168168
169+ // track (possible) uncle block
170+ var uncle bool
169171 // Block validation
170172 if err = sm .ValidateHeader (block .Header (), parent .Header ()); err != nil {
171- return
173+ if err != BlockEqualTSErr {
174+ return
175+ }
176+ err = nil
177+ uncle = true
172178 }
173179
174180 // There can be at most two uncles
@@ -223,14 +229,22 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
223229 td = CalculateTD (block , parent )
224230 // Sync the current block's state to the database
225231 state .Sync ()
226- // Remove transactions from the pool
227- sm .txpool .RemoveSet (block .Transactions ())
232+
233+ if ! uncle {
234+ // Remove transactions from the pool
235+ sm .txpool .RemoveSet (block .Transactions ())
236+ }
228237
229238 for _ , tx := range block .Transactions () {
230239 putTx (sm .extraDb , tx )
231240 }
232241
233- chainlogger .Infof ("processed block #%d (%x...)\n " , header .Number , block .Hash ().Bytes ()[0 :4 ])
242+ if uncle {
243+ chainlogger .Infof ("found possible uncle block #%d (%x...)\n " , header .Number , block .Hash ().Bytes ()[0 :4 ])
244+ return td , nil , BlockEqualTSErr
245+ } else {
246+ chainlogger .Infof ("processed block #%d (%x...)\n " , header .Number , block .Hash ().Bytes ()[0 :4 ])
247+ }
234248
235249 return td , state .Logs (), nil
236250}
@@ -255,10 +269,6 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
255269 return fmt .Errorf ("GasLimit check failed for block %v (%v > %v)" , block .GasLimit , a , b )
256270 }
257271
258- if block .Time <= parent .Time {
259- return ValidationError ("Block timestamp equal or less than previous block (%v - %v)" , block .Time , parent .Time )
260- }
261-
262272 if int64 (block .Time ) > time .Now ().Unix () {
263273 return BlockFutureErr
264274 }
@@ -272,6 +282,10 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
272282 return ValidationError ("Block's nonce is invalid (= %x)" , block .Nonce )
273283 }
274284
285+ if block .Time <= parent .Time {
286+ return BlockEqualTSErr //ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time)
287+ }
288+
275289 return nil
276290}
277291
@@ -307,14 +321,10 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
307321 return UncleError (fmt .Sprintf ("Uncle's parent unknown (%x)" , uncle .ParentHash [0 :4 ]))
308322 }
309323
310- if err := sm .ValidateHeader (uncle , ancestorHeaders [uncle .ParentHash ]); err != nil {
324+ if err := sm .ValidateHeader (uncle , ancestorHeaders [uncle .ParentHash ]); err != nil && err != BlockEqualTSErr {
311325 return ValidationError (fmt .Sprintf ("%v" , err ))
312326 }
313327
314- if ! sm .Pow .Verify (types .NewBlockWithHeader (uncle )) {
315- return ValidationError ("Uncle's nonce is invalid (= %x)" , uncle .Nonce )
316- }
317-
318328 r := new (big.Int )
319329 r .Mul (BlockReward , big .NewInt (15 )).Div (r , big .NewInt (16 ))
320330
0 commit comments