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

net: deprecate p2p message reject #883

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tynes
Copy link
Member

@tynes tynes commented Oct 16, 2019

This PR removes the RejectPacket from bcoin, following recent changes to bitcoind. I am not particularly opinionated on whether or not this gets merged, but am opening it up for discussion.

One thing that needs more investigation are the internal codes for reject packets as there is no test coverage for them.

The Pool will now call peer.increaseBan instead of calling peer.reject, which previously wrapper peer.increaseBan.

Part of the rationality of removing this packet was that it is not a recommended way to debug. If we do decide to remove the RejectPacket, then we should also be sure that logging is sufficient.

There is a case to be made about node diversity and supporting features that are not supported by bitcoind, regarding @pinheadmz's suggestion to couple them with whitebind.

Closes #880

@codecov-io
Copy link

codecov-io commented Oct 16, 2019

Codecov Report

Merging #883 into master will decrease coverage by 0.03%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #883      +/-   ##
==========================================
- Coverage   61.67%   61.63%   -0.04%     
==========================================
  Files         155      155              
  Lines       25976    25870     -106     
==========================================
- Hits        16021    15946      -75     
+ Misses       9955     9924      -31
Impacted Files Coverage Δ
lib/net/packets.js 77.49% <ø> (-0.46%) ⬇️
lib/net/peer.js 36.17% <ø> (-0.44%) ⬇️
lib/net/pool.js 31.73% <33.33%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b47913...7ccd0ff. Read the comment docs.

@braydonf
Copy link
Contributor

One thing the reject packet does is resolve the corresponding job, which absent the reject packet, will timeout instead.

@braydonf
Copy link
Contributor

braydonf commented Oct 16, 2019

Untested, LGTM. Code reads correct.

@braydonf braydonf added the net label Oct 16, 2019
@pinheadmz
Copy link
Member

One thing the reject packet does is resolve the corresponding job, which absent the reject packet, will timeout instead.

Where does that happen? We wait for a packet from a network peer to resolve a job?

const reject = packets.RejectPacket.fromReason(code, reason, msg, hash);

if (msg) {
this.logger.debug('Rejecting %s %h (%s): code=%s reason=%s.',
Copy link
Member

Choose a reason for hiding this comment

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

I think it's important that we continue to log reject reasons, even if we don't send the packets.

Copy link
Contributor

Choose a reason for hiding this comment

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

We may already be logging it internally, I'll check though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps increaseBan should log the reason, each time.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's important that we continue to log reject reasons, even if we don't send the packets.

I agree with this.

Perhaps increaseBan should log the reason, each time.

This seems like a smart place to log. I would like to know when my peers misbehave.

Copy link
Member Author

Choose a reason for hiding this comment

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

Except now that I think about it, that could be a DOS vector regarding a disk fill attack when too many loglines

Copy link
Contributor

Choose a reason for hiding this comment

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

Useful to consider, however it likely wouldn't be significant as at maximum it would be 100 lines, with increasing the score at 1 per time.

Copy link
Member Author

Choose a reason for hiding this comment

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

To allow for logging the reason, we would need to change the function signature of peer.increaseBan. Right now it just takes a ban score to add, the second argument could be a msg.

this.logger.info('Increasing banscore for %s by %d: %s', this.hostname(), score, msg);

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering about the DoS point, as there could be something there not considered.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe the logger should log on the debug level when logging about banscores. It would prevent possible attacks if we assume that production nodes should run with their logger on info

Copy link
Member

Choose a reason for hiding this comment

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

Default logger level is debug:

bcoin/bin/node

Line 30 in f991b0a

logLevel: 'debug',

@braydonf
Copy link
Contributor

In handleReject of BroadcastItem in lib/net/pool.js:

  handleReject(peer) {
    this.emit('reject', peer);

    for (const job of this.jobs)
      job.resolve(false);

    this.jobs.length = 0;
  }

Resolve in this case is the Promise resolve method for the broadcast.

@braydonf braydonf added this to the v3.0.0 milestone Jan 7, 2020
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.

Removal of reject P2P messages
4 participants