stratisproject / StratisBitcoinFullNode

Bitcoin full node in C#
https://stratisplatform.com
MIT License
787 stars 315 forks source link

Fix the node blocking inbounds after an inordinate amount of disconnects due to a peer being banned #4119

Closed fassadlr closed 4 years ago

fassadlr commented 4 years ago

This fixes a long standing issue whereby the node would stop receiving inbound connections.

The bug is that we add the connected peer to the network peer disposer after it has been disconnected because of a ban. The result is that the connected peers collection in the network peer disposer constantly increases as we never have the peer in the collection by the time the other node has disconnected it due to a ban. Eventually the max inbound count is reached and the node stops incoming connections here:

            if (this.networkPeerDisposer.ConnectedInboundPeersCount >= this.connectionManagerSettings.MaxInboundConnections)
            {
                this.logger.LogTrace("(-)[MAX_CONNECTION_THRESHOLD_REACHED]:false");
                return (false, $"Inbound Refused: Max Inbound Connection Threshold Reached, inbounds: {this.networkPeerDisposer.ConnectedInboundPeersCount}");
            }

It has been decided that to fix the race condition is unnecessary as we shouldn't even be allowing the inbound when it is banned.

dev0tion commented 4 years ago

Hurray!

Gabriel-x42 commented 4 years ago

Thank you so much!