build(p2p): internalize libp2p as local module#6673
Open
barbatos2011 wants to merge 7 commits intotronprotocol:developfrom
Open
build(p2p): internalize libp2p as local module#6673barbatos2011 wants to merge 7 commits intotronprotocol:developfrom
barbatos2011 wants to merge 7 commits intotronprotocol:developfrom
Conversation
added 6 commits
April 10, 2026 22:56
Copy source code from tronprotocol/libp2p v2.2.7 into a new p2p/ gradle submodule. This commit introduces the original source without modifications, preserving the org.tron.p2p package structure. - Add p2p/build.gradle with protobuf plugin and dependency declarations - Add p2p/lombok.config to override root lombok field name (log vs logger) - Move example code (StartApp) to src/test/java - Proto generated code is not committed (built by protobuf plugin) - Update gradle/verification-metadata.xml for new dependencies
Replace all @Slf4j-generated 'log' references with 'logger' to match java-tron's lombok.config (lombok.log.fieldName=logger). Remove the temporary p2p/lombok.config override added in the previous commit. Checkstyle is not yet enabled for the p2p module due to ~1900 violations inherited from the original libp2p codebase. This will be addressed in a follow-up PR.
Replace the Maven dependency on io.github.tronprotocol:libp2p:2.2.7 with a project dependency on the local :p2p module. This eliminates 11 exclude rules that were needed for the external artifact and removes the libp2p entry from dependency verification metadata. java-tron no longer depends on any external libp2p artifact.
Apply google-java-format for bulk formatting (indentation, imports, whitespace), then fix remaining violations manually: - Lambda indentation adjustments for checkstyle 8.7 compatibility - Line length wrapping for long strings and license headers - Empty catch blocks: add // expected comments - Star import replacement, multiple variable declaration splits Enable checkstyle plugin in p2p/build.gradle with proto-generated code excluded. Both checkstyleMain and checkstyleTest now pass.
- Replace BasicThreadFactory.builder() with new BasicThreadFactory.Builder() to use commons-lang3 3.4-compatible API, preventing implicit global version upgrade from 3.4 to 3.18.0 - Remove unused grpc-core dependency (p2p protos define only messages, no gRPC services); retain grpc-netty as Netty transport provider - Add p2p/.gitignore to exclude proto-generated code for all developers - Update verification-metadata.xml for changed dependency tree
- Replace Math.min/max with StrictMath.min/max in NodeEntry and NodeTable to satisfy CI check-math rule (integer operations, results are identical) - Rewrite NetUtilTest.testGetIP with mocked URLConnection instead of calling external IP services (checkip.amazonaws.com, ifconfig.me), covering: valid IP, connection failure, invalid IP, empty response - Remove testExternalIp (covered by mock tests) - Fix testGetLanIP to not depend on www.baidu.com connectivity
Add comprehensive unit tests to meet CI coverage gate requirements (changed files > 60%, overall delta < -0.1%). New test files (27): - connection/: Channel, ChannelManager, HandshakeService, KeepAlive, NodeDetect, ConnPoolService, UpgradeController, P2pProtobufDecoder, MessageHandler, PeerClient, P2pChannelInitializer, StatusMessage, P2pDisconnectMessage - dns/: DnsManager, AliClient, AwsClient, PublishService - discover/: FindNodeMessage, NeighborsMessage, Message, PacketDecoder, MessageHandler, DiscoverTask - utils/web3j: Numeric, Strings, Hash, ECKeyPair - stats: StatsManager - exception: DnsException - P2pService, P2pConfig Exclude proto-generated code from jacoco coverage calculation (consistent with checkstyle exclusion).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Internalize
io.github.tronprotocol:libp2p:2.2.7source code as a newp2p/gradle submodule, replacing the external Maven dependency. No functional changes to P2P behavior, protocol, or consensus.Why
The external libp2p repository had a 2.5-year development gap (2023.3 ~ 2025.10). Cross-repo maintenance creates friction:
p2p/package within the monorepo; this follows the same patternChanges
Commit 1:
chore(p2p): add libp2p v2.2.7 source as p2p moduleorg.web3jcrypto utils) + 2 proto files + 26 test files fromtronprotocol/libp2ptagv2.2.7p2p/build.gradlewith protobuf plugin configurationp2p/lombok.configto temporarily override root logger field name (logvslogger)StartApp) tosrc/test/java(not packaged in JAR, but available for reference)settings.gradle, updategradle/verification-metadata.xmlCommit 2:
style(p2p): replace log field with logger@Slf4j-generatedlogreferences withlogger(35 files) to match rootlombok.config(lombok.log.fieldName=logger)p2p/lombok.configoverrideCommit 3:
build(common): switch from external libp2p to local p2p modulecommon/build.gradle: replace 17 lines (Maven dependency + 11 exclude rules) with singleapi project(':p2p')io.github.tronprotocol:libp2p:2.2.7entry fromgradle/verification-metadata.xmlCommit 4:
style(p2p): fix checkstyle violations and enable checkstylegoogle-java-formatfor bulk formatting (indentation, imports, whitespace)exclude '**/protos/**')Commit 5:
fix(p2p): address review findingsBasicThreadFactory.builder()(requires commons-lang3 3.12+) withnew BasicThreadFactory.Builder()(available since 3.0) to prevent implicit global version upgrade from 3.4 to 3.18.0grpc-coredependency; retaingrpc-nettyas Netty transport provider (p2p uses 30+ Netty imports for TCP/UDP but zero gRPC imports)p2p/.gitignoreto exclude proto-generated code for all developersCommit 6:
fix(p2p): replace Math with StrictMath and fix flaky network testsMath.min/maxwithStrictMath.min/maxin 5 files to satisfy CIcheck-mathrule (integer operations, results identical)NetUtilTest.testGetIPwith mockedURLConnection— original test called 3 external IP services which failed in CI (libp2p's own CI never ran tests with-xtest)testExternalIp(covered by mock tests), fixtestGetLanIPto not depend on external connectivityKey Design Decisions
p2porg.tron.p2p, gethp2p/convention, project short-name style (common,crypto, etc.)protocol/; avoids couplingsrc/test/javabuilder()→new Builder()(3.0 API) instead of upgrading globallyservicedefinitions, zeroio.grpcimports in source**/protos/**Math→StrictMathcheck-mathrule; integer min/max results are identicaltestGetIPmock rewriteScope
org.tron.p2pare unchanged (package name preserved)git pulland rebuildKnown Issues (pre-existing in libp2p)
The following issues exist in the original libp2p v2.2.7 codebase and are NOT introduced by this PR. They will be addressed in follow-up PRs:
Critical:
java.util.Randominstead ofSecureRandom) — eclipse attack vectorHigh:
ChannelManager.handMessage(double onConnect)java.util.RandomAlgorithm.compressPubKeydrops leading zeros from public key X-coordinateMedium (from Cubic AI review):
Node.equalscompares byte[] vianew String(id)instead ofArrays.equalsChannel.hashCode()NPE wheninetSocketAddressis nullInterruptedExceptionswallowed in DiscoverServer and PeerClientTest
checkstyleMain+checkstyleTest: PASS for all modules including p2pcheck-math: PASS