near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.32k stars 623 forks source link

[network] Allow some network messages to be sent to self #12022

Closed shreyan-gupta closed 1 month ago

shreyan-gupta commented 2 months ago

This PR builds the basis to enable the network layer to redirect network messages to self.

Currently, any network message that is sent to self, i.e. sent to our own account id, is dropped. This can lead to some complications in the logic of dealing with sending chunk endorsement and partial witness messages.

For example, we send the chunk endorsement to the next 5 block producers, but since messages to self are dropped, we need to special case in to check if we are the block producer and handle that case separately.

For partial witness, we need to be careful about managing parts for which we are the owner, i.e. bypass the PartialEncodedStateWitnessMessage message and directly send PartialEncodedStateWitnessForwardMessage.

In subsequent PRs, we would remove these special cases.

Changes

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 56.31068% with 45 lines in your changes missing coverage. Please review.

Project coverage is 71.51%. Comparing base (541c84a) to head (4c12d11). Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...hain/network/src/peer_manager/network_state/mod.rs 59.18% 40 Missing :warning:
chain/network/src/network_protocol/mod.rs 0.00% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #12022 +/- ## ========================================== - Coverage 71.54% 71.51% -0.04% ========================================== Files 815 814 -1 Lines 164661 164525 -136 Branches 164661 164525 -136 ========================================== - Hits 117808 117660 -148 - Misses 41685 41697 +12 Partials 5168 5168 ``` | [Flag](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | Coverage Δ | | |---|---|---| | [backward-compatibility](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.17% <0.00%> (-0.06%)` | :arrow_down: | | [db-migration](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.17% <0.00%> (-0.06%)` | :arrow_down: | | [genesis-check](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.28% <0.00%> (-0.06%)` | :arrow_down: | | [integration-tests](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `38.59% <40.77%> (+0.07%)` | :arrow_up: | | [linux](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.19% <53.39%> (-0.04%)` | :arrow_down: | | [linux-nightly](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.10% <52.42%> (-0.01%)` | :arrow_down: | | [macos](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `54.04% <0.00%> (+1.41%)` | :arrow_up: | | [pytests](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.54% <0.00%> (-0.06%)` | :arrow_down: | | [sanity-checks](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.34% <0.00%> (-0.06%)` | :arrow_down: | | [unittests](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `65.39% <31.06%> (-0.11%)` | :arrow_down: | | [upgradability](https://app.codecov.io/gh/near/nearcore/pull/12022/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.21% <0.00%> (-0.06%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.