Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: Improve log output for errors during load #15491

Merged

Conversation

gwillen
Copy link
Contributor

@gwillen gwillen commented Feb 27, 2019

When loading the wallet, display the entire path in error messages, instead of
the name (which, for the default wallet, is the empty string.)

When an exception occurs during wallet loading, display e.what() if possible,
instead of nothing.

src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/walletdb.cpp Outdated Show resolved Hide resolved
src/wallet/walletdb.cpp Outdated Show resolved Hide resolved
@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch 2 times, most recently from 4b4127b to e5637b1 Compare February 27, 2019 02:43
@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 27, 2019

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

Conflicts

No conflicts as of last run.

@Sjors
Copy link
Member

Sjors commented Feb 27, 2019

tACK e5637b1

I now get a flood of this with one my broken wallets:

2019-02-27T08:32:30Z [default wallet] CDataStream::read(): end of data: unspecified iostream_category error
2019-02-27T08:32:30Z [default wallet] CDataStream::read(): end of data: unspecified iostream_category error
2019-02-27T08:32:30Z [default wallet] CDataStream::read(): end of data: unspecified iostream_category error

@gwillen
Copy link
Contributor Author

gwillen commented Feb 27, 2019

@Sjors Yep, that's the same thing I get -- at least in my case, each of those is a 'keymeta' entry, whose value is missing the final has_key_origin field of CKeyMetaData.

I think the flood of log entries is definitely better than the lack of any, although the volume is a little annoying (but I think it makes sense when encountering a broken wallet file to be verbose about it.)

@Sjors
Copy link
Member

Sjors commented Feb 27, 2019

It's fine. This is the type of error that should really never happen in the real world, so indeed when it does, the more information the better.

@instagibbs
Copy link
Member

@Sjors frankly these type of changes are mostly for developer's sanity. I've run into similar issues with wallet entries and felt compelled to upstream changes.

@instagibbs
Copy link
Member

utACK e5637b1

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

Does it make sense to commit some broken wallets to the repo?

src/wallet/walletdb.cpp Outdated Show resolved Hide resolved
@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from e5637b1 to 3bd35f2 Compare March 4, 2019 08:39
@gwillen
Copy link
Contributor Author

gwillen commented Mar 4, 2019

The idea of committing a broken wallet as a test case makes sense to me, but (1) I seem to recall I've heard people say in past cases that committing a binary wallet file to the repo is not reasonable even as test data, and (2) I definitely don't know how to go about minimizing such a test case, which seems both necessary and painful.

@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from 3bd35f2 to 0eea55f Compare March 6, 2019 04:36
@gwillen
Copy link
Contributor Author

gwillen commented Mar 6, 2019

Rebased.

@promag
Copy link
Member

promag commented Mar 6, 2019

Restarted travis job 6 - failed on commit 4e7fea2 with:

47/118 - rpc_psbt.py failed, Duration: 4 s
stdout:
2019-03-06T05:02:08.027000Z TestFramework (INFO): Initializing test directory /tmp/test_runner_₿_🏃_20190306_045534/rpc_psbt_69
2019-03-06T05:02:11.006000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/test_framework.py", line 175, in main
    self.run_test()
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/rpc_psbt.py", line 149, in run_test
    assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].converttopsbt, signedtx['hex'])
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/util.py", line 105, in assert_raises_rpc_error
    assert try_rpc(code, message, fun, *args, **kwds), "No exception raised"
AssertionError: No exception raised

@promag
Copy link
Member

promag commented Mar 6, 2019

@gwillen have you seen #15334? Do you think logging the absolute path makes it more clear - instead of "[default wallet]"?

@gwillen
Copy link
Contributor Author

gwillen commented Mar 6, 2019

Yeah, I think switching to absolute path would make sense. I assume I just need to switch from GetName to GetPath. Will try it out.

@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from 0eea55f to aa711d9 Compare March 6, 2019 21:23
@gwillen
Copy link
Contributor Author

gwillen commented Mar 6, 2019

Switched to GetPath().string() instead of GetName(). Removed the rename to log_wallet_name, in the interest of minimizing the size of the diff, since it is once again a wallet file name. (I can reinstate the rename if preferred.)

@gwillen
Copy link
Contributor Author

gwillen commented Mar 6, 2019

Oh, no, this didn't do what I wanted at all. On further inspection of #15334, it doesn't actually log the absolute path, it just logs the filename, but more importantly it doesn't use WalletLocation::GetPath, but it has some other place it's getting this info. GetPath is giving me the wallet directory, excluding the filename, it seems.

