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

optimize SR’s production order when multi masters exist #4630

Merged
merged 2 commits into from
Sep 13, 2022
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 @@ -90,12 +90,12 @@ public void receiveBlock(BlockCapsule blockCapsule) {
return;
}

if (dupBlockCount.get() == 0) {
dupBlockCount.set(new Random().nextInt(10));
} else {
dupBlockCount.set(10);
if (null != currentBlockId
&& currentBlockId.toString().compareTo(blockCapsule.getBlockId().toString()) > 0) {
return;
}

dupBlockCount.set(1);
dupBlockTime.set(System.currentTimeMillis());

logger.warn("Dup block produced: {}", blockCapsule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.tron.common.overlay.discover.node.Node;
import org.tron.common.utils.ByteArray;

public class NodeEntryTest {

Expand All @@ -23,4 +24,46 @@ public void test() throws InterruptedException {
Assert.assertTrue(isDif);
}

@Test
public void testDistance() {
byte[] randomId = Node.getNodeId();
String hexRandomIdStr = ByteArray.toHexString(randomId);
Assert.assertEquals(128, hexRandomIdStr.length());

byte[] nodeId1 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000");
byte[] nodeId2 = ByteArray.fromHexString(
"a000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000");
Assert.assertEquals(256, NodeEntry.distance(nodeId1, nodeId2));

byte[] nodeId3 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000001"
+ "0000000000000000000000000000000000000000000000000000000000000000");
Assert.assertEquals(1, NodeEntry.distance(nodeId1, nodeId3));

byte[] nodeId4 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000000"
+ "8000000000000000000000000000000000000000000000000000000000000000");
Assert.assertEquals(0, NodeEntry.distance(nodeId1, nodeId4)); // => 0

byte[] nodeId5 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000000"
+ "4000000000000000000000000000000000000000000000000000000000000000");
Assert.assertEquals(-1, NodeEntry.distance(nodeId1, nodeId5)); // => 0

byte[] nodeId6 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000000"
+ "2000000000000000000000000000000000000000000000000000000000000000");
Assert.assertEquals(-2, NodeEntry.distance(nodeId1, nodeId6)); // => 0

byte[] nodeId7 = ByteArray.fromHexString(
"0000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000001");
Assert.assertEquals(-255, NodeEntry.distance(nodeId1, nodeId7)); // => 0

Assert.assertEquals(-256, NodeEntry.distance(nodeId1, nodeId1)); // => 0
}

}