Skip to content

Log the actual wallet file version and no longer publicly expose the "version" record - #15588

Merged
meshcollider merged 3 commits into
bitcoin:masterfrom
achow101:rm-wallet-nfileversion
Jul 27, 2019
Merged

meshcollider merged 3 commits into
bitcoin:masterfrom
achow101:rm-wallet-nfileversion

Conversation

@achow101

@achow101 achow101 commented Mar 13, 2019 •

Copy link
Copy Markdown
Member

The wallet file version is stored in the "minversion" record, not the "version" record. However "version" is no longer used anywhere except to record the highest versioned client which has opened a wallet file (which is currently only used to check whether this was most recently opened by a 0.4.0 or 0.5.0rc1 client which had a broken wallet encryption implementation). Furthermore, "version" was logged to the debug.log which is confusing because it is not the actual wallet file version.

This PR changes it so that this confusion largely no longer exists. The wallet file version logging is changed to use "minversion" and reading and writing the "version" record is no longer publicly exposed to prevent potential confusion about whether the actual file version is being read or written. Lastly, in the one place it is actually used, the variable name is changed from nFileVersion to last_client to better reflect what that record actually represents.

@ryanofsky

Copy link
Copy Markdown
Contributor

Just to clarify, is the only user-visible change here replacing:

nFileVersion = [version number of the newest wallet software that ever opened the wallet in the past]

with

Wallet File Version = [minimum wallet software version required to open the wallet file]

?

Comment thread src/wallet/db.cpp
bool fTmp = fReadOnly;
fReadOnly = false;
WriteVersion(CLIENT_VERSION);
Write(std::string("version"), CLIENT_VERSION);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something for a separate PR, but can we just drop this write entirely? It seems redundant given the write already in WalletBatch::LoadWallet, and better not to write the same field in two different places.

@achow101 achow101 Apr 16, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this is redundant. It's making sure that the version field exists, whereas WalletBatch::LoadWallet doesn't necessarily do that.

But we can remove this in a separate PR if it is redundant.

@achow101

Copy link
Copy Markdown
Member Author

Just to clarify, is the only user-visible change here replacing:

Yes.

@DrahtBot

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15709 (Do not add setting as unknown by Bushstar)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj

laanwj commented Apr 10, 2019

Copy link
Copy Markdown
Member

utACK 96a46f5

Comment thread src/wallet/walletdb.cpp Resolved
Comment thread src/wallet/walletdb.cpp Resolved
@laanwj

laanwj commented Jul 11, 2019

Copy link
Copy Markdown
Member

@meshcollider can you please take a look here

@laanwj
laanwj requested a review from meshcollider July 11, 2019 18:57

@jb55 jb55 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, I reviewed the changes in detail and confirmed they make sense logically. I have a few comments before I Approach ACK. Let me know what you think.

Comment thread src/wallet/walletdb.cpp

if (last_client < CLIENT_VERSION) // Update
WriteVersion(CLIENT_VERSION);
m_batch.Write(std::string("version"), CLIENT_VERSION);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with open-coding this here since there is only one use of it, but for semantic clarity nit we could have just moved it into a static method named {Read,Write}LatestClientVersion or something.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to leave it as is since these are the only uses of it. I had originally planned on removing these reads and writes entirely, but I was not certain that doing so wouldn't break backwards compatibility so I left them in.

Comment thread src/wallet/walletdb.cpp Resolved
Comment thread src/wallet/walletdb.cpp
}
} else if (strType != "bestblock" && strType != "bestblock_nomerkle" &&
strType != "minversion" && strType != "acentry") {
strType != "minversion" && strType != "acentry" && strType != "version") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this comment for other reviewers when trying to understand it. The wallet logs any unknown records, since we're not handling the version record specifically anymore (it was a no-op), we don't want to log version as an unknown record. It is still read-in during LoadWallet.

