vechain / thor

A general purpose blockchain highly compatible with Ethereum's ecosystem
GNU Lesser General Public License v3.0
795 stars 248 forks source link

Cleanup p2p thor + add tests #724

Closed otherview closed 1 month ago

otherview commented 2 months ago

Description

Connected with https://github.com/vechain/protocol-board-repo/issues/165 . It was hard to follow the expected behaviour when combining (allowed-peers, bootnodes, and stored cached peers). This was mainly due to the use of flag value retrieval, directory setup, and a few other operations being mixed with the flag operation behaviour. The PR decouples the setup of data and directories from the flag combination logic. It was also very hard to test. This PR does a bit of refactoring around the p2pcom and makes it more testable. The logic now works as follows:

This PR also introduces a test/datagen package that makes it easier to generate randomized data.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Checklist:

codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 43.51852% with 61 lines in your changes are missing coverage. Please review.

Project coverage is 61.91%. Comparing base (aedfc6b) to head (1115d76). Report is 1 commits behind head on master.

Files Patch % Lines
cmd/thor/utils.go 0.00% 29 Missing :warning:
cmd/thor/p2p/p2p.go 60.34% 23 Missing :warning:
p2psrv/server.go 16.66% 5 Missing :warning:
cmd/thor/main.go 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #724 +/- ## ========================================== + Coverage 61.77% 61.91% +0.14% ========================================== Files 195 199 +4 Lines 18246 18309 +63 ========================================== + Hits 11271 11336 +65 + Misses 5876 5871 -5 - Partials 1099 1102 +3 ```

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