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

Changed diffusion mode to initiatorOnlyDiffusionMode (true) #42

Merged
merged 1 commit into from
Jan 25, 2024
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 @@ -8,18 +8,21 @@
@EqualsAndHashCode
@ToString
public class N2NVersionData extends VersionData {
private Boolean initiatorAndResponderDiffusionMode;
public static final boolean InitiatorOnlyDiffusionMode = true;
public static final boolean InitiatorAndResponderDiffusionMode = false;

private Boolean diffusionMode;
private Integer peerSharing = 0;
private Boolean query = Boolean.FALSE;

public N2NVersionData(long networkMagic, Boolean initiatorAndResponderDiffusionMode) {
public N2NVersionData(long networkMagic, Boolean diffusionMode) {
super(networkMagic);
this.initiatorAndResponderDiffusionMode = initiatorAndResponderDiffusionMode;
this.diffusionMode = diffusionMode;
}

public N2NVersionData(long networkMagic, Boolean initiatorAndResponderDiffusionMode, Integer peerSharing, Boolean query) {
public N2NVersionData(long networkMagic, Boolean diffusionMode, Integer peerSharing, Boolean query) {
super(networkMagic);
this.initiatorAndResponderDiffusionMode = initiatorAndResponderDiffusionMode;
this.diffusionMode = diffusionMode;
this.peerSharing = peerSharing;
this.query = query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DataItem serializeDI(VersionTable versionTable) {
N2NVersionData versionData = (N2NVersionData) entry.getValue();
Array versionDataArray = new Array();
versionDataArray.add(new UnsignedInteger(versionData.getNetworkMagic()));
versionDataArray.add(versionData.getInitiatorAndResponderDiffusionMode() ? SimpleValue.TRUE : SimpleValue.FALSE);
versionDataArray.add(versionData.getDiffusionMode() ? SimpleValue.TRUE : SimpleValue.FALSE);

//TODO -- check with existing node versions
if (entry.getKey() >= N2NVersionTableConstant.PROTOCOL_V11) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.HashMap;
import java.util.Map;

import static com.bloxbean.cardano.yaci.core.protocol.handshake.messages.N2NVersionData.InitiatorOnlyDiffusionMode;

public class N2NVersionTableConstant {
public final static long PROTOCOL_V4 = 4;
public final static long PROTOCOL_V5 = 5;
Expand All @@ -20,7 +22,7 @@ public class N2NVersionTableConstant {
public final static long PROTOCOL_V13 = 13;

public static VersionTable v4AndAbove(long networkMagic) {
N2NVersionData versionData = new N2NVersionData(networkMagic, false);
N2NVersionData versionData = new N2NVersionData(networkMagic, InitiatorOnlyDiffusionMode);

Map<Long, VersionData> versionTableMap = new HashMap<>();
versionTableMap.put(PROTOCOL_V4, versionData);
Expand All @@ -38,11 +40,11 @@ public static VersionTable v4AndAbove(long networkMagic) {
}

public static VersionTable v11AndAbove(long networkMagic) {
return v11AndAbove(networkMagic, false, 0, false);
return v11AndAbove(networkMagic, InitiatorOnlyDiffusionMode, 0, false);
}

public static VersionTable v11AndAbove(long networkMagic, boolean initiatorAndResponderDiffusionMode, int peerSharing, boolean query) {
N2NVersionData versionData = new N2NVersionData(networkMagic, initiatorAndResponderDiffusionMode, peerSharing, query);
public static VersionTable v11AndAbove(long networkMagic, boolean diffusionMode, int peerSharing, boolean query) {
N2NVersionData versionData = new N2NVersionData(networkMagic, diffusionMode, peerSharing, query);

Map<Long, VersionData> versionTableMap = new HashMap<>();
versionTableMap.put(PROTOCOL_V11, versionData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import com.bloxbean.cardano.yaci.core.protocol.handshake.messages.VersionTable;
import com.bloxbean.cardano.yaci.core.protocol.handshake.util.N2NVersionTableConstant;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -51,6 +53,37 @@ public void fetchBlock() throws InterruptedException {
assertThat(blocks.get(0).getHeader().getHeaderBody().getBlockNumber()).isEqualTo(287622);
}

@Test
@Disabled
public void fetchBlock_tillTip() throws InterruptedException {
VersionTable versionTable = N2NVersionTableConstant.v4AndAbove(protocolMagic);
BlockFetcher blockFetcher = new BlockFetcher(node, nodePort, versionTable);

AtomicInteger count = new AtomicInteger(0);
blockFetcher.addBlockFetchListener(new BlockfetchAgentListener() {
@Override
public void byronBlockFound(ByronMainBlock byronBlock) {
if (count.incrementAndGet() % 1000 == 0)
System.out.println("Byron Block >> " + byronBlock.getHeader().getConsensusData().getDifficulty());
count.incrementAndGet();
}

@Override
public void blockFound(Block block) {
if (count.incrementAndGet() % 1000 == 0)
System.out.println("Block >> " + block.getHeader().getHeaderBody().getBlockNumber());
}
});
blockFetcher.start();

Point from = new Point(2, "1d031daf47281f69cd95ab929c269fd26b1434a56a5bbbd65b7afe85ef96b233");
Point to = new Point(50468813, "2fb2554a9fec38ce4b8121c001087f867b1bd19cda11e93dc5475dc253baf0e9");
blockFetcher.fetch(from, to);

while (true)
Thread.sleep(1000);
}

@Test
public void fetchBlockByron() throws InterruptedException {
BlockFetcher blockFetcher = new BlockFetcher(node, nodePort, protocolMagic);
Expand Down
Loading