-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Move the blocknotify callback ahead of peer announcement. #7037
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
Conversation
Wizkid057 reported getbestblockhash polling was frequently beating blocknotify, sometimes by 2 seconds. Under the theory that getting cs_vNodes and running running PushInventory for all peers was sometimes taking a while or UpdatedBlockTip (see below), I suggested moving up the notify. He reported doing so made it consistently faster. I think it's reasonable to signal blocknotify first: All it does is fire off a new thread, so it should never block. This does not move up GetMainSignals().UpdatedBlockTip() which because that signal includes the wallet, and if there is a wallet with many keys the wallet processing of a block can be quite slow. Unfortunately, it also sends out the ZMQ notify.
|
utACK |
|
It's strange to have the same notification in two different moments. Can we make the inventory relay asynchronous and as a slot connected to In other words, I don't see these kind of |
|
I agree that it's strange to have notifications effectively three times, but I think we should wait to refactor until after #6494, which is tagged for 0.12. Also I'd be surprised if it turns out the p2p block relay operations are slow, but I haven't timed yet; I'll do some analysis. Anyway what's the reasoning behind having two different notification systems ( |
|
@sdaftuar One was historically for the wallet and the other for the GUI, but I don't think there is any reason to keep both now. |
|
Don't forget cvBlockChange which is what lets getblocktemplate know the tip has changed and is called on every block connected or disconnected. I haven't thought about it until just now, but does it make sense to be calling that inside of ActivateBestChainStep? I guess it won't be able to do anything until ActivateBestChainStep releases cs_main, at which point it may have received several notifications in a reorg. |
|
@sdaftuar it would be great to have that analysis. Still, any slot connected to |
|
@promag They're not in different moments, there is a sequence of things that get notified. And this patch moves the last to the first because when present it's often the most latency critical and it won't block. This is sufficient to make blocknotify faster. When the wallet fires is not latency critical. Fortunately they already use different mechanisms, so it was easy to order them. |
|
The discussion above leaves me dangling. I think we should do this because its a simple and effectively free performance improvement... that it wouldn't be possible if everything were using the same signals, is IMO just an example of the limitations in that particular approach; but while we do, we should take the benefit available. |
|
utACK. Won't hurt. |
|
I don't care about having two signals. I do think the zmq notify should use this as well. Having the old launch-a-process have less latency than zmq, which we supposedly added to have a lower latency notification mechanism, just isn't acceptable :) (especially if we're talking about seconds here) |
|
AFAICT ZMQ and the wallet ride on the same notification, and there appears to be no way to control what order they execute in. Suggestions? |
|
Needs rebase |
|
IMO we should remove |
|
Agreed with @jonasschnelli, but that will require a larger code change... |
For this to work, no signal handlers should be executing anything expensive. The problem is that the wallet does this, resulting in the problem that this pull tries to mitigate. That should be solved first. |
|
This is possibly an issue if wallet-based services use this signal to trigger wallet RPCs, as those may complete before the wallet was notified about the change. |
|
@sipa then perhaps the wallet should have a 'block' notification of its own, as, conceptually, that is what you're saying. (Users are waiting on both the new block notification AND the wallet notification of having recognised that block, not the wallet 'receiving' the block notification itself) |
Yes, a ProcessedBlock signal on wallet would make sense (if there's any users for that? most wallet users care about transactions, not blocks), as handling becomes more asynchronous it's no longer possible to rely on the fact that core signals mean that anything wallet (or other subsystem) related has happened. |
|
An equivalent change was merged in #7112. This should be closed. |
|
We should still think about consolidating the signals to avoid these issues in future. Probably low priority at the moment though. |
Wizkid057 reported getbestblockhash polling was frequently beating
blocknotify, sometimes by 2 seconds. Under the theory that getting
cs_vNodes and running running PushInventory for all peers was
sometimes taking a while or UpdatedBlockTip (see below), I
suggested moving up the notify. He reported doing so made it
consistently faster.
I think it's reasonable to signal blocknotify first: All it does
is fire off a new thread, so it should never block.
This does not move up GetMainSignals().UpdatedBlockTip() which
because that signal includes the wallet, and if there is a
wallet with many keys the wallet processing of a block can
be quite slow. Unfortunately, it also sends out the ZMQ notify.