@@ -191,15 +191,16 @@ def _update_head(self, block, forward_pending_transactions=True):
191
191
processblock .verify (bc , bc .get_parent ())
192
192
self .blockchain .put ('HEAD' , block .hash )
193
193
assert self .blockchain .get ('HEAD' ) == block .hash
194
- #log.debug('New head: %s %d\n' % (utils.encode_hex(block.hash), block.number))
195
194
self .index .update_blocknumbers (self .head )
195
+ assert self .head == block
196
+ log .debug ('set new head' , head = self .head )
196
197
self ._update_head_candidate (forward_pending_transactions )
197
198
if self .new_head_cb and not block .is_genesis ():
198
199
self .new_head_cb (block )
199
200
200
201
def _update_head_candidate (self , forward_pending_transactions = True ):
201
202
"after new head is set"
202
- log .debug ('updating head candidate' )
203
+ log .debug ('updating head candidate' , head = self . head )
203
204
# collect uncles
204
205
blk = self .head # parent of the block we are collecting uncles for
205
206
uncles = set (u .header for u in self .get_brothers (blk ))
@@ -225,12 +226,17 @@ def _update_head_candidate(self, forward_pending_transactions=True):
225
226
# add transactions from previous head candidate
226
227
old_head_candidate = self .head_candidate
227
228
self .head_candidate = head_candidate
228
- if old_head_candidate is not None and forward_pending_transactions :
229
- log .debug ('forwarding pending transactions' )
230
- for tx in old_head_candidate .get_transactions ():
231
- self .add_transaction (tx )
232
- else :
233
- log .debug ('discarding pending transactions' )
229
+ if old_head_candidate is not None :
230
+ tx_hashes = self .head .get_transaction_hashes ()
231
+ pending = [tx for tx in old_head_candidate .get_transactions ()
232
+ if tx .hash not in tx_hashes ]
233
+ if pending :
234
+ if forward_pending_transactions :
235
+ log .debug ('forwarding pending transactions' , num = len (pending ))
236
+ for tx in pending :
237
+ self .add_transaction (tx )
238
+ else :
239
+ log .debug ('discarding pending transactions' , num = len (pending ))
234
240
235
241
def get_uncles (self , block ):
236
242
"""Return the uncles of `block`."""
@@ -306,7 +312,7 @@ def add_block(self, block, forward_pending_transactions=True):
306
312
307
313
# set to head if this makes the longest chain w/ most work for that number
308
314
if block .chain_difficulty () > self .head .chain_difficulty ():
309
- _log .debug ('new head' )
315
+ _log .debug ('new head' , num_tx = block . num_transactions () )
310
316
self ._update_head (block , forward_pending_transactions )
311
317
elif block .number > self .head .number :
312
318
_log .warn ('has higher blk number than head but lower chain_difficulty' ,
0 commit comments