|
@@ -4,6 +4,7 @@ candidate for an even longer chain that it attempts to download and verify.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
import threading
|
|
import threading
|
|
|
|
|
+import logging
|
|
|
from typing import List, Dict, Callable, Optional
|
|
from typing import List, Dict, Callable, Optional
|
|
|
|
|
|
|
|
from .block import GENESIS_BLOCK, GENESIS_BLOCK_HASH
|
|
from .block import GENESIS_BLOCK, GENESIS_BLOCK_HASH
|
|
@@ -72,6 +73,7 @@ class ChainBuilder:
|
|
|
|
|
|
|
|
def _new_primary_block_chain(self, chain: 'Blockchain'):
|
|
def _new_primary_block_chain(self, chain: 'Blockchain'):
|
|
|
""" Does all the housekeeping that needs to be done when a new longest chain is found. """
|
|
""" Does all the housekeeping that needs to be done when a new longest chain is found. """
|
|
|
|
|
+ logging.info("new primary block chain with height %d", len(chain.blocks))
|
|
|
self._assert_thread_safety()
|
|
self._assert_thread_safety()
|
|
|
self.primary_block_chain = chain
|
|
self.primary_block_chain = chain
|
|
|
todelete = set()
|
|
todelete = set()
|
|
@@ -84,6 +86,8 @@ class ChainBuilder:
|
|
|
for handler in self.chain_change_handlers:
|
|
for handler in self.chain_change_handlers:
|
|
|
handler()
|
|
handler()
|
|
|
|
|
|
|
|
|
|
+ self.protocol.broadcast_primary_block(chain.head)
|
|
|
|
|
+
|
|
|
def get_next_unconfirmed_block(self):
|
|
def get_next_unconfirmed_block(self):
|
|
|
"""
|
|
"""
|
|
|
Helper function that tries to complete the unconfirmed chain,
|
|
Helper function that tries to complete the unconfirmed chain,
|
|
@@ -102,6 +106,7 @@ class ChainBuilder:
|
|
|
self.unconfirmed_block_chain = []
|
|
self.unconfirmed_block_chain = []
|
|
|
else:
|
|
else:
|
|
|
self.protocol.send_block_request(unc[-1].prev_block_hash)
|
|
self.protocol.send_block_request(unc[-1].prev_block_hash)
|
|
|
|
|
+ logging.debug("asking for another block %d", len(unc))
|
|
|
|
|
|
|
|
def new_block_received(self, block: 'Block'):
|
|
def new_block_received(self, block: 'Block'):
|
|
|
""" Event handler that is called by the network layer when a block is received. """
|
|
""" Event handler that is called by the network layer when a block is received. """
|