Comment thread src/wallet/walletdb.cpp Resolved
achow101 added 3 commits July 22, 2019 13:02
nFileVersion is not the actual file version and is not used except
in one place. So it is removed from CWalletScanState and changed so
that it is just read at the place it is needed. Furthermore, the
"version" record now only indicates the version of the highest
versioned client that has opened a wallet file so the variable
name is changed accordingly
The actual wallet file version is the minversion record, not the
version record.
The "version" record that these functions read and write are not
used anywhere in the code except for one place. There is no reason
to expose these functions publicly. Furthermore, this avoids potential
confusion as developers may mistake these functions for actually
reading and writing the wallet version when they do not.
@achow101
achow101 force-pushed the rm-wallet-nfileversion branch from 96a46f5 to 35e60e7 Compare July 22, 2019 17:03

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 35e60e7. This code still pretty confusing, but a little simpler now. And the previous log statement was really misleading and useless compared to the new one here.

@jb55

jb55 commented Jul 23, 2019

Copy link
Copy Markdown
Contributor

ACK 35e60e7, I compiled locally as a quick sanity check.

@meshcollider meshcollider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! utACK 35e60e7

@meshcollider
meshcollider merged commit 35e60e7 into bitcoin:master Jul 27, 2019
meshcollider added a commit that referenced this pull request Jul 27, 2019
…ly expose the "version" record

35e60e7 Remove ReadVersion and WriteVersion (Andrew Chow)
b3d4f6c Log the actual wallet file version (Andrew Chow)
c88e87c Remove nFileVersion from CWalletScanState (Andrew Chow)

Pull request description:

  The wallet file version is stored in the "minversion" record, not the "version" record. However "version" is no longer used anywhere except to record the highest versioned client which has opened a wallet file (which is currently only used to check whether this was most recently opened by a 0.4.0 or 0.5.0rc1 client which had a broken wallet encryption implementation). Furthermore, "version" was logged to the debug.log which is confusing because it is not the actual wallet file version.

  This PR changes it so that this confusion largely no longer exists. The wallet file version logging is changed to use "minversion" and reading and writing the "version" record is no longer publicly exposed to prevent potential confusion about whether the actual file version is being read or written. Lastly, in the one place it is actually used, the variable name is changed from nFileVersion to last_client to better reflect what that record actually represents.

ACKs for top commit:
  jb55:
    ACK 35e60e7, I compiled locally as a quick sanity check.
  ryanofsky:
    utACK 35e60e7. This code still pretty confusing, but a little simpler now. And the previous log statement was really misleading and useless compared to the new one here.
  meshcollider:
    Looks good, thanks! utACK 35e60e7

Tree-SHA512: f782b2f215d07fbc9b806322bda8085445b81c02b65ca674a8c6a3e1de505a0abd050669afe0ead4778816144a1c18462e13930071cedb7227a058aeb39493f7
konez2k pushed a commit to bitcoin-green/bitcoingreen that referenced this pull request Jul 27, 2019
… publicly expose the "version" record

35e60e7 Remove ReadVersion and WriteVersion (Andrew Chow)
b3d4f6c Log the actual wallet file version (Andrew Chow)
c88e87c Remove nFileVersion from CWalletScanState (Andrew Chow)

Pull request description:

  The wallet file version is stored in the "minversion" record, not the "version" record. However "version" is no longer used anywhere except to record the highest versioned client which has opened a wallet file (which is currently only used to check whether this was most recently opened by a 0.4.0 or 0.5.0rc1 client which had a broken wallet encryption implementation). Furthermore, "version" was logged to the debug.log which is confusing because it is not the actual wallet file version.

  This PR changes it so that this confusion largely no longer exists. The wallet file version logging is changed to use "minversion" and reading and writing the "version" record is no longer publicly exposed to prevent potential confusion about whether the actual file version is being read or written. Lastly, in the one place it is actually used, the variable name is changed from nFileVersion to last_client to better reflect what that record actually represents.

ACKs for top commit:
  jb55:
    ACK 35e60e7, I compiled locally as a quick sanity check.
  ryanofsky:
    utACK 35e60e7. This code still pretty confusing, but a little simpler now. And the previous log statement was really misleading and useless compared to the new one here.
  meshcollider:
    Looks good, thanks! utACK 35e60e7

Tree-SHA512: f782b2f215d07fbc9b806322bda8085445b81c02b65ca674a8c6a3e1de505a0abd050669afe0ead4778816144a1c18462e13930071cedb7227a058aeb39493f7
kwvg added a commit to kwvg/dash that referenced this pull request Dec 12, 2021
UdjinM6 added a commit to dashpay/dash that referenced this pull request Dec 12, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants