-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(api): incorrect field mappings in GRPC GetStatsInfo and GetNodeInfo #6930
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
Open
xxo1shine
wants to merge
1
commit into
tronprotocol:develop
Choose a base branch
from
xxo1shine:fix/node-info-metrics-field-mapping
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
58 changes: 58 additions & 0 deletions
58
common/src/test/java/org/tron/common/entity/NodeInfoTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.tron.common.entity; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.tron.protos.Protocol; | ||
|
|
||
| public class NodeInfoTest { | ||
|
|
||
| private PeerInfo newPeerInfo(boolean syncFlag, boolean needSyncFromPeer, | ||
| boolean needSyncFromUs) { | ||
| PeerInfo peerInfo = new PeerInfo(); | ||
| peerInfo.setSyncFlag(syncFlag); | ||
| peerInfo.setNeedSyncFromPeer(needSyncFromPeer); | ||
| peerInfo.setNeedSyncFromUs(needSyncFromUs); | ||
| // string fields must be non-null, otherwise the protobuf setters throw NPE | ||
| peerInfo.setLastSyncBlock(""); | ||
| peerInfo.setHost("127.0.0.1"); | ||
| peerInfo.setNodeId(""); | ||
| peerInfo.setHeadBlockWeBothHave(""); | ||
| peerInfo.setLocalDisconnectReason(""); | ||
| peerInfo.setRemoteDisconnectReason(""); | ||
| return peerInfo; | ||
| } | ||
|
|
||
| /** | ||
| * The protobuf conversion must map each peer flag from its own source field. A previous | ||
| * copy-and-paste defect populated needSyncFromPeer from isSyncFlag(); distinct values for | ||
| * syncFlag and needSyncFromPeer are required so that such a mismatch is detected. | ||
| */ | ||
| @Test | ||
| public void testPeerFlagMappingIsIndependent() { | ||
| NodeInfo nodeInfo = new NodeInfo(); | ||
| nodeInfo.setBlock(""); | ||
| nodeInfo.setSolidityBlock(""); | ||
| List<PeerInfo> peerList = new ArrayList<>(); | ||
| // syncFlag != needSyncFromPeer so the two fields cannot be confused | ||
| peerList.add(newPeerInfo(false, true, false)); | ||
| peerList.add(newPeerInfo(true, false, true)); | ||
| nodeInfo.setPeerList(peerList); | ||
| nodeInfo.setCheatWitnessInfoMap(new java.util.HashMap<>()); | ||
|
|
||
| Protocol.NodeInfo proto = nodeInfo.transferToProtoEntity(); | ||
|
|
||
| Assert.assertEquals(2, proto.getPeerInfoListCount()); | ||
|
|
||
| Protocol.NodeInfo.PeerInfo peer0 = proto.getPeerInfoList(0); | ||
| Assert.assertFalse(peer0.getSyncFlag()); | ||
| Assert.assertTrue(peer0.getNeedSyncFromPeer()); | ||
| Assert.assertFalse(peer0.getNeedSyncFromUs()); | ||
|
|
||
| Protocol.NodeInfo.PeerInfo peer1 = proto.getPeerInfoList(1); | ||
| Assert.assertTrue(peer1.getSyncFlag()); | ||
| Assert.assertFalse(peer1.getNeedSyncFromPeer()); | ||
| Assert.assertTrue(peer1.getNeedSyncFromUs()); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NIT] Test isolation backlog
MetricsUtilkeeps a staticMetricRegistry, whileBaseMethodTestresets the Spring context andArgsbut not that registry. Adding fixed amounts therefore does not guarantee that the four final cumulative counts remain distinct; prior activity in the same test JVM can make one of theassertNotEqualschecks fail even when the mapping is correct.Suggestion: derive marks from captured baseline counts so the resulting values are deterministic and distinct, or swap in and restore a test-scoped registry instead of relying on cumulative global totals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked how these meters are used in the test suite. Currently, no other tests write non-zero values to these four traffic meters. This test sets four distinct counts immediately after starting the application and reads the results before any actual network traffic can be generated. Therefore, although the
MetricRegistryis static, there is no historical data in the current test execution path that could cause these counts to collide, so the fixed sentinel values remain deterministic and distinct. Based on this, I do not think the test needs any additional changes at this time.