Skip to content

log: Move validation option logging to LoadChainstate() - #25951

Merged
maflcko merged 2 commits into
bitcoin:masterfrom
maflcko:2208-log-val-🚣
Sep 1, 2022

Hidden character warning

The head ref may contain hidden characters: "2208-log-val-\ud83d\udea3"
Merged

maflcko merged 2 commits into
bitcoin:masterfrom
maflcko:2208-log-val-🚣

Conversation

@maflcko

@maflcko maflcko commented Aug 29, 2022

Copy link
Copy Markdown
Member

This would allow libbitcoinkernel users to see the options logged as well. Currently they would only be logged for bitcoind. Behavior change suggested in the refactoring pull #25704 (comment)

@maflcko

maflcko commented Aug 29, 2022

Copy link
Copy Markdown
Member Author

One way to test this is to modify bitcoin-chainstate a bit:

diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp
index 7312ae45d4..4ec71ca3fb 100644
--- a/src/bitcoin-chainstate.cpp
+++ b/src/bitcoin-chainstate.cpp
@@ -53,6 +53,10 @@ int main(int argc, char* argv[])
     // SETUP: Misc Globals
     SelectParams(CBaseChainParams::MAIN);
     const CChainParams& chainparams = Params();
+LogInstance().m_print_to_console=true;
+LogInstance().m_file_path = AbsPathForConfigVal("log_debug");
+LogInstance().m_log_timestamps = false;
+Assert(LogInstance().StartLogging());
 
     kernel::Context kernel_context{};
     // We can't use a goto here, but we can use an assert since none of the

Command to test:

make && ./src/bitcoin-chainstate /tmp/temp_dd

Output diff:

@@ -3,6 +3,9 @@ Using RdSeed as an additional entropy source
 Using RdRand as an additional entropy source
 Using 16 MiB out of 16 MiB requested for signature cache, able to store 524288 elements
 Using 16 MiB out of 16 MiB requested for script execution cache, able to store 524288 elements
+Validating signatures for all blocks.
+Setting nMinimumChainWork=0000000000000000000000000000000000000000000000000000000000000000
+Warning: nMinimumChainWork set below default value of 00000000000000000000000000000000000000002927cdceccbd5209e81e80db
 Switching active chainstate to Chainstate [ibd] @ height -1 (null)
 Opening LevelDB in /tmp/temp_dd/blocks/index
 scheduler thread start

@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:

  • #25704 (refactor: Remove almost all validation option globals by MarcoFalke)

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.

@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.

Code review ACK fa3358b. This should simplify #25704 a little.

One suggestion: It might also be good to move the pruning log prints immediately below to simplify #25781

@jonatack

Copy link
Copy Markdown
Member

Concept ACK

@fanquake
fanquake requested a review from theuni August 31, 2022 19:26
@jonatack

jonatack commented Sep 1, 2022

Copy link
Copy Markdown
Member

ACK fa3358b

Tested and it works with bitcoin-chainstate as described in #25951 (comment).

Note that this pull also changes the placement of this logging from the top

2022-08-31T20:05:35Z Bitcoin Core version v23.99.0-7c7c71500403-dirty (debug build)
2022-08-31T20:05:35Z Assuming ancestors of block 000000000000000000052d314a259755ca65944e68df6b12a067ea8f1f5a7091 have valid signatures.
2022-08-31T20:05:35Z Setting nMinimumChainWork=00000000000000000000000000000000000000002927cdceccbd5209e81e80db

to a bit further down after the asmap, "Loading P2P addresses…" and "Cache configuration" sections into the "init message: Loading block index…" one, which seems ok

...
2022-09-01T12:08:23Z Using BerkeleyDB version ...
2022-09-01T12:08:23Z Using wallet ...
2022-09-01T12:08:23Z BerkeleyEnvironment::Open: LogDir=
2022-09-01T12:08:23Z Opened asmap file (1219959 bytes) from disk
2022-09-01T12:08:25Z Using asmap version  for IP bucketing
2022-09-01T12:08:25Z init message: Loading P2P addresses…
2022-09-01T12:08:27Z Loaded 75260 addresses from peers.dat  2853ms
2022-09-01T12:08:27Z init message: Loading banlist…
2022-09-01T12:08:27Z SetNetworkActive: true
2022-09-01T12:08:27Z Cache configuration:
...
2022-09-01T12:08:27Z init message: Loading block index…
2022-09-01T12:08:27Z Assuming ancestors of block 000000000000000000052d314a259755ca65944e68df6b12a067ea8f1f5a7091 have valid signatures.
2022-09-01T12:08:27Z Setting nMinimumChainWork=00000000000000000000000000000000000000002927cdceccbd5209e81e80db

@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.

Code review ACK fa4c59d. Only change since last review is moving pruning logprints out of AppInitParameterInteraction as suggested

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review ACK fa4c59d

@maflcko
maflcko merged commit 36e1b52 into bitcoin:master Sep 1, 2022
@maflcko
maflcko deleted the 2208-log-val-🚣 branch September 2, 2022 11:58
@theuni

theuni commented Sep 6, 2022

Copy link
Copy Markdown
Member

I kinda would've expected the opposite here, where statuses are returned and the caller (bitcoin-chainstate) can choose to report them as necessary.

I've probably missed discussions about logging though. Is the plan to have an instantiated logger in the future so that the caller can control the output?

@maflcko

maflcko commented Sep 6, 2022

Copy link
Copy Markdown
Member Author

InitializeChainstate already calls LogPrintf, so all LogPrintf (old and new) can be switched to something else once it is clear what that is. I am not sure myself what the plan here is.

@ryanofsky

Copy link
Copy Markdown
Contributor

I think log prints are useful whether you are calling a library or running a daemon, so it shouldn't be a goal to strip them out.

I lost track of the different branches Carl sent (https://github.com/dongcarl/bitcoin/commits/2022-03-kirby-p2.5, etc) but I think all of them kept a global logger object. The global object could be fully or partially replaced with locals if it is a problem.

@bitcoin bitcoin locked and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants