Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Component;
import org.tron.common.utils.ByteArray;
import org.tron.core.ChainBaseManager;
import org.tron.core.ChainBaseManager.NodeType;
import org.tron.core.config.args.Args;
import org.tron.core.net.TronNetService;
import org.tron.core.net.message.handshake.HelloMessage;
Expand Down Expand Up @@ -96,12 +97,21 @@ public void processHelloMessage(PeerConnection peer, HelloMessage msg) {
}

if (chainBaseManager.getSolidBlockId().getNum() >= msg.getSolidBlockId().getNum()
&& !chainBaseManager.containBlockInMainChain(msg.getSolidBlockId())) {
logger.info("Peer {} different solid block, peer->{}, me->{}",
peer.getInetSocketAddress(),
msg.getSolidBlockId().getString(),
chainBaseManager.getSolidBlockId().getString());
peer.disconnect(ReasonCode.FORKED);
&& !chainBaseManager.containBlockInMainChain(msg.getSolidBlockId())) {
if (chainBaseManager.getNodeType() == NodeType.FULL) {
Comment thread
317787106 marked this conversation as resolved.
Outdated
logger.info("Peer {} solid block is below than we and fork with me, peer->{}, me->{}",
peer.getInetSocketAddress(),
msg.getSolidBlockId().getString(),
chainBaseManager.getSolidBlockId().getString());
peer.disconnect(ReasonCode.FORKED);
} else {
logger.info("Peer {} solid block is below than we and light node doesn't contain the block,"
+ " it's unuseful, peer->{}, me->{}",
peer.getInetSocketAddress(),
msg.getSolidBlockId().getString(),
chainBaseManager.getSolidBlockId().getString());
peer.disconnect(ReasonCode.LIGHT_NODE_SYNC_FAIL);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.tron.common.utils.ReflectUtils;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.ChainBaseManager;
import org.tron.core.ChainBaseManager.NodeType;
import org.tron.core.Constant;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.config.DefaultConfig;
Expand Down Expand Up @@ -256,6 +257,15 @@ public void testLowAndGenesisBlockNum() throws NoSuchMethodException {
.setNumber(sid.getNum())
.build();
builder.setSolidBlockId(sBlockId);
ChainBaseManager.getChainBaseManager().setNodeType(NodeType.FULL);
try {
HelloMessage helloMessage = new HelloMessage(builder.build().toByteArray());
method.invoke(p2pEventHandler, peer, helloMessage.getSendBytes());
} catch (Exception e) {
Assert.fail();
}

ChainBaseManager.getChainBaseManager().setNodeType(NodeType.LITE);
try {
HelloMessage helloMessage = new HelloMessage(builder.build().toByteArray());
method.invoke(p2pEventHandler, peer, helloMessage.getSendBytes());
Expand Down