Skip to content
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

feat(net): optimize network logs #4977

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ private void check(PeerConnection peer, BlockMessage msg) throws P2pException {
Item item = new Item(msg.getBlockId(), InventoryType.BLOCK);
if (!peer.getSyncBlockRequested().containsKey(msg.getBlockId()) && !peer.getAdvInvRequest()
.containsKey(item)) {
logger.error("Receive bad block {} from peer {}, with no request",
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "no request");
}
BlockCapsule blockCapsule = msg.getBlockCapsule();
if (blockCapsule.getInstance().getSerializedSize() > maxBlockSize) {
logger.error("Receive bad block {} from peer {}, block size over limit",
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block size over limit");
}
long gap = blockCapsule.getTimeStamp() - System.currentTimeMillis();
if (gap >= BLOCK_PRODUCED_INTERVAL) {
logger.error("Receive bad block {} from peer {}, block time error",
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block time error");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ public void statusCheck() {
if (!isDisconnected) {
isDisconnected = peer.getAdvInvRequest().values().stream()
.anyMatch(time -> time < now - NetConstants.ADV_TIME_OUT);
if (isDisconnected) {
logger.warn("Peer {} get avd message timeout", peer.getInetAddress());
}
}

if (!isDisconnected) {
isDisconnected = peer.getSyncBlockRequested().values().stream()
.anyMatch(time -> time < now - NetConstants.SYNC_TIME_OUT);
if (isDisconnected) {
logger.warn("Peer {} get sync message timeout", peer.getInetAddress());
}
}

if (isDisconnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void init() {
long lastSendTime = p.getChannel().getLastSendTime();
if (p.getChannel().waitForPong) {
if (now - pingSent > PING_TIMEOUT) {
logger.warn("Peer {} receive pong timeout", p.getInetSocketAddress());
p.disconnect(Protocol.ReasonCode.TIME_OUT);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
Expand All @@ -18,6 +20,7 @@
import org.tron.core.net.message.adv.BlockMessage;
import org.tron.core.net.peer.Item;
import org.tron.core.net.peer.PeerConnection;
import org.tron.p2p.connection.Channel;
import org.tron.protos.Protocol.Inventory.InventoryType;
import org.tron.protos.Protocol.Transaction;

Expand All @@ -31,12 +34,18 @@ public class BlockMsgHandlerTest {
* init context.
*/
@Before
public void init() {
public void init() throws Exception {
Args.setParam(new String[]{"--output-directory", "output-directory", "--debug"},
Constant.TEST_CONF);
context = new TronApplicationContext(DefaultConfig.class);
handler = context.getBean(BlockMsgHandler.class);
peer = context.getBean(PeerConnection.class);
Channel c1 = new Channel();
InetSocketAddress a1 = new InetSocketAddress("100.1.1.1", 100);
Field field = c1.getClass().getDeclaredField("inetAddress");
field.setAccessible(true);
field.set(c1, a1.getAddress());
peer.setChannel(c1);
}

@Test
Expand Down