Skip to content

Conversation

jonatack
Copy link
Member

To not needlessly alarm users upgrading from v0.20 and earlier, log a message rather than an error if the anchors.dat file is missing. "ERROR: DeserializeFileDB" will still be printed if anchors.dat is found but cannot be read. Motivation from this user report.

before

2021-02-14T14:23:46Z ERROR: DeserializeFileDB: Failed to open file ~/.bitcoin/anchors.dat
2021-02-14T14:23:46Z 0 block-relay-only anchors will be tried for connections.

after

2021-02-15T06:53:56Z Could not find anchors file "~/.bitcoin/anchors.dat"
2021-02-15T06:53:56Z 0 block-relay-only anchors will be tried for connections.

@hebasto
Copy link
Member

hebasto commented Feb 15, 2021

Concept ACK. Absence of anchors.dat is not an error.

To not needlessly alarm users upgrading from v0.20 and earlier...

The anchors.dat also could be absent after unclean shut down.

@naumenkogs
Copy link
Member

Concept ACK

@maflcko
Copy link
Member

maflcko commented Feb 15, 2021

Shouldn't this be done for all files? I am pretty sure it will still print that error for all other files on a fresh start.

@jonatack
Copy link
Member Author

For example, this check is done for the asmap file since #17812 (src/init.cpp::1512) but prints an error, as in this case the user may have provided an incorrect filename or path.

@maflcko
Copy link
Member

maflcko commented Feb 15, 2021

Maybe it would help to simply remove the screaming ERROR in all uppercase. It is not really a fatal error (if it was, the program should stop), but more like a debug statement.

2021-02-15T09:14:40Z ERROR: DeserializeFileDB: Failed to open file /tmp/new_datadir/a/regtest/banlist.dat
2021-02-15T09:14:40Z Failed to read fee estimates from /tmp/new_datadir/a/regtest/fee_estimates.dat. Continue anyway.
2021-02-15T09:14:40Z Failed to open mempool file from disk. Continuing anyway.
2021-02-15T09:14:40Z ERROR: DeserializeFileDB: Failed to open file /tmp/new_datadir/a/regtest/peers.dat
2021-02-15T09:14:40Z ERROR: DeserializeFileDB: Failed to open file /tmp/new_datadir/a/regtest/anchors.dat

@practicalswift
Copy link
Contributor

practicalswift commented Feb 15, 2021

Concept ACK

Thanks for removing unnecessary (and thus spammy) logging.

@jonatack
Copy link
Member Author

Maybe it would help to simply remove the screaming ERROR in all uppercase.

  1. that would not resolve the issue
  1. providing anchor.dat logs that distinguish between missing and unreadable anchors.dat seems more useful and helpful to users

This seems to be a clear improvement with a small change similar to what we do for the asmap file. I'm not sure if there are other files that would benefit from the same, but it doesn't need to be done here and I'm not sure there is a need to provide a general abstraction right now unless more cases are identified.

Suggesting this be merged to master and backported to 0.21.x

@laanwj
Copy link
Member

laanwj commented Feb 15, 2021

Concept and Code review ACK 8f51826

Maybe it would help to simply remove the screaming ERROR in all uppercase.

Yes screaming is generally bad but apart from that I think it makes sense to have multiple severities in logging.
E.g. other types of error that happen in DeserializeFileDB (say, specific de-serialization errors) might not be fatal but would ideally trigger someone to take a closer look.
Something @gmaxwell suggested once is to replace it with UNEXPECTED. c-lightning does this as well.

@jonatack
Copy link
Member Author

I think it makes sense to have multiple severities in logging.

