I'll quote this post from an other thread cause is describing the best the problem. I've updated electrum from git to 2.8.3 and restoring it from seed didn't help either. It restored only the spent coins and the balance isn't the correct one.
Well, frankly I don't really know how to go through all the steps @crazylol posted bellow.
Hi All!
We have a strange problem with electrum-wallet.
Facts: We have 10 electrum-daemons 2.7.18, which run under different users on one server. JSON-requests to this daemons are balanced by nginx. All works fine about the month (without restart), but recently we wanted to update our wallets to 2.8.2. After command
electrum daemon stop balance of 5 wallets out of 10 became 0. Then, i started electrum daemons again, and in 5 of 10 wallets balance became much less than should be.
Ok, I tried to restore this wallets from seed, but, unfortunately, balance was like after reboot.
Investigation: Fortunally, all addresses, which were used for payment requests were stored in 2 places - in wallet_file and on the filesystem. Grep on payment requests showed more than 700 addresses, which were used for this requests, but
electrum listaddresses showed me less than 300 addresses.
Next, I took one random address from 700 and said
electrum ismine _thisaddress_, result was false. I manually added this address in wallet_file in tag "addresses":"receiving", and after that result of
electrum ismine _thisaddress_ became true.
Ok, next I tried to send BTC from this address and received an error: 'code': -26, 'message': '16: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation) - this error means "error in sign of transaction". Sending BTC from addresses, restored from seed, was fine.
Next, I tried to export private key of _thisaddress_. It was ok, but, when I tried to import it to new wallet, I saw, that address of this private key did not match with _thisaddress_. I think, that this situation and error: 'code': -26 have one reason.
Next, I exported all 700+ addresses from payment requests, flushed tag "addresses":"receiving" in wallet_file and manually added all this addresses in this tag. After that, I exported all private keys from this wallet and imported them to new wallet. The balance of new wallet became correct and I could send BTC from this addresses.
Question: Why did this happen?