Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1WNorf-0006L9-DU for bitcoin-development@lists.sourceforge.net; Wed, 12 Mar 2014 19:30:55 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.213.65 as permitted sender) client-ip=209.85.213.65; envelope-from=travis.johanssen@gmail.com; helo=mail-yh0-f65.google.com; Received: from mail-yh0-f65.google.com ([209.85.213.65]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1WNore-0005Qm-Nw for bitcoin-development@lists.sourceforge.net; Wed, 12 Mar 2014 19:30:55 +0000 Received: by mail-yh0-f65.google.com with SMTP id z6so3169362yhz.8 for ; Wed, 12 Mar 2014 12:30:49 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.236.122.173 with SMTP id t33mr5036769yhh.117.1394652649266; Wed, 12 Mar 2014 12:30:49 -0700 (PDT) Received: by 10.170.79.9 with HTTP; Wed, 12 Mar 2014 12:30:49 -0700 (PDT) Date: Wed, 12 Mar 2014 13:30:49 -0600 Message-ID: From: Travis Johansen To: bitcoin-development@lists.sourceforge.net Content-Type: text/plain; charset=ISO-8859-1 X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (travis.johanssen[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1WNore-0005Qm-Nw Subject: [Bitcoin-development] zapwallettxes problem and wallet DB ordering X-BeenThere: bitcoin-development@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Mar 2014 19:30:55 -0000 Most of the issue seems to be because of CWalletDB::ReorderTransactions. After applying zapwallettxes, I noticed that listtransactions was no longer listing new transactions. After further investigation, new tx records were being given a low nOrderPos number while old acentry records were high enough that they were being ordered at the end of listtransactions all the time. My theory is that after the malleability attacks, the wallet DB got filled with dead transactions that were removed by zapwallettxes, then somehow ReorderTransactions got invoked and reset nOrderPosNext. This left the acentry records with high nOrderPos and the new transactions being added near the beginning. I believe this is due to two issues: 1. ReorderTransactions only collects the acentry records from "": ListAccountCreditDebit("", acentries); which should probably be: ListAccountCreditDebit("*", acentries); 2. ReorderTransactions seems to try too hard to maintain previous ordering and likely fails. Or at least it did after I applied the fix above. Would it not be better to just reorder the records with: for (TxItems::iterator it = txByTime.begin(); it != txByTime.end(); ++it) { CWalletTx *const pwtx = (*it).second.first; CAccountingEntry *const pacentry = (*it).second.second; int64_t& nOrderPos = (pwtx != 0) ? pwtx->nOrderPos : pacentry->nOrderPos; nOrderPos = ++nOrderPosNext; if (pwtx) { if (!WriteTx(pwtx->GetHash(), *pwtx)) return DB_LOAD_FAIL; } else if (!WriteAccountingEntry(pacentry->nEntryNo, *pacentry)) return DB_LOAD_FAIL; } if (!WriteOrderPosNext(nOrderPosNext)) return DB_LOAD_FAIL; Perhaps I'm missing something here but this seems to be a better solution given the simplicity of the ordering system. Unsurprisingly, applying the two fixes (and hacking one entry to an nOrderPos of -1 to trigger ReorderTransactions) corrects the ordering in my wallet DB. Or at least I think it does. Does anyone know why this might be a bad idea? I'm new to the code and would like to know if I'm potentially breaking something else.