File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -3211,21 +3211,17 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
3211
3211
internal = true ;
3212
3212
}
3213
3213
3214
- if (!setInternalKeyPool.empty ()) {
3215
- nEnd = *(setInternalKeyPool.rbegin ()) + 1 ;
3216
- }
3217
- if (!setExternalKeyPool.empty ()) {
3218
- nEnd = std::max (nEnd, *(setExternalKeyPool.rbegin ()) + 1 );
3219
- }
3214
+ assert (m_max_keypool_index < std::numeric_limits<int64_t >::max ()); // How in the hell did you use so many keys?
3215
+ int64_t index = ++m_max_keypool_index;
3220
3216
3221
- if (!walletdb.WritePool (nEnd , CKeyPool (GenerateNewKey (walletdb, internal), internal))) {
3217
+ if (!walletdb.WritePool (index , CKeyPool (GenerateNewKey (walletdb, internal), internal))) {
3222
3218
throw std::runtime_error (std::string (__func__) + " : writing generated key failed" );
3223
3219
}
3224
3220
3225
3221
if (internal) {
3226
- setInternalKeyPool.insert (nEnd );
3222
+ setInternalKeyPool.insert (index );
3227
3223
} else {
3228
- setExternalKeyPool.insert (nEnd );
3224
+ setExternalKeyPool.insert (index );
3229
3225
}
3230
3226
}
3231
3227
if (missingInternal + missingExternal > 0 ) {
Original file line number Diff line number Diff line change @@ -701,6 +701,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
701
701
702
702
std::set<int64_t > setInternalKeyPool;
703
703
std::set<int64_t > setExternalKeyPool;
704
+ int64_t m_max_keypool_index;
704
705
705
706
int64_t nTimeFirstKey;
706
707
@@ -743,13 +744,14 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
743
744
}
744
745
}
745
746
746
- void LoadKeyPool (int nIndex, const CKeyPool &keypool)
747
+ void LoadKeyPool (int64_t nIndex, const CKeyPool &keypool)
747
748
{
748
749
if (keypool.fInternal ) {
749
750
setInternalKeyPool.insert (nIndex);
750
751
} else {
751
752
setExternalKeyPool.insert (nIndex);
752
753
}
754
+ m_max_keypool_index = std::max (m_max_keypool_index, nIndex);
753
755
754
756
// If no metadata exists yet, create a default with the pool key's
755
757
// creation time. Note that this may be overwritten by actually
@@ -795,6 +797,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
795
797
nAccountingEntryNumber = 0 ;
796
798
nNextResend = 0 ;
797
799
nLastResend = 0 ;
800
+ m_max_keypool_index = 0 ;
798
801
nTimeFirstKey = 0 ;
799
802
fBroadcastTransactions = false ;
800
803
nRelockTime = 0 ;
You can’t perform that action at this time.
0 commit comments