# Buggy code
def __init__(self, storage):
    self.electrum_version = ELECTRUM_VERSION
    self.storage = storage
    self.network = None
    # verifier (SPV) and synchronizer are started in start_threads
    self.synchronizer = None
    self.verifier = None

    self.gap_limit_for_change = 6  # constant

    # locks: if you need to take multiple ones, acquire them in the order they are defined here!
    self.lock = threading.RLock()
    self.transaction_lock = threading.RLock()

    # saved fields
    self.use_change = storage.get("use_change", True)
    self.multiple_change = storage.get("multiple_change", False)
    self.labels = storage.get("labels", {})
    self.frozen_addresses = set(storage.get("frozen_addresses", []))
    self.history = storage.get("addr_history", {})  # address -> list(txid, height)
    self.fiat_value = storage.get("fiat_value", {})
    self.receive_requests = storage.get("payment_requests", {})

    # Verified transactions.  Each value is a (height, timestamp, block_pos) tuple.  Access with self.lock.
    self.verified_tx = storage.get("verified_tx3", {})

    # Transactions pending verification.  A map from tx hash to transaction
    # height.  Access is not contended so no lock is needed.
    self.unverified_tx = defaultdict(int)

    self.load_keystore()
    self.load_addresses()
    self.test_addresses_sanity()
    self.load_transactions()
    self.check_history()
    self.load_unverified_transactions()
    self.load_local_history()
    self.build_spent_outpoints()

    # there is a difference between wallet.up_to_date and interface.is_up_to_date()
    # interface.is_up_to_date() returns true when all requests have been answered and processed
    # wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
    self.up_to_date = False

    # save wallet type the first time
    if self.storage.get("wallet_type") is None:
        self.storage.put("wallet_type", self.wallet_type)

    # invoices and contacts
    self.invoices = InvoiceStore(self.storage)
    self.contacts = Contacts(self.storage)

    self.coin_price_cache = {}


