Skip to content

Commit

Permalink
feat(net): add codeVersion for HelloMessage (#5584)
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 authored Dec 27, 2023
1 parent c4d7635 commit 989115a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.tron.core.net.message.MessageTypes;
import org.tron.core.net.message.TronMessage;
import org.tron.p2p.discover.Node;
import org.tron.program.Version;
import org.tron.protos.Discover.Endpoint;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.HelloMessage.Builder;
Expand Down Expand Up @@ -61,6 +62,7 @@ public HelloMessage(Node from, long timestamp, ChainBaseManager chainBaseManager
builder.setNodeType(chainBaseManager.getNodeType().getType());
builder.setLowestBlockNum(chainBaseManager.isLiteNode()
? chainBaseManager.getLowestBlockNum() : 0);
builder.setCodeVersion(ByteString.copyFrom(Version.getVersion().getBytes()));

this.helloMessage = builder.build();
this.type = MessageTypes.P2P_HELLO.asByte();
Expand Down Expand Up @@ -127,17 +129,23 @@ public String toString() {
.append("lowestBlockNum: ").append(helloMessage.getLowestBlockNum()).append("\n");

ByteString address = helloMessage.getAddress();
if (address != null && !address.isEmpty()) {
if (!address.isEmpty()) {
builder.append("address:")
.append(StringUtil.encode58Check(address.toByteArray())).append("\n");
}

ByteString signature = helloMessage.getSignature();
if (signature != null && !signature.isEmpty()) {
if (!signature.isEmpty()) {
builder.append("signature:")
.append(signature.toByteArray().length).append("\n");
}

ByteString codeVersion = helloMessage.getCodeVersion();
if (!codeVersion.isEmpty()) {
builder.append("codeVersion:")
.append(new String(codeVersion.toByteArray())).append("\n");
}

return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.tron.p2p.connection.Channel;
import org.tron.p2p.discover.Node;
import org.tron.p2p.utils.NetUtil;
import org.tron.program.Version;
import org.tron.protos.Discover.Endpoint;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.HelloMessage.Builder;
Expand Down Expand Up @@ -99,6 +100,9 @@ public void testOkHelloMessage()
Node node = new Node(NetUtil.getNodeId(), a1.getAddress().getHostAddress(), null, a1.getPort());
HelloMessage helloMessage = new HelloMessage(node, System.currentTimeMillis(),
ChainBaseManager.getChainBaseManager());

Assert.assertEquals(Version.getVersion(),
new String(helloMessage.getHelloMessage().getCodeVersion().toByteArray()));
method.invoke(p2pEventHandler, peer, helloMessage.getSendBytes());

//dup hello message
Expand Down
1 change: 1 addition & 0 deletions protocol/src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ message HelloMessage {
bytes signature = 8;
int32 nodeType = 9;
int64 lowestBlockNum = 10;
bytes codeVersion = 11;
}

message InternalTransaction {
Expand Down

1 comment on commit 989115a

@Irajis
Copy link

@Irajis Irajis commented on 989115a Apr 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Please sign in to comment.