From 70134eb34f58f0c572e7c3775e292d408f03b5ab Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 18 Oct 2021 18:22:59 -0400 Subject: [PATCH] wallet: Properly set hd chain counters when loading When build CHDChains out of CKeyMetadata, the chain counters are actually 1 based, not 0 based, so 1 must be added to each index. --- src/wallet/walletdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index f392649bd9f..3e99d145d89 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -556,9 +556,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, } if (internal) { chain.nVersion = CHDChain::VERSION_HD_CHAIN_SPLIT; - chain.nInternalChainCounter = std::max(chain.nInternalChainCounter, index); + chain.nInternalChainCounter = std::max(chain.nInternalChainCounter, index + 1); } else { - chain.nExternalChainCounter = std::max(chain.nExternalChainCounter, index); + chain.nExternalChainCounter = std::max(chain.nExternalChainCounter, index + 1); } } } else if (strType == DBKeys::WATCHMETA) {