Skip to content

Commit

Permalink
ARMORY-76
Browse files Browse the repository at this point in the history
fixing the 99% bug, with proper of ledger entries and reorgs
  • Loading branch information
goatpig committed Apr 2, 2014
1 parent 575bf4b commit 6cc7c8a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ArmoryQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2529,8 +2529,8 @@ def finishLoadBlockchain(self):
# Now that the blockchain is loaded, let's populate the wallet info
if TheBDM.isInitialized():

for wltID in self.walletMap.iterkeys():
TheBDM.bdm.unregisterWallet(self.walletMap[wltID].cppWallet)
#for wltID in self.walletMap.iterkeys():
# TheBDM.bdm.unregisterWallet(self.walletMap[wltID].cppWallet)

self.currBlockNum = TheBDM.getTopBlockHeight()
self.setDashboardDetails()
Expand Down
22 changes: 20 additions & 2 deletions cppForSwig/BlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,16 @@ void BtcWallet::pprintAlot(uint32_t topBlk, bool withAddr)
}
}

void BtcWallet::reorgChangeBlkNum(uint32_t newBlkHgt)
{
if(newBlkHgt<lastScanned_)
{
lastScanned_ = newBlkHgt;
reorgTrigger_ = true;
}
}


/////////////////////////////////////////////////////////////////////////////
// This method is used in the registeredScrAddrScan to conditionally create and
// insert a transaction into the registered list
Expand Down Expand Up @@ -3697,7 +3707,12 @@ void BlockDataManager_LevelDB::scanRegisteredTxForWallet( BtcWallet & wlt,
{
SCOPED_TIMER("scanRegisteredTxForWallet");

if(!blkStart && blkStart > wlt.lastScanned_) blkStart = wlt.lastScanned_;
if(!wlt.reorgTrigger_)
{
blkStart = wlt.lastScanned_;
wlt.reorgTrigger_ = false;
}

bool isMainWallet = true;
if(&wlt != (*registeredWallets_.begin())) isMainWallet = false;

Expand Down Expand Up @@ -4522,12 +4537,15 @@ void BlockDataManager_LevelDB::buildAndScanDatabases(
// Update registered address list so we know what's already been scanned
lastTopBlock_ = getTopBlockHeight() + 1;
allScannedUpToBlk_ = lastTopBlock_;

LOGINFO << "Updating registered addresses";
updateRegisteredScrAddrs(lastTopBlock_);

// Since loading takes so long, there's a good chance that new block data
// came in... let's get it.
readBlkFileUpdate();

LOGINFO << "Scanning Wallets";
set<BtcWallet*>::iterator wltIter;
for(wltIter = registeredWallets_.begin();
wltIter != registeredWallets_.end();
Expand Down Expand Up @@ -5168,7 +5186,7 @@ void BlockDataManager_LevelDB::updateWalletAfterReorg(BtcWallet & wlt)
changeToBlkNum = getTxRefByHash(txHash).getBlockHeight();
addrLedg[i].changeBlkNum(changeToBlkNum);

wlt.changeBlkNum(changeToBlkNum);
wlt.reorgChangeBlkNum(changeToBlkNum);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions cppForSwig/BlockUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class ScrAddrObj
class BtcWallet
{
public:
BtcWallet(void) : bdmPtr_(NULL) {lastScanned_ = 0;}
BtcWallet(void) : bdmPtr_(NULL), lastScanned_(0), reorgTrigger_(0) {}
explicit BtcWallet(BlockDataManager_LevelDB* bdm) : bdmPtr_(bdm) {}
~BtcWallet(void);

Expand Down Expand Up @@ -448,10 +448,10 @@ class BtcWallet

vector<LedgerEntry> & getEmptyLedger(void) { EmptyLedger_.clear(); return EmptyLedger_;}

void changeBlkNum(uint32_t newBlkHgt)
{if(newBlkHgt<lastScanned_) lastScanned_ = newBlkHgt;}
void reorgChangeBlkNum(uint32_t newBlkHgt);

uint32_t lastScanned_;

uint32_t reorgTrigger_;

private:
vector<ScrAddrObj*> scrAddrPtrs_;
Expand All @@ -471,7 +471,6 @@ class BtcWallet
BlockDataManager_LevelDB* bdmPtr_;
static vector<LedgerEntry> EmptyLedger_; // just a null-reference object


};


Expand Down

0 comments on commit 6cc7c8a

Please sign in to comment.