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

SpecificNodeBlockProvider: Modify handshake warning logging #12949

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Apr 29, 2024

Fixes #11184

This PR is basically just what @turbolay suggested here.

Testing

  1. Run WW with your bitcoin node already started. No warning should be reported.
  2. Run WW with your bitcoin node stopped and then start your bitcoin node. A single warning should be produced.
  3. The same as 2 but start and stop your bitcoin node while WW is running.

@@ -110,7 +115,8 @@ private async Task ReconnectingLoopAsync()
}
catch (Exception ex)
{
if (ex is OperationCanceledException && connectCts.Token.IsCancellationRequested)
Copy link
Collaborator Author

@kiminuo kiminuo Apr 29, 2024

Choose a reason for hiding this comment

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

I believe that connectCts.Token.IsCancellationRequested should not be here as that looks like a bug to me. I replaced it with !shutdownToken.IsCancellationRequested as that makes more sense to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right it looks like it made no sense

@kiminuo kiminuo force-pushed the feature/2024-04-29-SpecificNodeBlockProvider-log-better branch from bf7ded4 to 42e9db2 Compare April 29, 2024 12:41
@kiminuo kiminuo force-pushed the feature/2024-04-29-SpecificNodeBlockProvider-log-better branch from 42e9db2 to f7aee44 Compare April 29, 2024 19:56
@kiminuo kiminuo changed the title SpecificNodeBlockProvider: Log warning only the first time or after a successful connection SpecificNodeBlockProvider: Modify handshake warning logging Apr 29, 2024
@@ -110,14 +116,17 @@ private async Task ReconnectingLoopAsync()
}
catch (Exception ex)
{
if (ex is OperationCanceledException && connectCts.Token.IsCancellationRequested)
// In general, we do do not log a message if we fail to connect to the bitcoin core endpoint. The only exception is when a handshake error occurs.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is current behavior. I find it it weird though. I would expect that we log once that we cannot log to the specified bitcoin node (i.e. to log when SocketException is thrown`).

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are logging, simply in Trace. We could move to Warning and extend logWarningOnHandshakeError to any type of exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are logging, simply in Trace.

Ah, I see now.

We are logging, simply in Trace. We could move to Warning and extend logWarningOnHandshakeError to any type of exception.

Do you want me to change it in this PR or is like an idea?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can do it in a subsequent PR

if (ex is OperationCanceledException && connectCts.Token.IsCancellationRequested)
// In general, we do do not log a message if we fail to connect to the bitcoin core endpoint. The only exception is when a handshake error occurs.
// If we are not shutting down the application and if this is not a repeated-handshake failure, then log a warning.
if (ex is OperationCanceledException && !shutdownToken.IsCancellationRequested && logWarningOnHandshakeError)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Catching OperationCanceledException seems like it's some sort of workaround, I tried to modify requirements of the local node (I required a nonsense witness version) and this warning was not shown.

So I'm not too sure how we ended up with this condition.

@kiminuo kiminuo marked this pull request as ready for review April 29, 2024 20:12
@kiminuo kiminuo requested a review from turbolay April 29, 2024 20:12
@kiminuo kiminuo requested a review from adamPetho May 9, 2024 06:17
adamPetho
adamPetho previously approved these changes May 9, 2024
Copy link
Collaborator

@adamPetho adamPetho left a comment

Choose a reason for hiding this comment

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

I don't get a full node, so I can't test it, but code changes LGTM

WalletWasabi/Wallets/SpecificNodeBlockProvider.cs Outdated Show resolved Hide resolved
@kiminuo
Copy link
Collaborator Author

kiminuo commented May 9, 2024

I don't get a full node, so I can't test it, but code changes LGTM

You can test it with a RegTest node as well. That's what I did.

Co-authored-by: adamPetho <45069029+adamPetho@users.noreply.github.com>
@adamPetho
Copy link
Collaborator

Wasabi + backend + Knots are running, everything is fine.
Then I kill Knots, but the exception is SocketException all the time.

I couldn't manage to get this warning log Wasabi could not complete the handshake with the node....
Anything specific I should do while testing this? I tried to follow your description.

  1. Works fine
  2. & 3. SocketExceptions

@kiminuo
Copy link
Collaborator Author

kiminuo commented May 9, 2024

Wasabi + backend + Knots are running, everything is fine. Then I kill Knots, but the exception is SocketException all the time.

I couldn't manage to get this warning log Wasabi could not complete the handshake with the node.... Anything specific I should do while testing this? I tried to follow your description.

1. Works fine

2. & 3. SocketExceptions

It sounds like this: https://github.com/zkSNACKs/WalletWasabi/pull/12949/files#r1583684668

adamPetho
adamPetho previously approved these changes May 9, 2024
Copy link
Collaborator

@adamPetho adamPetho left a comment

Choose a reason for hiding this comment

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

t(rust)ACK, I wasn't able to repro the original issue. Code still LGTM

@@ -156,6 +165,9 @@ private async Task ReconnectingLoopAsync()
}
}

/// <exception cref="SocketException">When connecting to the node fails.</exception>
/// <exception cref="OperationCanceledException">When handshake protocol with the node fails.</exception>
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to your previous comment, isn't this statement incorrect?

Copy link
Collaborator Author

@kiminuo kiminuo May 9, 2024

Choose a reason for hiding this comment

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

I have removed that line. I've been looking into NBitcoin and its Node.VersionHandshake and it throws InvalidOperationException in multiple scenarios. But it's a mess because NBitcoin is such a sh* library (Try* methods throw, convert one exception to another one, etc.).

How exactly it throws OperationCanceledException, I don't know.

Copy link
Collaborator Author

@kiminuo kiminuo May 9, 2024

Choose a reason for hiding this comment

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

My best guess is that this:

https://github.com/MetacoSA/NBitcoin/blob/583e33b038e6e04c9c87d9aee0b553b00d74d7a0/NBitcoin/Protocol/NodeListener.cs#L51

can throw an OCE and then the scenario is: You send a handshake and you don't get a response (which can presumably happen if you are starting Bitcoin Core and it is not fully initialized).

But like who knows. NBitcoin has been written in an adhoc way so it's hard to say what's intentional and what is a bug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I see the problem... I will make a new PR to log in all cases, just waiting for CI

@kiminuo kiminuo merged commit 925ef8e into WalletWasabi:master May 9, 2024
5 of 8 checks passed
@kiminuo kiminuo deleted the feature/2024-04-29-SpecificNodeBlockProvider-log-better branch May 9, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't try to connect to a non-existing full node
3 participants