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

feat(core-p2p): Validate GET replies from other peers #2102

Merged
merged 12 commits into from
Feb 22, 2019

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Feb 14, 2019

Proposed changes

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build (changes that affect the build system)
  • Docs (documentation only changes)
  • Test (adding missing tests or fixing existing tests)
  • Other... Please describe:

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@ghost
Copy link

ghost commented Feb 14, 2019

@air1one @faustbrian @supaiku0 - please review this in the next few days. Be sure to explicitly select labels so I know what's going on.

If no reviewer appears after a week, a reminder will be sent out.

@ghost ghost requested a review from air1one February 14, 2019 17:46
@ghost
Copy link

ghost commented Feb 14, 2019

@vasild The ci/circleci: test-node11-2 job is failing as of 94761b29e288c4c1a6e4dfed652219d7cf64516b. Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@faustbrian
Copy link
Contributor

This is a breaking change in how the legacy P2P API responds, some people still rely on it so that is a no go. This is a change that will be made for websockets.

@vasild
Copy link
Contributor Author

vasild commented Feb 15, 2019

This is a breaking change in how the legacy P2P API responds, some people still rely on it so that is a no go. This is a change that will be made for websockets.

We agreed that I add a schema validation as a followup PR after #2032:
#2032 (comment)
#2032 (comment)

Now, should I relax the validation so that it allows "legacy P2P API" replies, or completely ditch this PR
@supaiku0, @kristjank?

@vasild
Copy link
Contributor Author

vasild commented Feb 15, 2019

By the way I get the following with this patch:

[ERROR]: Got unexpected reply from http://137.74.237.196:4002/peer/list: {"peers":[{...},{"ip":"2130706433",...}: child "peers" fails because ["peers" at position 1 fails because [child "ip" fails because ["ip" must be a valid ip address with a forbidden CIDR]]]

and the node keeps working by fetching the peer list from another peer. This looks like a good way to get rid of the IP addresses like "2130706433" with which devnet is poisoned.

@faustbrian
Copy link
Contributor

If you change it so that the responses don't change we can keep it open, otherwise I would wait until 2.6 with it and talk to @air1one as he currently is working on the websockets.

@vasild
Copy link
Contributor Author

vasild commented Feb 18, 2019

If you change it so that the responses don't change we can keep it open, otherwise I would wait until 2.6 with it and talk to @air1one as he currently is working on the websockets.

Yes, sure. The idea was never to change the responses. The idea is to check that the responses are the expected ones. So, I guess, the rules should be relaxed. @air1one how would this fit with websockets? I guess with websockets we still send JSONs back and forth, right? So the validation is still relevant, no matter whether we received the reply via HTTP or websockets.

@faustbrian
Copy link
Contributor

@vasild try to finish this until the end of the week so we can put it on devnet and freeze the develop branch for the 2.2 release.

@codecov-io
Copy link

codecov-io commented Feb 22, 2019

Codecov Report

Merging #2102 into develop will decrease coverage by 0.06%.
The diff coverage is 90.62%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2102      +/-   ##
===========================================
- Coverage    79.55%   79.48%   -0.07%     
===========================================
  Files          329      330       +1     
  Lines         7900     7913      +13     
  Branches      1123     1114       -9     
===========================================
+ Hits          6285     6290       +5     
- Misses        1582     1590       +8     
  Partials        33       33
Impacted Files Coverage Δ
packages/core-p2p/src/peer-verifier.ts 85.61% <100%> (-1.35%) ⬇️
packages/core-p2p/src/reply-schemas.ts 100% <100%> (ø)
packages/core-p2p/src/peer.ts 85% <89.65%> (+0.78%) ⬆️
packages/core-p2p/src/errors.ts 36.36% <0%> (-45.46%) ⬇️

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 c7be0cf...b4f1d2e. Read the comment docs.

@vasild vasild added this to the 2.2.0 milestone Feb 22, 2019
import util from "util";
import { config as localConfig } from "./config";
import { PeerPingTimeoutError, PeerStatusResponseError, PeerVerificationFailedError } from "./errors";
import { PeerVerificationResult, PeerVerifier } from "./peer-verifier";

export class Peer implements P2P.IPeer {
private static replySchemas: any = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move the schemas into a separate file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in abb0242.

vasild and others added 3 commits February 22, 2019 15:27
…ply-validation

* ArkEcosystem/core/develop:
  chore(release): 2.2.0-beta.6 (#2136)
  refactor(core-container): throw an error if the peers or plugins file are missing (#2135)
@spkjp spkjp self-requested a review February 22, 2019 16:33
…ply-validation

* ArkEcosystem/core/develop:
  chore(release): 2.2.0-beta.7 (#2141)
@vasild vasild merged commit bbca40c into develop Feb 22, 2019
@ghost ghost deleted the peer-reply-validation branch February 22, 2019 16:54
@ghost ghost removed the Status: Needs Review label Feb 22, 2019
vasild added a commit that referenced this pull request Feb 27, 2019
* ArkEcosystem/core/2.3:
  chore: move core-graphql to the deprecated folder (#2169)
  refactor(crypto): benchmarks (#2167)
  refactor: replace micromatch with nanomatch and remove heavy deps (#2165)
  feat(crypto): increase vendor field length to 255 bytes (#2159)
  feat(core-api): search delegates by usernames (#2143)
  feat(core-logger-pino): initial implementation (#2134)
  perf(crypto): integrate bcrypto (#2158)
  feat(core): ask for process restarts after updating (#2155)
  refactor(core): replace pm2 with process manager (#2154)
  refactor(core): require the user to take action for updates (#2153)
  feat(core-p2p): Fetch list of peers from at least a few others (#2152)
  refactor(core): more robust check for ensureDefaults (#2151)
  fix(core): ensure file and defaults before reading
  fix(core): return correct suffix for core:restart command (#2150)
  fix(core-database): properly sort BigNumber values (#2144)
  feat(core): configuration and channel support for the CLI (#2145)
  feat(core): merge core-snapshot-cli commands into core (#2149)
  fix(core-api): pass query to findAllByVote method (#2142)
  feat(core-p2p): Validate GET replies from other peers (#2102)
  chore(release): 2.2.0-beta.7 (#2141)
  fix(core-blockchain): stuck at not ready to accept new block (#2139)
  refactor(core-p2p): Improve selection of peer for downloading blocks (#2137)
  fix(core): overwrite the config path if an env variable is provided (#2140)
  fix(core): do not ignore the network flag in parseWithNetwork (#2138)
  chore(release): 2.2.0-beta.6 (#2136)
  refactor(core-container): throw an error if the peers or plugins file are missing (#2135)
  chore(release): 2.2.0-beta.5 (#2132)
  refactor(core-p2p):  reduce logging noise (#2129)
  misc(core-p2p): remove superfluous log message (#2128)
  refactor(core-p2p): Improve fork handling in updatePeersOnMissingBlocks (#2125)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants