# Buggy code
def __init__(self, config=None):
    if config is None:
        config = {}  # Do not use mutables as default values!
    util.DaemonThread.__init__(self)
    self.config = SimpleConfig(config) if isinstance(config, dict) else config
    self.num_server = 10 if not self.config.get("oneserver") else 0
    self.blockchains = blockchain.read_blockchains(self.config)
    self.print_error("blockchains", self.blockchains.keys())
    self.blockchain_index = config.get("blockchain_index", 0)
    if self.blockchain_index not in self.blockchains.keys():
        self.blockchain_index = 0
    self.protocol = "t" if self.config.get("nossl") else "s"
    # Server for addresses and transactions
    self.default_server = self.config.get("server")
    # Sanitize default server
    try:
        host, port, protocol = deserialize_server(self.default_server)
        assert protocol == self.protocol
    except:
        self.default_server = None
    if not self.default_server:
        self.default_server = pick_random_server()
    self.lock = threading.Lock()
    self.pending_sends = []
    self.message_id = 0
    self.debug = False
    self.irc_servers = {}  # returned by interface (list from irc)
    self.recent_servers = self.read_recent_servers()

    self.banner = ""
    self.donation_address = ""
    self.relay_fee = None
    # callbacks passed with subscriptions
    self.subscriptions = defaultdict(list)
    self.sub_cache = {}
    # callbacks set by the GUI
    self.callbacks = defaultdict(list)

    dir_path = os.path.join(self.config.path, "certs")
    if not os.path.exists(dir_path):
        os.mkdir(dir_path)
        os.chmod(dir_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    # subscriptions and requests
    self.subscribed_addresses = set()
    self.h2addr = {}
    # Requests from client we've not seen a response to
    self.unanswered_requests = {}
    # retry times
    self.server_retry_time = time.time()
    self.nodes_retry_time = time.time()
    # kick off the network.  interface is the main server we are currently
    # communicating with.  interfaces is the set of servers we are connecting
    # to or have an ongoing connection with
    self.interface = None
    self.interfaces = {}
    self.auto_connect = self.config.get("auto_connect", True)
    self.connecting = set()
    self.socket_queue = queue.Queue()
    self.start_network(self.protocol, deserialize_proxy(self.config.get("proxy")))


# Traceback (AssertionError)
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/home/user/wspace/electrum/lib/network.py", line 966, in run
self.wait_on_sockets()
File "/home/user/wspace/electrum/lib/network.py", line 948, in wait_on_sockets
self.process_responses(interface)
File "/home/user/wspace/electrum/lib/network.py", line 612, in process_responses
self.process_response(interface, response, callbacks)
File "/home/user/wspace/electrum/lib/network.py", line 558, in process_response
self.on_get_header(interface, response)
File "/home/user/wspace/electrum/lib/network.py", line 807, in on_get_header
chain = blockchain.check_header(header)
File "/home/user/wspace/electrum/lib/blockchain.py", line 85, in check_header
if b.check_header(header):
File "/home/user/wspace/electrum/lib/blockchain.py", line 131, in check_header
return header_hash == self.get_hash(height)
File "/home/user/wspace/electrum/lib/blockchain.py", line 266, in get_hash
assert (height+1) % 2016 == 0
AssertionError

# Fixed code
def __init__(self, config=None):
    if config is None:
        config = {}  # Do not use mutables as default values!
    util.DaemonThread.__init__(self)
    self.config = SimpleConfig(config) if isinstance(config, dict) else config
    self.num_server = 10 if not self.config.get("oneserver") else 0
    self.blockchains = blockchain.read_blockchains(self.config)
    self.print_error("blockchains", self.blockchains.keys())
    self.blockchain_index = config.get("blockchain_index", 0)
    if self.blockchain_index not in self.blockchains.keys():
        self.blockchain_index = 0
    self.protocol = "t" if self.config.get("nossl") else "s"
    # Server for addresses and transactions
    self.default_server = self.config.get("server")
    # Sanitize default server
    try:
        host, port, protocol = deserialize_server(self.default_server)
        assert protocol == self.protocol
    except:
        self.default_server = None
    if not self.default_server:
        self.default_server = pick_random_server()
    self.lock = threading.Lock()
    self.pending_sends = []
    self.message_id = 0
    self.debug = False
    self.irc_servers = {}  # returned by interface (list from irc)
    self.recent_servers = self.read_recent_servers()

    self.banner = ""
    self.donation_address = ""
    self.relay_fee = None
    # callbacks passed with subscriptions
    self.subscriptions = defaultdict(list)
    self.sub_cache = {}
    # callbacks set by the GUI
    self.callbacks = defaultdict(list)

    dir_path = os.path.join(self.config.path, "certs")
    if not os.path.exists(dir_path):
        os.mkdir(dir_path)
        os.chmod(dir_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    # subscriptions and requests
    self.subscribed_addresses = set()
    self.h2addr = {}
    # Requests from client we've not seen a response to
    self.unanswered_requests = {}
    # retry times
    self.server_retry_time = time.time()
    self.nodes_retry_time = time.time()
    # kick off the network.  interface is the main server we are currently
    # communicating with.  interfaces is the set of servers we are connecting
    # to or have an ongoing connection with
    self.interface = None
    self.interfaces = {}
    self.auto_connect = self.config.get("auto_connect", True)
    self.connecting = set()
    self.requested_chunks = set()
    self.socket_queue = queue.Queue()
    self.start_network(self.protocol, deserialize_proxy(self.config.get("proxy")))