Skip to content

Commit df613c4

Browse files
committed
[wallet] v2 wallet format compatibility
1 parent f072bc6 commit df613c4

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

src/chain.h

+10
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class CBlockIndex
223223
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
224224
int32_t nSequenceId;
225225

226+
// The time at which this block was first seen locally.
227+
int64_t nArrivalTime;
228+
226229
//! (memory only) Maximum nTime in the chain up to and including this block.
227230
unsigned int nTimeMax;
228231

@@ -255,6 +258,7 @@ class CBlockIndex
255258
nTime = 0;
256259
nBits = 0;
257260
nNonce = uint256();
261+
nArrivalTime = -1;
258262
nSolution.clear();
259263
}
260264

@@ -335,6 +339,11 @@ class CBlockIndex
335339

336340
static constexpr int nMedianTimeSpan = 11;
337341

342+
int64_t GetBlockArrivalTime() const
343+
{
344+
return nArrivalTime;
345+
}
346+
338347
int64_t GetMedianTimePast() const
339348
{
340349
int64_t pmedian[nMedianTimeSpan];
@@ -448,6 +457,7 @@ class CDiskBlockIndex : public CBlockIndex
448457
READWRITE(nTime);
449458
READWRITE(nBits);
450459
READWRITE(nNonce);
460+
READWRITE(nArrivalTime);
451461
READWRITE(nSolution);
452462

453463
// Only read/write nSproutValue if the client version used to create

src/rpc/blockchain.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
158158
result.pushKV("bits", strprintf("%08x", blockindex->nBits));
159159
result.pushKV("difficulty", GetDifficulty(blockindex));
160160
result.pushKV("chainwork", blockindex->nChainWork.GetHex());
161+
result.pushKV("arrivaltime", blockindex->GetBlockArrivalTime());
161162
result.pushKV("nTx", (uint64_t)blockindex->nTx);
162163

163164
if (blockindex->pprev)

src/txdb.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
537537
pindexNew->nTime = diskindex.nTime;
538538
pindexNew->nBits = diskindex.nBits;
539539
pindexNew->nNonce = diskindex.nNonce;
540+
pindexNew->nArrivalTime = diskindex.nArrivalTime;
540541
pindexNew->nSolution = diskindex.nSolution;
541542
pindexNew->nStatus = diskindex.nStatus;
542543
pindexNew->nCachedBranchId = diskindex.nCachedBranchId;

src/validation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3677,6 +3677,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
36773677
{
36783678
LOCK(cs_nBlockSequenceId);
36793679
pindex->nSequenceId = nBlockSequenceId++;
3680+
pindex->nArrivalTime = GetAdjustedTime();
36803681
}
36813682
if (m_chain.Tip() == nullptr || !setBlockIndexCandidates.value_comp()(pindex, m_chain.Tip())) {
36823683
setBlockIndexCandidates.insert(pindex);

src/wallet/walletdb.cpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ const std::string ACENTRY{"acentry"};
2424
const std::string BESTBLOCK_NOMERKLE{"bestblock_nomerkle"};
2525
const std::string BESTBLOCK{"bestblock"};
2626
const std::string CRYPTED_KEY{"ckey"};
27-
const std::string SPROUT_CRYPTED_KEY{"sprout_ckey"};
28-
const std::string SAPLING_CRYPTED_KEY{"sapling_ckey"};
27+
const std::string SPROUT_CRYPTED_KEY{"czkey"};
28+
const std::string SAPLING_CRYPTED_KEY{"csapzkey"};
2929
const std::string CSCRIPT{"cscript"};
3030
const std::string DEFAULTKEY{"defaultkey"};
3131
const std::string DESTDATA{"destdata"};
3232
const std::string FLAGS{"flags"};
33-
const std::string HDCHAIN{"hdchain"};
34-
const std::string SAPLING_HDCHAIN{"sapling_hdchain"};
33+
const std::string HDCHAIN{"base_hdchain"};
34+
const std::string ZEC_HDCHAIN{"hdchain"};
3535
const std::string KEYMETA{"keymeta"};
36-
const std::string SPROUT_KEYMETA{"sprout_keymeta"};
37-
const std::string SAPLING_KEYMETA{"sapling_keymeta"};
36+
const std::string SPROUT_KEYMETA{"zkeymeta"};
37+
const std::string SAPLING_KEYMETA{"sapzkeymeta"};
3838
const std::string KEY{"key"};
39-
const std::string SPROUT_KEY{"sprout_key"};
40-
const std::string SAPLING_KEY{"sapling_key"};
39+
const std::string SPROUT_KEY{"zkey"};
40+
const std::string SAPLING_KEY{"sapzkey"};
4141
const std::string MASTER_KEY{"mkey"};
4242
const std::string MINVERSION{"minversion"};
4343
const std::string NAME{"name"};
@@ -56,11 +56,11 @@ const std::string WATCHMETA{"watchmeta"};
5656
const std::string SPROUT_WATCHMETA{"sprout_watchmeta"};
5757
const std::string SAPLING_WATCHMETA{"sapling_watchmeta"};
5858
const std::string WATCHS{"watchs"};
59-
const std::string SPROUT_WATCHS{"sprout_watchs"};
59+
const std::string SPROUT_WATCHS{"vkey"};
6060
const std::string SAPLING_WATCHS{"sapling_watchs"};
61-
const std::string SAPLING_ADDRESS{"sapling_address"};
62-
const std::string ZEC_HDSEED{"zec_hdseed"};
63-
const std::string ZEC_CRYPTED_HDSEED{"zec_chdseed"};
61+
const std::string SAPLING_ADDRESS{"sapzaddr"};
62+
const std::string ZEC_HDSEED{"hdseed"};
63+
const std::string ZEC_CRYPTED_HDSEED{"chdseed"};
6464
const std::string WITNESSCACHESIZE{"witnesscachesize"};
6565
} // namespace DBKeys
6666

@@ -527,8 +527,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
527527
wss.nSaplingKeyMeta++;
528528

529529
pwallet->LoadSaplingZKeyMetadata(ivk, keyMeta);
530-
} else if (strType == DBKeys::SAPLING_ADDRESS)
531-
{
530+
} else if (strType == DBKeys::SAPLING_ADDRESS) {
532531
libzcash::SaplingPaymentAddress addr;
533532
ssKey >> addr;
534533
libzcash::SaplingIncomingViewingKey ivk;
@@ -623,7 +622,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
623622
CHDChain chain;
624623
ssValue >> chain;
625624
pwallet->SetHDChain(chain, true);
626-
} else if (strType == DBKeys::SAPLING_HDCHAIN) {
625+
} else if (strType == DBKeys::ZEC_HDCHAIN) {
627626
CZecHDChain chain;
628627
ssValue >> chain;
629628
pwallet->SetZecHDChain(chain, true);
@@ -1042,7 +1041,7 @@ bool WalletBatch::WriteCryptedZecHDSeed(const uint256& seedFp, const std::vector
10421041

10431042
bool WalletBatch::WriteZecHDChain(const CZecHDChain& chain)
10441043
{
1045-
return WriteIC(DBKeys::SAPLING_HDCHAIN, chain);
1044+
return WriteIC(DBKeys::ZEC_HDCHAIN, chain);
10461045
}
10471046

10481047
bool WalletBatch::WriteZKey(const libzcash::SproutPaymentAddress& addr, const libzcash::SproutSpendingKey& key, const CKeyMetadata &keyMeta)

src/wallet/walletdb.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extern const std::string DEFAULTKEY;
6868
extern const std::string DESTDATA;
6969
extern const std::string FLAGS;
7070
extern const std::string HDCHAIN;
71-
extern const std::string SAPLING_HDCHAIN;
71+
extern const std::string ZEC_HDCHAIN;
7272
extern const std::string KEY;
7373
extern const std::string SPROUT_KEY;
7474
extern const std::string SAPLING_KEY;
@@ -173,7 +173,8 @@ class CKeyMetadata
173173
{
174174
public:
175175
static const int VERSION_BASIC=1;
176-
static const int VERSION_WITH_HDDATA=10;
176+
static const int VERSION_WITH_ZEC_HDDATA=10;
177+
static const int VERSION_WITH_HDDATA=11;
177178
static const int VERSION_WITH_KEY_ORIGIN = 12;
178179
static const int CURRENT_VERSION=VERSION_WITH_KEY_ORIGIN;
179180
int nVersion;
@@ -200,12 +201,15 @@ class CKeyMetadata
200201
inline void SerializationOp(Stream& s, Operation ser_action) {
201202
READWRITE(this->nVersion);
202203
READWRITE(nCreateTime);
203-
if (this->nVersion >= VERSION_WITH_HDDATA)
204+
if (this->nVersion >= VERSION_WITH_ZEC_HDDATA)
204205
{
205206
READWRITE(hdKeypath);
206-
READWRITE(hd_seed_id);
207207
READWRITE(seedFp);
208208
}
209+
if (this->nVersion >= VERSION_WITH_HDDATA)
210+
{
211+
READWRITE(hd_seed_id);
212+
}
209213
if (this->nVersion >= VERSION_WITH_KEY_ORIGIN)
210214
{
211215
READWRITE(key_origin);

0 commit comments

Comments
 (0)