Skip to content

Commit 9d99aca

Browse files
Little-Peonyclaude
andcommitted
refactor(framework): promote relayNodes to instance field in PeerConnection
Extract relayNodes from a local variable inside setChannel() to a lazy- initialized instance field. setChannel() now only fetches from Args when the field is still null, so tests can pre-inject a custom list via reflection before calling setChannel(). This restores testability of PeerManagerTest without touching the test itself. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f0dfdea commit 9d99aca

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

framework/src/main/java/org/tron/core/net/peer/PeerConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@ public class PeerConnection {
161161
private volatile boolean needSyncFromUs = true;
162162
@Getter
163163
private P2pRateLimiter p2pRateLimiter = new P2pRateLimiter();
164+
@Getter
165+
private List<InetSocketAddress> relayNodes;
164166

165167
public void setChannel(Channel channel) {
166168
this.channel = channel;
167-
List<InetSocketAddress> relayNodes = Args.getInstance().getFastForwardNodes();
169+
if (this.relayNodes == null) {
170+
this.relayNodes = Args.getInstance().getFastForwardNodes();
171+
}
168172
if (relayNodes != null
169173
&& relayNodes.stream().anyMatch(n -> n.getAddress().equals(channel.getInetAddress()))) {
170174
this.isRelayPeer = true;

0 commit comments

Comments
 (0)