I would like this indeed (and mention it in #20576).

@jnewbery
Copy link
Contributor

Concept ACK.

Maybe it would help to simply remove the screaming ERROR in all uppercase. It is not really a fatal error (if it was, the program should stop), but more like a debug statement.

Agree. It's not an error condition to start without peers.dat, anchors.dat or banlist.dat. I think we could probably resolve all three by just changing the log message?

@maflcko
Copy link
Member

maflcko commented Feb 15, 2021

I think we should be consistent in the way this is treated. Someone will create a pull in x months to fix this for banlist.dat, then for peers.dat in y months. So finally we have 5 different error messages for the same condition.

  • Failed to read fee estimates from {}. Continue anyway.
  • Failed to open mempool file from disk. Continuing anyway.
  • Could not find anchors file {}
  • Could not find asmap file {}
  • ... Another message for banlist and peers?

@jonatack
Copy link
Member Author

Then perhaps move this change into DeserializeFileDB()?

@jonatack
Copy link
Member Author

I think we should be consistent in the way this is treated. Someone will create a pull in x months to fix this for banlist.dat, then for peers.dat in y months.

ISTM this is what has been happening with moving the logging from debug to NET, one by one, and no one minded. Maybe I should stay away from logging 😄

@jonatack
Copy link
Member Author

To my surprise, this is controversial. I think it will have more success if someone else proposes it.

@jonatack jonatack closed this Feb 15, 2021
@maflcko
Copy link
Member

maflcko commented Feb 15, 2021

This has 4 Concept ACK and no NACK, so I don't think anyone sees this as controversial

@jnewbery
Copy link
Contributor

This is not at all controversial. I don't understand why this has been closed?

@michaelfolkson
Copy link

Concept ACK too

@jonatack
Copy link
Member Author

I don't understand the suggested changes. We can't fix this by updating the message in ReadAnchors(), it's in DeserializeFileDB(). We can't update that message without affecting the other callers. And suddenly we're talking about gathering consensus on aligning unrelated file messages that were never aligned before AFAIK, so a small fix turns into a wide change. I don't know why is that suddenly necessary (and didn't plan for that) in the context of a small fix.

@michaelfolkson
Copy link

michaelfolkson commented Feb 15, 2021

Keep the scope as limited as you want and provide some direction for others who might want to open additional PRs on top of this one?

It is ok (imo) to say "I see merit in that idea but I want to keep the scope of this PR limited. You are free to open PRs on top of this one if you want to widen the scope" or "I think what you are suggesting is too complicated. I would prefer to keep the scope of this PR limited to what it currently does."

@jonatack
Copy link
Member Author

Updated #20576 to be a general RFC on logging improvements and linked to some of the comments/ideas here.

@laanwj
Copy link
Member

laanwj commented Feb 15, 2021

To be clear I'm completely okay with this specific change my comment was only about possible future direction.

@jonatack
Copy link
Member Author

That is how I read it (thank you). Re-opening to respect the time people spent reviewing.

@jonatack jonatack reopened this Feb 15, 2021
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 8f51826

  • This PR is an improvement over master.
  • Yes, further improvements are possible, some of which may rewrite the change from this PR, but they do not exist yet and may never be created. So I think this PR should be closed without merge only if another PR exists which clearly supersedes it.

Comment on lines +170 to +173
if (!fs::exists(anchors_db_path)) {
LogPrintf("Could not find anchors file %s\n", anchors_db_path);
anchors.clear();
} else if (DeserializeFileDB(anchors_db_path, anchors)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a race here - the file may exist during the fs::exists check and be deleted after that and before DeserializeFileDB(). Of course this is irrelevant and ok in this case. I just can't stop myself from mentioning it. Apparently not everything I do is in my control, sorry.

Copy link
Member

@laanwj laanwj Feb 18, 2021

Choose a reason for hiding this comment

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

I had also noticed this but thought it wise not to comment 😄 (because the race doesn't affect anything but how the error is reported)
But yes if you want to be pedantic about it, it would be to make DeserializeFileDB return a distinguishable error condition when it could not find the anchors file and then log this message, instead of doing a separate check.

@maflcko
Copy link
Member

maflcko commented Feb 18, 2021

Obviously this pull is a fine improvement over master, but I am still not convinced that we need to create several back-and-forth patches to fix a trivial logging issue. Created #21222 as an alternative.

@jonatack
Copy link
Member Author

#21222 seems less helpful to users, but you're not happy with this and I'm not keen on having a competition. I was just trying to improve things for our users.

@jonatack jonatack closed this Feb 18, 2021
@jonatack jonatack deleted the log-message-instead-of-error-if-missing-anchors branch February 18, 2021 15:13
maflcko pushed a commit that referenced this pull request Feb 23, 2021
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to #21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 23, 2021
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to bitcoin#21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to bitcoin#21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2021
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to bitcoin#21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to bitcoin#21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 17, 2022
faf48f2 log: Clarify log message when file does not exist (MarcoFalke)

Pull request description:

  Shorter and broader alternative to bitcoin#21181

  Rendered diff:

  ```diff
  @@ -1,4 +1,4 @@
  -Bitcoin Core version v21.99.0-db656db2ed5a (release build)
  +Bitcoin Core version v21.99.0-faf48f20f196 (release build)
   Qt 5.15.2 (dynamic), plugin=wayland (dynamic)
   No static plugins.
   Style: adwaita / Adwaita::Style
  @@ -24,8 +24,8 @@ scheduler thread start
   Using wallet directory /tmp/test_001/regtest/wallets
   init message: Verifying wallet(s)...
   init message: Loading banlist...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/banlist.dat
  -Invalid or missing banlist.dat; recreating
  +Missing or invalid file /tmp/test_001/regtest/banlist.dat
  +Recreating banlist.dat
   SetNetworkActive: true
   Failed to read fee estimates from /tmp/test_001/regtest/fee_estimates.dat. Continue anyway.
   Using /16 prefix for IP bucketing
  @@ -63,9 +63,9 @@ Bound to [::]:18444
   Bound to 0.0.0.0:18444
   Bound to 127.0.0.1:18445
   init message: Loading P2P addresses...
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/peers.dat
  -Invalid or missing peers.dat; recreating
  -ERROR: DeserializeFileDB: Failed to open file /tmp/test_001/regtest/anchors.dat
  +Missing or invalid file /tmp/test_001/regtest/peers.dat
  +Recreating peers.dat
  +Missing or invalid file /tmp/test_001/regtest/anchors.dat
   0 block-relay-only anchors will be tried for connections.
   init message: Starting network threads...
   net thread start

ACKs for top commit:
  jnewbery:
    utACK faf48f2
  amitiuttarwar:
    utACK faf48f2, 👍 for consistency. also checked where we create / load other `.dat` files, looks good to me.
  practicalswift:
    cr ACK faf48f2

Tree-SHA512: 697a728ef2b9f203363ac00b03eaf23ddf80bee043ecd3719265a0d884e8cfe88cd39afe946c86ab849edd1c836f05ec51125f052bdc14fe184b84447567756f
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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.

10 participants