mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 05:23:01 +01:00
Merge #10795: No longer ever reuse keypool indexes
1fc8c3d
No longer ever reuse keypool indexes (Matt Corallo)
Pull request description:
This fixes an issue where you could reserve a keypool entry, then
top up the keypool, writing out a new key at the given index, then
return they key from the pool. This isnt likely to cause issues,
but given there is no reason to ever re-use keypool indexes
(they're 64 bits...), best to avoid it alltogether.
Builds on #10235, should probably get a 15 tag.
Tree-SHA512: c13a18a90f1076fb74307f2d64e9d80149811524c6bda259698ff2c65adaf8c6c3f2a3a07a5f4bf03251bc942ba8f5fd33a4427aa4256748c40b062991682caf
This commit is contained in:
parent
d04633d28c
commit
b8c1d66fb9
@ -4333,21 +4333,18 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
|
|||||||
if (i < missingInternal) {
|
if (i < missingInternal) {
|
||||||
fInternal = true;
|
fInternal = true;
|
||||||
}
|
}
|
||||||
if (!setInternalKeyPool.empty()) {
|
|
||||||
nEnd = *(--setInternalKeyPool.end()) + 1;
|
assert(m_max_keypool_index < std::numeric_limits<int64_t>::max()); // How in the hell did you use so many keys?
|
||||||
}
|
int64_t index = ++m_max_keypool_index;
|
||||||
if (!setExternalKeyPool.empty()) {
|
|
||||||
nEnd = std::max(nEnd, *(--setExternalKeyPool.end()) + 1);
|
if (!walletdb.WritePool(index, CKeyPool(GenerateNewKey(walletdb, internal), internal))) {
|
||||||
}
|
|
||||||
// TODO: implement keypools for all accounts?
|
|
||||||
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey(walletdb, 0, fInternal), fInternal))) {
|
|
||||||
throw std::runtime_error(std::string(__func__) + ": writing generated key failed");
|
throw std::runtime_error(std::string(__func__) + ": writing generated key failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fInternal) {
|
if (fInternal) {
|
||||||
setInternalKeyPool.insert(nEnd);
|
setInternalKeyPool.insert(index);
|
||||||
} else {
|
} else {
|
||||||
setExternalKeyPool.insert(nEnd);
|
setExternalKeyPool.insert(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missingInternal + missingExternal > 0) {
|
if (missingInternal + missingExternal > 0) {
|
||||||
|
@ -753,6 +753,7 @@ private:
|
|||||||
|
|
||||||
std::set<int64_t> setInternalKeyPool;
|
std::set<int64_t> setInternalKeyPool;
|
||||||
std::set<int64_t> setExternalKeyPool;
|
std::set<int64_t> setExternalKeyPool;
|
||||||
|
int64_t m_max_keypool_index;
|
||||||
|
|
||||||
int64_t nTimeFirstKey;
|
int64_t nTimeFirstKey;
|
||||||
|
|
||||||
@ -799,13 +800,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadKeyPool(int nIndex, const CKeyPool &keypool)
|
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
|
||||||
{
|
{
|
||||||
if (keypool.fInternal) {
|
if (keypool.fInternal) {
|
||||||
setInternalKeyPool.insert(nIndex);
|
setInternalKeyPool.insert(nIndex);
|
||||||
} else {
|
} else {
|
||||||
setExternalKeyPool.insert(nIndex);
|
setExternalKeyPool.insert(nIndex);
|
||||||
}
|
}
|
||||||
|
m_max_keypool_index = std::max(m_max_keypool_index, nIndex);
|
||||||
|
|
||||||
// If no metadata exists yet, create a default with the pool key's
|
// If no metadata exists yet, create a default with the pool key's
|
||||||
// creation time. Note that this may be overwritten by actually
|
// creation time. Note that this may be overwritten by actually
|
||||||
@ -851,6 +853,7 @@ public:
|
|||||||
nAccountingEntryNumber = 0;
|
nAccountingEntryNumber = 0;
|
||||||
nNextResend = 0;
|
nNextResend = 0;
|
||||||
nLastResend = 0;
|
nLastResend = 0;
|
||||||
|
m_max_keypool_index = 0;
|
||||||
nTimeFirstKey = 0;
|
nTimeFirstKey = 0;
|
||||||
fBroadcastTransactions = false;
|
fBroadcastTransactions = false;
|
||||||
nRelockTime = 0;
|
nRelockTime = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user