# Traceback (AssertionError)
user@debian:~/wspace/electrum$ python3.6 ./electrum -v --testnet --oneserver
[SimpleConfig] electrum directory /home/user/.electrum/testnet
[get_server] [Errno 111] Connection refused
[Plugins] registering hardware digitalbitbox: ('hardware', 'digitalbitbox', 'Digital Bitbox wallet')
[Plugins] registering hardware keepkey: ('hardware', 'keepkey', 'KeepKey wallet')
[Plugins] registering hardware ledger: ('hardware', 'ledger', 'Ledger wallet')
[Plugins] registering hardware trezor: ('hardware', 'trezor', 'TREZOR wallet')
[Plugins] registering wallet type ('2fa', 'trustedcoin')
[profiler] __init__ 0.0027
cannot connect fork_0_1249088
cannot connect fork_0_1202455
cannot connect fork_0_1227602
cannot connect fork_0_1210726
cannot connect fork_0_1231244
cannot connect fork_0_1251380
cannot connect fork_0_1230884
cannot connect fork_0_1202487
cannot connect fork_0_1253281
cannot connect fork_0_1230299
cannot connect fork_0_1210502
cannot connect fork_0_1251316
cannot connect fork_0_1210720
cannot connect fork_0_1230929
cannot connect fork_0_1210707
cannot connect fork_0_1210467
cannot connect fork_0_1251387
cannot connect fork_0_1196375
cannot connect fork_0_1251366
cannot connect fork_0_1253410
cannot connect fork_0_1251305
cannot connect fork_0_1231249
cannot connect fork_0_1251344
cannot connect fork_0_1230934
[Network] blockchains dict_keys([0, 1258867, 1270262, 1266048, 1266400, 1255522, 1266183, 1270223, 1276034, 1266197, 1280568, 1264485, 1266081, 1288369, 1257139, 1265590, 1266410, 1260858, 1269147, 1255571, 1256086, 1261183, 1256802, 1255209, 1288889, 1264428, 1264371, 1275773, 1276991, 1266386, 1255503, 1261935, 1287426, 1276989, 1255581, 1266347, 1257189, 1264518, 1287446, 1254742, 1280612, 1275799, 1264342, 1288937, 1265989, 1270208, 1255758, 1266200, 1261961, 1255271, 1276073, 1265981, 1266065, 1270175, 1266492, 1266354, 1266448, 1266013, 1255612, 1266487, 1266397, 1288918, 1276070, 1278114, 1276091, 1287511, 1276431, 1288300, 1275844, 1266433, 1266336, 1257065, 1266460, 1254304, 1266389, 1287232, 1275787, 1276914, 1260839, 1260899, 1257193, 1264490, 1256811, 1254839, 1266059, 1257069, 1254119, 1266438, 1257223, 1275964, 1260847, 1265566, 1258872, 1265952, 1255396, 1261958, 1265661, 1275738, 1275667, 1276039, 1287143, 1275840, 1266566, 1261943, 1256240, 1255099, 1258805, 1262097, 1264470, 1270237, 1265641, 1266420, 1266351, 1254225, 1266078, 1256824, 1266366, 1265994, 1264528, 1257173, 1266191, 1266026, 1265616, 1254988, 1266091, 1257501, 1266174, 1275833, 1266098, 1275692, 1254282, 1266195, 1270219, 1287836, 1266343, 1266074, 1255055, 1254272, 1288324, 1257866, 1275846, 1266038, 1257154, 1261140, 1255132, 1254607, 1266025, 1254130, 1264473, 1255769, 1260836, 1266061, 1288368, 1266199, 1275838, 1265971, 1261940, 1275857, 1291573, 1266370, 1264515, 1268856, 1265613, 1280938, 1266456, 1257220, 1266333, 1265578, 1280522, 1276123, 1257442, 1256037, 1254871, 1254863, 1260861, 1264525, 1265987, 1275871, 1266011, 1261850, 1266406, 1265917, 1261979, 1266178, 1265969, 1255525, 1260883, 1257216, 1255385, 1266478, 1260867, 1270195, 1275730, 1266441, 1255597, 1256837, 1275788, 1277996, 1257182, 1261156, 1262007, 1264467, 1264458, 1255244, 1266318, 1266497, 1266042, 1254238, 1262076, 1270194, 1254731, 1261952, 1255722, 1266151, 1256746, 1256820, 1255375, 1255776, 1266180, 1264482, 1270185, 1266402, 1255405, 1264475, 1266161, 1275912, 1265667, 1283995, 1280273, 1256844, 1255094, 1266563, 1261949, 1276967, 1265617, 1265592, 1264499, 1256818, 1281628, 1258646, 1254796, 1264394, 1254970, 1275975, 1276025, 1266463, 1264348, 1266169, 1257491, 1265648, 1264317, 1264392, 1254358, 1266204, 1257167, 1261970, 1254425, 1258874, 1254950, 1255252, 1280271, 1261855, 1275800, 1261187, 1276096, 1264361, 1255563, 1256063, 1265576, 1266173, 1266068, 1278105, 1275955, 1254277, 1265979, 1275777, 1257201, 1265609, 1258601, 1256126, 1265556])
[Network] starting network
[Network] connecting to testnet.qtornado.com:51002:s as new interface
[FxThread] using exchange BitcoinAverage
[BitcoinAverage] getting fx quotes for USD
[WalletStorage] wallet path /home/user/.electrum/testnet/wallets/test_segwit_asdasd
[profiler] load_transactions 0.0046
[profiler] build_spent_outpoints 0.0001
[profiler] check_history 0.0005
[Synchronizer] missing tx {'36dc056916b9f7b31045387e9ef85dc35cc598f66b15475b98cb7545b5ccbe99': 0}
[profiler] get_full_history 0.0223
[profiler] on_update 0.0535
[testnet.qtornado.com] connected
[Network] switching to testnet.qtornado.com:51002:s
[Network] sending subscriptions to testnet.qtornado.com:51002:s 0 0
[testnet.qtornado.com] --> ('blockchain.headers.subscribe', [], 0)
[testnet.qtornado.com] --> ('server.version', ['3.1.2', '1.2'], 1)
[testnet.qtornado.com] --> ('server.banner', [], 2)
[testnet.qtornado.com] --> ('server.donation_address', [], 3)
[testnet.qtornado.com] --> ('server.peers.subscribe', [], 4)
[testnet.qtornado.com] --> ('mempool.get_fee_histogram', [], 5)
[testnet.qtornado.com] --> ('blockchain.estimatefee', [25], 6)
[testnet.qtornado.com] --> ('blockchain.estimatefee', [10], 7)
[testnet.qtornado.com] --> ('blockchain.estimatefee', [5], 8)
[testnet.qtornado.com] --> ('blockchain.estimatefee', [2], 9)
[testnet.qtornado.com] --> ('blockchain.relayfee', [], 10)
[testnet.qtornado.com] --> ('blockchain.transaction.get', ['36dc056916b9f7b31045387e9ef85dc35cc598f66b15475b98cb7545b5ccbe99'], 11)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3d7f776e77095bc267f085f77d82d72b6127916baecb1d4dc7199c34d0bf6e3e'], 12)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['6ec9bac1b6a7449896e89d6009a8622f783cd187e0dbb3d79027fc1e43568327'], 13)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['01c62caa5ea73e4bc85784d150fadb01928b026a9e8db01b3066b0df0c1b7e48'], 14)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['ac46cad1860ba1062888394e2a810ae8626390c604bb07d0891860e57a18c7b4'], 15)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['a14232e576c3302fdf780b82ce80e52c744b439b7e75f7114e0ded5c71828c85'], 16)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['d474dbc60d3e729e431789b048136fd506590648b85f064cb7be81f8c08a6cb2'], 17)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3c9a013a1a2ba21556ed4e923b4804ff62f0d1b0be887e1bd52c7d6c2c52d716'], 18)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b2e371266659ddad6132557c51ad13b46edddbf77ff8903379901a9f4480d9b0'], 19)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['2826da383df2fdef0afcadf3d2a57028c391df8cc25bf4a51876c2b36e635eac'], 20)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['2c59e48192e894b808d00163e497363276203d99c559f5a5c135b9bcd9b1c274'], 21)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['814538d8b0dc4560aab9b780dbf3f87cf19358e0799f72af8764ca83b9f49b55'], 22)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3714761e92ea2ac111d17d47457d9217c9414286dcac20783b1e3d30f13026f7'], 23)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['472b09ed58e26925f617182897a31e1c19ba0041fd58906051718cbca6816586'], 24)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['642e2194f1c0acb1c62b6ad09a09a64dad9b348283d2bb065c851c0a8974fc44'], 25)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['fd3d8ca4fa363784822f36dd97f94b104bf88b75cdf9bac0b377675ba880399d'], 26)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['4e55e6b4198323d6e28ffcefbbcd9ec808bb5106dedbf4e13ee5c30f4ffd5ac9'], 27)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b65f62b3efda27cb2c79038c91fd2c1c2069d402f7850966bbe1d821e505f84a'], 28)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['ccc4d253b668d9c615784ade31d1f2dad0dcf2b43e20aa88a8a0ad488cf9b154'], 29)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['512c44a10dfcb6c57d758d71e14ce94df143f5cc026f907605c1cd02a93fecaf'], 30)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['9ad1d5e69a5dd3e9de92b26eb548fd9586e0480f187501b6240e6301c4b459a9'], 31)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['6c1aa6dcc02d34faedb668407c1988ff2767be1d958d8530464659af23fa49fa'], 32)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['704bb81524d3debbc7494b15bb756235e1fb5aee3aab915bbbf7b9f292d60d1e'], 33)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1a2017fce4f2f130dc584476d41c97269c91a7eac08db6c5d8a949f27da57253'], 34)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3fdbb97e1be6e4f28b714ac4375b3bcd642302b23be19a49543e01cb019dc303'], 35)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1ed3c97d567fcc87c694a021037a28a079d0d777db58305bb34a626ec786efab'], 36)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['f6859323205f123f85eeacabf05a7afc2b016d3859727fe16bf091ceb1778192'], 37)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['f3923d1b1d3746107eb54e753aa6296022ba630d616255ab5fbe452f818f3fa7'], 38)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['ab7882359f690811ded59007bb07aa09b4ffc63a41bcd21fff0a82b1a833945d'], 39)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['feeb1d7683c452375f85c63ddaf6efc97172ff9ba19fc53bf2549feab98ed818'], 40)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['727235af886ea9abb9477bc407da1d46c0bef8cd907f442acef0ec03372c8f8c'], 41)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['68be916ffb14fc7f32bf9c84929fd234292d8412dd63a4119a2323001b841b25'], 42)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['ae4f9aae1b39d699e3f1793240e84b23946cfd7a6039b507c954b24acec06f08'], 43)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['84238e6b869553aeb525b4f891a14adab02c235b8ad82736c1b0240fa9db1265'], 44)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['05e420086ec0d01d13165cbbe22d1d3b9e2054d53bdee6384ab9a28702ca4fc7'], 45)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['8092d3b81b1eda50aa3f5ae2e4c9b5535879003213bb0e20c8e12243bb88506a'], 46)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['7a35bf176a7cd5917f36c1e11d73f855480e3b3fe9bda94f8bea796b79a97c48'], 47)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['508609ea1b2ba36264c1dd26c50cbc823f5097ea4317a4e69e4b357e4ec0aef9'], 48)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['7f061b64abbb3fd241d4c00e4547ea4a64fdf3e1c5224775900a438ad3c9ee13'], 49)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['f61de766a39f43636b2ebb22e3ab1e16231fd2a69094f185bc2f4b944bffe804'], 50)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['bf2b8d167fa1fdb1541d18de9fda5f471902e16415d46da86d54d6babdb8a29b'], 51)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['72121d7ab56105c337747974ffd3b5c99d926b5e3c36b76be81a166aae902d94'], 52)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['202420f68d09a1caa60685b67fb0911081eb85f82996fb57f1eeba2f58160558'], 53)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['4cbada5f2af0adbf13b0cd2a643fad0bc83dc692b438bb682d48b4cb67ec21e9'], 54)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['61a625955f98fd9db1a3480da15738217caa5c1d8acc70b7782d07b49bb9458b'], 55)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['6319df994838bc221182f746b6514fada4137b206d9e0991378b6dbc69b122a3'], 56)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['176836e405dbdf078aecf0141dc207b665052550e0b60d56cd53f5fd75663e4d'], 57)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['ab1e6b5f6364933f2f6f889b530406c472877e7d50a7b719d78055fe11d9d831'], 58)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['67e373f6af32692b4238bc38c06c84035e4fe4ae3243a8eb00bda4b30fc28345'], 59)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['a15db3260478002283bc886992546eacc35238c1c3da3e4aff91b181a48c6e98'], 60)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['0d65ebe46b08571f2fbdaf08cf45ce3b4851cee63e9f577bcb208323abae60cb'], 61)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['58d52350becf73726c20d0ae9ce2dbd9638ed4ae49c1d018026a86ffc52ca4c2'], 62)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['d42679de97b95ccf2d0d1b9b28298dc134a5de7d9cb9fba1e207ae674e6531c0'], 63)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1a250bb8deea9cbba706480c093db6003cca8a40bfb34fd46feeeb4d6ec0d660'], 64)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b8e825a9f63b4b9863b120175bdf5ba02edeb792e4b9e86203eed5998f53d04d'], 65)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['653a5f417ba8a5082d9a97e553af18496ce6dd28eaff09df63f58f23e0c5ab88'], 66)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1dd25d6fc3e02ce6640c9c5955028d26b4ed8105fdb8b41bfba4fd28f3c7ae57'], 67)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['5bab7aaa46e010038bd15ea448ff07b443df4a8c8a55870d38073427c8a71ce9'], 68)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['c39522aa1e0a65d321d70b8dc6435f105ee3363e60c5175e2a290efd14d1ca83'], 69)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['230bda35b500b1017a6d44a06e868f32221175081db0c5d993062b97d0ba4702'], 70)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3eac5caf6da57b0c864f88a5a8839441dde6ba3bc6642c654bd48584318164cc'], 71)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['875a55cb7875ebf433e17859dcf16afef9fb247b785ff217e697ac223b5b1e7c'], 72)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['15f93c1bcb8f992868baa1b9cc2ba72bf130c4e576b60fbc576a053a611089b3'], 73)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['dfeaedf2c073a7877d69f3585b96474cd65b8bcabe115f51807bd4bb9f4733a2'], 74)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['3ba0bbcd0fb27e1088aff8195b5899684710f52d827c72274cf4c7018c7deb24'], 75)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['691dcb1f71833e77abcdb0f40f03b6f590bda8f73ae781f8fbcf6440b17777b4'], 76)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['d63cd2622a81facac7990c2d2a277941fcb2b6bc36d84ce3a175d78ab6d91346'], 77)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['0379ac4daacbdcf0faf824ade83f5fddfa1dddc5d3f96c4d3d31fb1404dde435'], 78)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['e62cc405cdf3d2a4ad8042ede8b778039ae227294f865e5155131382ee27fb54'], 79)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['9277840ec8f5144a5c3cee14377f90a11c2cc69bd66e2b046adc0a2cdc5c8d63'], 80)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['75e60c8f2107d76c197d007e145f279ff9d0ed5db2e447b1fa93360380104087'], 81)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['588193eaeb004169b175b8a0b0a956dcdaa9d330e23ac13ecbc3eb391159e0de'], 82)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1663e7deeda2a9dd19496ac269185000db7002244e5c0ef61572cee815665b65'], 83)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['bc53f93e92a0434041992179fb575863093e4ed8692e3e6a38015b420a3553c8'], 84)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['fb4c39e6f7586fc53826b742fe4a7660448988f9828e31aa5d6b1b375ac82b8b'], 85)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['c2bfcfc001279c1893f616e94fdec68213062fbf65cc1926602507825347346f'], 86)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['7006b2d57d60bbaab22a7303c3bec9cf0aea801b9f905228e9103052a733c6c9'], 87)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['a2a6682cbefcdf0292953ab3fae891ebf5c064a264735e87b4502c77f81a2d9b'], 88)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['f91ab900f7881a0956adfe19b6331e09c2751f9e83fe8f36ad08a79269110bdf'], 89)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b9fc839fa3a8866fa5e652b3a0fe4899e8030e46f4a9d3e2b5e996ea2a96d27d'], 90)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['5ba15cc21f756dc23a98a9ae1a9f317772262ce233a5a6c375a05268842da0ca'], 91)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['7f09535bc267563bd7042c086d6b3fd6a7280bea48dea05c0cbfe012bb6e1b9f'], 92)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['08ba7f902cc8e9b4a42a72877d6b3bf113853c55410b117d139da11f1bd235b9'], 93)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['60818c7df5e359e6af740a60eb7d97bb4cc990294949034d158074569d6254a9'], 94)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['bf5c9c3137a70bda83c33c418df80cf60da78cb88d5a859560684eb8304f0bc9'], 95)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['a57e4f31a6db3d9d9abf18e83518aab2f3fa8bdd201707266d74be51eb526ed0'], 96)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['330f3eee2b1fd277d1b1899512247d2d43191d539b0b269130d9b72c658d6916'], 97)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['0844b2836acd62251a32838ce1fb6a67a5fe49a76cb89abcec4014a9b5cd2e37'], 98)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['7d10d9b4cd68584489ac05ac5d6bd81ee083cbf9490e48b26aca2aeb73cf20ef'], 99)
[ElectrumWindow/test_segwit_asdasd] Notifying GUI
[profiler] load_wallet 0.1972
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 0, 'result': {'block_height': 1291699, 'version': 536870912, 'prev_block_hash': '00000000000000b15770979e8a5e3dd4383757dc2da0705d4cca823dcc6ddc9a', 'merkle_root': 'f52881543b92be0cbb10718b93d91abb8596d2f8e6d5612faa78ed57c29bd4b3', 'timestamp': 1523006702, 'bits': 486604799, 'nonce': 1021007632}}
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['6be2a33324abe9048cc52b1cf6c580b1d6653c2b4833b9b34e0b67f83b5739f4'], 100)
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 1, 'result': ['ElectrumX 1.3', '1.2']}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 2, 'result': 'Welcome to testnet.qtornado.com!\r\n\r\nBitcoin Core 0.16.0\r\n/Satoshi:0.16.0/\r\nElectrumX 1.3\r\n\r\nContact: qtornado@protonmail.com (PGP: 59FDAC19FBC4E692652F3EB0C7B7552BDF21283B)\r\n\r\nIf you would like to support this server,\r\nmainnet bitcoin donations are welcome on:\r\nbc1qnkeffmuh6yfrtr7geqrgnq7q4xk3zfk0z3acjg453t9g02fxnedsuaeljq\r\n\r\nAlways use the latest version of Electrum at https://electrum.org/#download\r\n'}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 3, 'result': ''}
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['5707cdf6dbbd316267406d67f4fccbb1b6a376681388d9a9a22765184dde1d88'], 101)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1455d919cf211a94aac9710e0ac4401ce5b9a4e0b3ed6806c61f69b67f965703'], 102)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['92503a9de5b4f36328e507fb08bdb4c9739330f9e0e1b2543f730a6472b0060c'], 103)
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 4, 'result': [['176.24.203.196', 'testnetnode.arihanc.com', ['v1.2', 's51002', 't51001']], ['144.76.2.138', 'electrumx.kekku.li', ['v1.2', 's51002']], ['81.2.249.49', 'testnet1.bauerj.eu', ['v1.2', 's50002', 't50001']], ['76.174.26.91', 'testnet.hsmiths.com', ['v1.2', 's53012', 't53011']], ['198.100.147.192', 'electrum.akinbo.org', ['v1.2', 's51002', 't51001']], ['88.99.162.199', 'testnet.qtornado.com', ['v1.2', 's51002', 't51001']]]}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 5, 'result': []}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 6, 'result': 1e-05}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 7, 'result': 1e-05}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 8, 'result': 0.00863497}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 9, 'result': 0.00863497}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 10, 'result': 1e-05}
[Network] fee_histogram []
[Network] fee_estimates[25] 1000
[Network] fee_estimates[10] 1000
[Network] fee_estimates[5] 863497
[Network] fee_estimates[2] 863497
[Network] relayfee 1000
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['1a5208e912732cd01cc08df708fcb30296c7f95719ca3f8d3faa97b43e6ccf00'], 104)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['88b48ce4cb19678fdd60f36e8d092381024900526b4a923ac900c198166b8458'], 105)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b0312db83e0430665c6858f4ef940e3b86b6289dbf80d31f79efd1def36c2136'], 106)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['cd3ccd42bc7368e8b51e60a2102c04c55d30c9564a801a0542fdb71a330bc8a2'], 107)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['4b348a906b4fc9b4c822c3cb78808e028ec5baa279d4f178cc22caa743112575'], 108)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['f9ec120ab19df3e960f4858686dbefdf5aed8ea3fbb61f142a0881424448a0ed'], 109)
[testnet.qtornado.com] --> ('blockchain.scripthash.subscribe', ['b58d6fedbbe87161e5a7155258f51c4556ea96750cbfaed2752442c271171f7f'], 110)
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 11, 'result': '01000000000101ec96bc433352ff81f3480e36ed1eaf432990988ee99d50d368f74ca1d8b9ec5f0000000000fdffffff02809698000000000017a914758edb22d1f5b686feb08d3d3261b3e6407c884887d72b3101000000001600149bc8e9b3473cd72256adf93c078bc262961a80fa02483045022100f8051f3535d04116cb1bf9728a5643c11ec00e39de66dd429900920d12d4dc180220086e94ad0a1528b3ab47c49f373d1a7e7b1e77adca520fbc32ca253c512560b9012102e54eb21ef6d2a98ce834e66035dcd16ef3b4a3c182344a0de5b73047b4381109b2b51300'}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 12, 'result': '2e807673fe1a9678857ca4da036085f9581f1ff1063ddaef84826917d6f80df5'}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 13, 'result': 'abd53b0fbdf7ecca678b96f10ec7f68755494b9009dc8968eb68d8e33980b7fe'}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 14, 'result': '9c45721288c8a39bb8d99071aa3ee7492752b5bec034aad0ee51500d8e558526'}
[testnet.qtornado.com] <-- {'jsonrpc': '2.0', 'id': 15, 'result': '59b19defd94acb7fc04f9310af9164858a2167c792799ae50602bbd4235fa008'}
wallet.add_transaction() entered for 36dc056916b9f7b31045387e9ef85dc35cc598f66b15475b98cb7545b5ccbe99
tx conflicts with ccc3f803e55c2e5e6f0fdd01720561bb1af9b09c2dc66fec4068d714c05ef270
[BitcoinAverage] received fx quotes
Traceback (most recent call last):
File "/home/user/wspace/electrum/lib/util.py", line 794, in run_with_except_hook
run_original(*args2, **kwargs2)
File "/home/user/wspace/electrum/lib/network.py", line 984, in run
self.wait_on_sockets()
File "/home/user/wspace/electrum/lib/network.py", line 966, in wait_on_sockets
self.process_responses(interface)
File "/home/user/wspace/electrum/lib/network.py", line 625, in process_responses
self.process_response(interface, response, callbacks)
File "/home/user/wspace/electrum/lib/network.py", line 574, in process_response
callback(response)
File "/home/user/wspace/electrum/lib/synchronizer.py", line 153, in tx_response
self.wallet.receive_tx_callback(tx_hash, tx, tx_height)
File "/home/user/wspace/electrum/lib/wallet.py", line 951, in receive_tx_callback
self.add_transaction(tx_hash, tx)
File "/home/user/wspace/electrum/lib/wallet.py", line 845, in add_transaction
conflicting_txns = self.get_conflicting_transactions(tx)
File "/home/user/wspace/electrum/lib/wallet.py", line 805, in get_conflicting_transactions
assert spending_tx_hash in self.transactions
AssertionError
[ElectrumWindow/test_segwit_asdasd] close_wallet /home/user/.electrum/testnet/wallets/test_segwit_asdasd
[Plugins] stopped
[profiler] save_transactions 0.0023
[WalletStorage] saved /home/user/.electrum/testnet/wallets/test_segwit_asdasd
[profiler] write 0.0418
[Daemon] shutting down network
[Daemon] stopped