Can someone clue me in to the exact semantics / interpretation of the name and path in WalletLocation? Can I just slap "wallet.dat" on the end of the output of GetPath and be good, or are there other cases?

@ryanofsky
Copy link
Contributor

I'd suggest adding a new method to the BerkeleyDatabase class:

+    fs::path DataFilePath() const { return env->Directory() / strFile; }

and printing the path with GetDBHandle().DataFilePath().string()

@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from aa711d9 to 7cf7290 Compare March 8, 2019 01:54
@gwillen
Copy link
Contributor Author

gwillen commented Mar 8, 2019

@ryanofsky I ended up taking a slightly different approach, because at this point we do not have a CWallet yet to get a db handle from (we are in the flow to open one.) Instead, I added a free function for normalizing paths.

(I could have accomplished the same thing without adding a function, by calling SplitWalletPath (but it's static, and a slightly weird interface for this) or GetWalletEnv (but it's a very weird interface for this, and also it manipulates g_dbenvs, which I don't know the consequences of and seems a little heavy-handed for just figuring out a path.)

@ryanofsky
Copy link
Contributor

Looks good if you s/wallet database file/data file path/ and s/FullWalletFilePath/WalletDataFilePath/.

I'd suggest:

/** Given a wallet directory path or legacy file path, return path to main data file in the wallet database. */
fs::path WalletDataFilePath(const fs::path& wallet_path);

Wallet databases are really directories, not files. At a low level, wallet databases include not just wallet.dat files but also write-ahead database/log.?????????? files. At the user level, the -wallet option and createwallet rpc create new wallets as directories, and the -rpcwallet option and getwalletinfo rpc use directory paths.

The only reason it makes sense to reference files instead of directories in log messages is to disambiguate in the legacy case where there can be multiple data files for different wallets stored in the same directory and sharing mixed log files. (This was a misfeature which is mostly removed, except we still support loading these wallets in the top level walletdir.)

@gwillen
Copy link
Contributor Author

gwillen commented Mar 13, 2019

Got it, thanks @ryanofsky , makes sense. Changed as suggested!

@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from 7cf7290 to 17d0114 Compare March 13, 2019 00:22
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 17d0114

It would be good to update the PR description #15491 (comment) which still references "[default wallet]".

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

utACK 17d0114.

@@ -84,6 +84,13 @@ bool IsWalletLoaded(const fs::path& wallet_path)
return database && database->IsDatabaseLoaded(database_filename);
}

fs::path WalletDataFilePath(const fs::path& wallet_path) {
Copy link
Member

Choose a reason for hiding this comment

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

nit, { should be in new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curses, done.

I'm afraid my brain is stuck in the wrong style for life, sorry.

When loading the wallet, display the entire path in error messages, instead of
the name (which, for the default wallet, is the empty string.)

When an exception occurs during wallet loading, display e.what() if possible,
instead of nothing.
@gwillen gwillen force-pushed the feature-improve-wallet-load-debug-output branch from 17d0114 to faf3698 Compare March 15, 2019 01:49
@gwillen
Copy link
Contributor Author

gwillen commented Mar 15, 2019

Fixed the PR description.

Fixed the brace @promag was complaining about.

No other changes.

@meshcollider
Copy link
Contributor

utACK faf3698

@meshcollider meshcollider merged commit faf3698 into bitcoin:master Mar 18, 2019
meshcollider added a commit that referenced this pull request Mar 18, 2019
faf3698 wallet: Improve log output for errors during load (Glenn Willen)

Pull request description:

  When loading the wallet, display the entire path in error messages, instead of
  the name (which, for the default wallet, is the empty string.)

  When an exception occurs during wallet loading, display e.what() if possible,
  instead of nothing.

Tree-SHA512: 435247628db669579bb694ba4b53ba174fe42c0329fc72f09fc274bb28463ee69f53412abb2a3b45bb8f59f7eb928c0167e397b8d0a514135142192a87294614
linuxsh2 pushed a commit to linuxsh2/dash that referenced this pull request Aug 11, 2021
faf3698 wallet: Improve log output for errors during load (Glenn Willen)

Pull request description:

  When loading the wallet, display the entire path in error messages, instead of
  the name (which, for the default wallet, is the empty string.)

  When an exception occurs during wallet loading, display e.what() if possible,
  instead of nothing.

Tree-SHA512: 435247628db669579bb694ba4b53ba174fe42c0329fc72f09fc274bb28463ee69f53412abb2a3b45bb8f59f7eb928c0167e397b8d0a514135142192a87294614
@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.

None yet

9 participants