@@ -1442,6 +1442,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
1442
1442
}
1443
1443
}
1444
1444
} else {
1445
+ TopUpKeyPoolCombo (0 , true );
1445
1446
for (const CTxOut& txout : tx.vout ) {
1446
1447
CScript scriptPubKey = txout.scriptPubKey ;
1447
1448
CTxDestination dest;
@@ -1456,7 +1457,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
1456
1457
CPubKey retrievePubKey;
1457
1458
if (GetPubKey (keyID, retrievePubKey)) {
1458
1459
if (ReserveKeyForTransactions (retrievePubKey)) {
1459
- TopUpKeyPoolCombo ( 0 , true );
1460
+ SetAddressBook (dest, " " , " " );
1460
1461
fNeedToRescanTransactions = true ;
1461
1462
}
1462
1463
}
@@ -4694,26 +4695,32 @@ bool CWallet::TopUpKeyPoolCombo(unsigned int kpSize, bool fIncreaseSize)
4694
4695
if (IsLocked (true ))
4695
4696
return false ;
4696
4697
4698
+ int64_t amountExternal = setExternalKeyPool.size ();
4699
+ int64_t amountInternal = setInternalKeyPool.size ();
4700
+
4697
4701
// Top up key pool
4698
4702
unsigned int nTargetSize;
4703
+ unsigned int defaultKeyPoolSize = std::max (GetArg (" -keypool" , DEFAULT_KEYPOOL_SIZE), (int64_t )0 );
4699
4704
if (kpSize > 0 )
4700
4705
nTargetSize = kpSize;
4701
4706
else {
4702
- nTargetSize = std::max (GetArg (" -keypool" , DEFAULT_KEYPOOL_SIZE), (int64_t )0 );
4707
+ if (defaultKeyPoolSize >= DynamicKeyPoolSize) {
4708
+ DynamicKeyPoolSize = defaultKeyPoolSize;
4709
+ }
4710
+
4711
+ if (fIncreaseSize ) {
4712
+ DynamicKeyPoolSize = DynamicKeyPoolSize + 1 ;
4713
+ } // if fIncreaseSize
4714
+
4715
+ nTargetSize = DynamicKeyPoolSize;
4703
4716
}
4704
4717
4705
4718
// count amount of available keys (internal, external)
4706
4719
// make sure the keypool of external and internal keys fits the user selected target (-keypool)
4707
- int64_t amountExternal = setExternalKeyPool.size ();
4708
- int64_t amountInternal = setInternalKeyPool.size ();
4720
+
4709
4721
int64_t missingExternal = std::max (std::max ((int64_t )nTargetSize, (int64_t )1 ) - amountExternal, (int64_t )0 );
4710
4722
int64_t missingInternal = std::max (std::max ((int64_t )nTargetSize, (int64_t )1 ) - amountInternal, (int64_t )0 );
4711
4723
4712
- if (fIncreaseSize ) {
4713
- missingExternal = missingExternal + 2 ;
4714
- missingInternal = missingInternal + 2 ;
4715
- }
4716
-
4717
4724
if (!IsHDEnabled ()) {
4718
4725
// don't create extra internal keys
4719
4726
missingInternal = 0 ;
@@ -4763,7 +4770,11 @@ bool CWallet::TopUpKeyPoolCombo(unsigned int kpSize, bool fIncreaseSize)
4763
4770
}
4764
4771
4765
4772
double dProgress = 100 .f * nEnd / (nTargetSize + 1 );
4766
- std::string strMsg = strprintf (_ (" Loading wallet... (%3.2f %%)" ), dProgress);
4773
+ std::string strMsg = " " ;
4774
+ if (dProgress <= 100 )
4775
+ strMsg = strprintf (_ (" Loading wallet... (%3.2f %%)" ), dProgress);
4776
+ else
4777
+ strMsg = strprintf (_ (" Increasing keypool... (%d)" ),amountExternal);
4767
4778
uiInterface.InitMessage (strMsg);
4768
4779
}
4769
4780
}
@@ -4904,7 +4915,9 @@ bool CWallet::ReserveKeyForTransactions(const CPubKey& pubKeyToReserve)
4904
4915
EraseIndex = true ;
4905
4916
IndexToErase = nIndex;
4906
4917
ReserveKeyCount++;
4907
- SaveRescanIndex = true ;
4918
+ if (ReserveKeyCount <= DEFAULT_RESCAN_THRESHOLD) {
4919
+ SaveRescanIndex = true ;
4920
+ }
4908
4921
}
4909
4922
it++;
4910
4923
}
@@ -5697,7 +5710,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile, const bool
5697
5710
walletInstance->ScanForWalletTransactions (pindexRescan, true );
5698
5711
5699
5712
// rescan if boolean is set. go back 100 transactions from most recent transaction involving me.
5700
- while ((walletInstance->fNeedToRescanTransactions ) && (walletInstance->ReserveKeyCount > DEFAULT_RESCAN_THRESHOLD )) {
5713
+ while ((walletInstance->fNeedToRescanTransactions ) && (walletInstance->ReserveKeyCount > 0 )) {
5701
5714
// initialize values
5702
5715
walletInstance->fNeedToRescanTransactions = false ;
5703
5716
walletInstance->ReserveKeyCount = 0 ;
@@ -5707,6 +5720,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile, const bool
5707
5720
computed_rescan_index = chainActive[computed_rescan_index->nHeight - 100 ];
5708
5721
}
5709
5722
walletInstance->ScanForWalletTransactions (computed_rescan_index, true );
5723
+
5710
5724
}
5711
5725
5712
5726
LogPrintf (" rescan %15dms\n " , GetTimeMillis () - nStart);
0 commit comments