# Fixed code
def __init__(self, storage):
    self.electrum_version = ELECTRUM_VERSION
    self.storage = storage
    self.network = None
    # verifier (SPV) and synchronizer are started in start_threads
    self.synchronizer = None
    self.verifier = None

    self.gap_limit_for_change = 6  # constant

    # locks: if you need to take multiple ones, acquire them in the order they are defined here!
    self.lock = threading.RLock()
    self.transaction_lock = threading.RLock()

    # saved fields
    self.use_change = storage.get("use_change", True)
    self.multiple_change = storage.get("multiple_change", False)
    self.labels = storage.get("labels", {})
    self.frozen_addresses = set(storage.get("frozen_addresses", []))
    self.history = storage.get("addr_history", {})  # address -> list(txid, height)
    self.fiat_value = storage.get("fiat_value", {})
    self.receive_requests = storage.get("payment_requests", {})

    # Verified transactions.  Each value is a (height, timestamp, block_pos) tuple.  Access with self.lock.
    self.verified_tx = storage.get("verified_tx3", {})

    # Transactions pending verification.  A map from tx hash to transaction
    # height.  Access is not contended so no lock is needed.
    self.unverified_tx = defaultdict(int)

    self.load_keystore()
    self.load_addresses()
    self.test_addresses_sanity()
    self.load_transactions()
    self.check_history()
    self.load_unverified_transactions()
    self.load_local_history()
    self.build_spent_outpoints()
    self.remove_local_transactions_we_dont_have()

    # there is a difference between wallet.up_to_date and interface.is_up_to_date()
    # interface.is_up_to_date() returns true when all requests have been answered and processed
    # wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
    self.up_to_date = False

    # save wallet type the first time
    if self.storage.get("wallet_type") is None:
        self.storage.put("wallet_type", self.wallet_type)

    # invoices and contacts
    self.invoices = InvoiceStore(self.storage)
    self.contacts = Contacts(self.storage)

    self.coin_price_cache = {}