Skip to content

Commit

Permalink
06302 - turn NodeId into a record containing a long (#6370)
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Wertz <edward@swirldslabs.com>
  • Loading branch information
edward-swirldslabs committed May 12, 2023
1 parent 04446a4 commit 074dd7c
Show file tree
Hide file tree
Showing 114 changed files with 308 additions and 437 deletions.
Expand Up @@ -143,7 +143,7 @@ public void init(final Platform platform, final NodeId id) {
this.platform = platform;
this.selfId = id;
this.console = createConsole(platform, true); // create the window, make it visible
SwirldsGui.setAbout(platform.getSelfId().getId(), "Cryptocurrency and stock market demo v. 1.0\n");
SwirldsGui.setAbout(platform.getSelfId().id(), "Cryptocurrency and stock market demo v. 1.0\n");
this.console.addKeyListener(keyListener);
}

Expand Down
Expand Up @@ -244,7 +244,7 @@ public void paintComponent(final Graphics g) {
print(g, "%5.3f sec, create to consensus", createCons);
print(g, "%5.3f sec, receive to consensus", recCons);
final Address address =
platform.getAddressBook().getAddress(platform.getSelfId().getId());
platform.getAddressBook().getAddress(platform.getSelfId().id());
print(g, "Internal: " + Network.getInternalIPAddress() + " : " + address.getPortInternalIpv4(), 0);

final ExternalIpAddress ipAddress = Network.getExternalIpAddress();
Expand Down Expand Up @@ -392,11 +392,11 @@ private void calcNames() {
@Override
public void init(final Platform platform, final NodeId id) {
this.platform = platform;
this.selfId = id.getId();
this.selfId = id.id();
final String[] parameters = ((PlatformWithDeprecatedMethods) platform).getParameters();

SwirldsGui.setAbout(
platform.getSelfId().getId(),
platform.getSelfId().id(),
"Hashgraph Demo v. 1.1\n" + "\n"
+ "trans/sec = # transactions added to the hashgraph per second\n"
+ "events/sec = # events added to the hashgraph per second\n"
Expand Down
Expand Up @@ -78,9 +78,9 @@ public void init(final Platform platform, final NodeId id) {
platform.getNotificationEngine().register(PlatformStatusChangeListener.class, this::platformStatusChange);

this.platform = (SwirldsPlatform) platform;
this.selfId = id.getId();
this.selfId = id.id();
this.console = createConsole(platform, true); // create the window, make it visible
SwirldsGui.setAbout(platform.getSelfId().getId(), "Hello Swirld v. 1.0\n");
SwirldsGui.setAbout(platform.getSelfId().id(), "Hello Swirld v. 1.0\n");
this.platform.setSleepAfterSync(sleepPeriod);
}

Expand Down
Expand Up @@ -210,7 +210,7 @@ public void init(final Platform platform, final NodeId id) {

long syncDelay;
this.platform = platform;
selfId = id.getId();
selfId = id.id();
// parse the config.txt parameters, and allow optional _ as in 1_000_000
final String[] parameters = ((PlatformWithDeprecatedMethods) platform).getParameters();
headless = (parameters[0].equals("1"));
Expand All @@ -227,7 +227,7 @@ public void init(final Platform platform, final NodeId id) {
console = createConsole(platform, true);
}
SwirldsGui.setAbout(
platform.getSelfId().getId(),
platform.getSelfId().id(),
"Stats Demo v. 1.2\nThis writes statistics to a log file,"
+ " such as the number of transactions per second.");
((PlatformWithDeprecatedMethods) platform).setSleepAfterSync(syncDelay);
Expand Down
Expand Up @@ -159,7 +159,7 @@ public void init(
parseArguments(((PlatformWithDeprecatedMethods) platform).getParameters());
}

this.selfId = platform.getSelfId().getId();
this.selfId = platform.getSelfId().id();
}

/**
Expand Down
Expand Up @@ -141,7 +141,7 @@ public void init(
parseArguments(((PlatformWithDeprecatedMethods) platform).getParameters());
}

this.selfId = platform.getSelfId().getId();
this.selfId = platform.getSelfId().id();
}

/**
Expand Down
Expand Up @@ -70,11 +70,11 @@ public void init(final Platform platform, final NodeId selfId) {

final String[] parameters = ((PlatformWithDeprecatedMethods) platform).getParameters();
logger.info(MARKER, "Parsing arguments {}", (Object) parameters);
seed = Long.parseLong(parameters[0]) + selfId.getId();
seed = Long.parseLong(parameters[0]) + selfId.id();
maximumTransactionsPerNode = Integer.parseInt(parameters[1]);

generator = new TransactionGenerator(seed);
SwirldsGui.setAbout(platform.getSelfId().getId(), "MigrationTestingApp");
SwirldsGui.setAbout(platform.getSelfId().id(), "MigrationTestingApp");

// Initialize application statistics
initAppStats();
Expand Down
Expand Up @@ -221,7 +221,7 @@ private void genesisInit(final Platform platform) {
.preferDiskBasedIndexes(false);

setVirtualMap(new VirtualMap<>("virtualMap", jasperDbBuilder));
selfId = platform.getSelfId().getId();
selfId = platform.getSelfId().id();
}

/**
Expand All @@ -242,7 +242,7 @@ public void init(
if (virtualMap != null) {
logger.info(MARKER, "VirtualMap initialized with {} values", virtualMap.size());
}
selfId = platform.getSelfId().getId();
selfId = platform.getSelfId().id();

if (trigger == InitTrigger.GENESIS) {
logger.error(MARKER, "InitTrigger was {} when expecting RESTART or RECONNECT", trigger);
Expand Down
Expand Up @@ -66,7 +66,7 @@ public class AppClient extends Thread {

transactionPool = new TransactionPool(
platform,
platform.getSelfId().getId(),
platform.getSelfId().id(),
payloadConfig,
myName,
currentConfig.getFcmConfig(),
Expand Down
Expand Up @@ -537,7 +537,7 @@ public void init(Platform platform, NodeId id) {
platform.getNotificationEngine().register(PlatformStatusChangeListener.class, this::platformStatusChange);
registerReconnectCompleteListener();

SwirldsGui.setAbout(selfId.getId(), "Platform Testing Demo");
SwirldsGui.setAbout(selfId.id(), "Platform Testing Demo");
try {
final PlatformTestingToolState state = ((PlatformWithDeprecatedMethods) platform).getState();

Expand Down Expand Up @@ -608,8 +608,7 @@ public void init(Platform platform, NodeId id) {
final Pair<Long, Long> entitiesFirstIds = extractFirstIdForEntitiesFromSavedState(platform);
virtualMerkleConfig.setFirstAccountId(entitiesFirstIds.getKey());
virtualMerkleConfig.setFirstSmartContractId(entitiesFirstIds.getValue());
VirtualMerkleStateInitializer.initStateChildren(
platform, selfId.getId(), virtualMerkleConfig);
VirtualMerkleStateInitializer.initStateChildren(platform, selfId.id(), virtualMerkleConfig);
}
final Metrics metrics = platform.getContext().getMetrics();
if (state.getVirtualMap() != null) {
Expand All @@ -629,7 +628,7 @@ public void init(Platform platform, NodeId id) {
// through calls to the setFirstAccountId and setFirstSmartContractId methods.
transactionPool = new TransactionPool(
platform,
platform.getSelfId().getId(),
platform.getSelfId().id(),
payloadConfig,
myName,
currentConfig.getFcmConfig(),
Expand Down Expand Up @@ -710,7 +709,7 @@ private void initBasedOnPayloadCfgSimple(final PayloadCfgSimple pConfig) {
}

private void initializeAppClient(final String[] pars, final ObjectMapper objectMapper) throws IOException {
if (pars.length < 2 || !selfId.equalsMain(0)) {
if (pars.length < 2 || !selfId.equals(new NodeId(0L))) {
return;
}

Expand All @@ -720,9 +719,9 @@ private void initializeAppClient(final String[] pars, final ObjectMapper objectM
for (int k = 0; k < CLIENT_AMOUNT; k++) {
appClient[k] = new AppClient(
this.platform,
this.selfId.getId(),
this.selfId.id(),
clientConfig,
platform.getAddressBook().getAddress(selfId.getId()).getNickname());
platform.getAddressBook().getAddress(selfId.id()).getNickname());
appClient[k].start();
}
}
Expand Down Expand Up @@ -782,7 +781,7 @@ public void run() {

// if single mode only node 0 can submit transactions
// if not single mode anyone can submit transactions
if (!submitConfig.isSingleNodeSubmit() || selfId.equalsMain(0)) {
if (!submitConfig.isSingleNodeSubmit() || selfId.equals(new NodeId(0L))) {

if (submitConfig.isSubmitInTurn()) {
// Delay the start of transactions by interval multiply by node id
Expand Down Expand Up @@ -952,7 +951,7 @@ private void registerReconnectCompleteListener() {
final PlatformTestingToolState state = ((PlatformWithDeprecatedMethods) platform).getState();
state.initControlStructures(this::handleMessageQuorum);
SyntheticBottleneckConfig.getActiveConfig()
.registerReconnect(platform.getSelfId().getId());
.registerReconnect(platform.getSelfId().id());
} finally {
((PlatformWithDeprecatedMethods) platform).releaseState();
}
Expand Down Expand Up @@ -1088,7 +1087,7 @@ private void handleEnterValidation(final Instant consensusTime) {
final PlatformTestingToolState state = ((PlatformWithDeprecatedMethods) platform).getState();

final String expectedMapFile =
createExpectedMapName(platform.getSelfId().getId(), consensusTime);
createExpectedMapName(platform.getSelfId().id(), consensusTime);
logger.info(
LOGM_DEMO_QUORUM,
"Achieved Quorum on ENTER_VALIDATION transaction [ expectedMapFile = {}, consensusTime = {} ]",
Expand Down Expand Up @@ -1121,7 +1120,7 @@ private void handleEnterValidation(final Instant consensusTime) {
};

new ThreadConfiguration(getStaticThreadManager())
.setNodeId(platform.getSelfId().getId())
.setNodeId(platform.getSelfId().id())
.setComponent(PTT_COMPONENT)
.setThreadName(ENTER_VALIDATION_THREAD_NAME)
.setRunnable(fn)
Expand All @@ -1139,7 +1138,7 @@ private void handleExitValidation(final Instant consensusTime) {

// the first node sends a freeze transaction after all transaction finish
// This is for guaranteeing that all nodes generated same amount of signed states
if (platform.getSelfId().getId() == 0) {
if (platform.getSelfId().id() == 0) {
sendFreezeTransaction();
}

Expand All @@ -1152,7 +1151,7 @@ private void handleExitValidation(final Instant consensusTime) {
};

new ThreadConfiguration(getStaticThreadManager())
.setNodeId(platform.getSelfId().getId())
.setNodeId(platform.getSelfId().id())
.setComponent(PTT_COMPONENT)
.setThreadName(EXIT_VALIDATION_THREAD_NAME)
.setRunnable(fn)
Expand Down
Expand Up @@ -592,7 +592,7 @@ public long getLastPurgeTimestamp() {
}

public synchronized void setPayloadConfig(final FCMConfig fcmConfig) {
expectedFCMFamily.setNodeId(platform.getSelfId().getId());
expectedFCMFamily.setNodeId(platform.getSelfId().id());
expectedFCMFamily.setFcmConfig(fcmConfig);
expectedFCMFamily.setWeightedNodeNum(platform.getAddressBook().getNumberWithWeight());

Expand All @@ -615,7 +615,7 @@ public void initChildren() {

void initControlStructures(final Action<Long, ControlAction> action) {
this.controlQuorum = new QuorumTriggeredAction<>(
() -> platform.getSelfId().getId(),
() -> platform.getSelfId().id(),
platform.getAddressBook()::getSize,
platform.getAddressBook()::getNumberWithWeight,
action);
Expand Down Expand Up @@ -698,7 +698,7 @@ private void delay() {
}
}
SyntheticBottleneckConfig.getActiveConfig()
.throttleIfNeeded(platform.getSelfId().getId());
.throttleIfNeeded(platform.getSelfId().id());
}

/**
Expand Down Expand Up @@ -816,7 +816,7 @@ private void handleFCMTransaction(
serialize(
expectedFCMFamily.getExpectedMap(),
new File(STORAGE_DIRECTORY),
createExpectedMapName(platform.getSelfId().getId(), timestamp),
createExpectedMapName(platform.getSelfId().id(), timestamp),
false);
TransactionSubmitter.setForcePauseCanSubmitMore(new AtomicBoolean(false));
logger.info(LOGM_DEMO_INFO, "handling SAVE_EXPECTED_MAP");
Expand Down Expand Up @@ -1068,7 +1068,7 @@ private void handleConsensusTransaction(
TESTING_EXCEPTIONS_ACCEPTABLE_RECONNECT.getMarker(),
"handleConsensusRound Interrupted [ nodeId = {}, round = {} ]. "
+ "This should happen only during a reconnect",
platform.getSelfId().getId(),
platform.getSelfId().id(),
roundNum);
Thread.currentThread().interrupt();
} catch (final ExecutionException e) {
Expand Down Expand Up @@ -1234,7 +1234,7 @@ public void init(
setConfig(new PayloadCfgSimple());
}

expectedFCMFamily.setNodeId(platform.getSelfId().getId());
expectedFCMFamily.setNodeId(platform.getSelfId().id());
expectedFCMFamily.setWeightedNodeNum(platform.getAddressBook().getNumberWithWeight());

// initialize data structures used for FCQueue transaction records expiration
Expand Down
Expand Up @@ -23,6 +23,7 @@

import com.google.protobuf.ByteString;
import com.swirlds.common.FastCopyable;
import com.swirlds.common.system.NodeId;
import com.swirlds.common.system.Platform;
import com.swirlds.common.test.crypto.ECDSASigningProvider;
import com.swirlds.common.test.crypto.ED25519SigningProvider;
Expand All @@ -49,6 +50,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -170,7 +172,9 @@ public TransactionPool(
}

/** If the startFreezeAfterMin is 0, we don't send freeze transaction */
if (freezeConfig != null && platform.getSelfId().equalsMain(0) && freezeConfig.getStartFreezeAfterMin() > 0) {
if (freezeConfig != null
&& Objects.equals(platform.getSelfId(), new NodeId(0L))
&& freezeConfig.getStartFreezeAfterMin() > 0) {
this.freezeConfig = freezeConfig;
this.needToSubmitFreezeTx = true;
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ public static void setUp() throws ConstructableRegistryException {
mapKey = new MapKey(0, 0, random.nextLong());
state = Mockito.spy(PlatformTestingToolState.class);
Platform platform = Mockito.spy(PlatformWithDeprecatedMethods.class);
when(platform.getSelfId()).thenReturn(NodeId.createMain(0));
when(platform.getSelfId()).thenReturn(new NodeId(0L));
AddressBook addressBook = Mockito.spy(AddressBook.class);
when(addressBook.getNumberWithWeight()).thenReturn(4);
when(platform.getAddressBook()).thenReturn(addressBook);
Expand Down
Expand Up @@ -151,7 +151,7 @@ class ExpectedFCMFamilyTest {

static {
platform = Mockito.mock(Platform.class);
Mockito.when(platform.getSelfId()).thenReturn(NodeId.createMain(0));
Mockito.when(platform.getSelfId()).thenReturn(new NodeId(0L));
}

@BeforeAll
Expand Down
Expand Up @@ -72,7 +72,7 @@ public class TransactionPoolTest {

static {
platform = Mockito.mock(Platform.class);
Mockito.when(platform.getSelfId()).thenReturn(NodeId.createMain(myID));
Mockito.when(platform.getSelfId()).thenReturn(new NodeId(myID));
System.arraycopy(payload, 0, payloadWithSig, 0, payload.length);
expectedFCMFamily = new DummyExpectedFCMFamily(myID);
fCMFamily = new FCMFamily(true);
Expand Down
Expand Up @@ -160,7 +160,7 @@ public void init(final Platform platform, final NodeId id) {

final long syncDelay;
this.platform = platform;
selfId = id.getId();
selfId = id.id();
// parse the config.txt parameters, and allow optional _ as in 1_000_000
final String[] parameters = ((PlatformWithDeprecatedMethods) platform).getParameters();
headless = (parameters[0].equals("1"));
Expand All @@ -184,13 +184,13 @@ public void init(final Platform platform, final NodeId id) {
transPerEventMax = 1024;
}
SwirldsGui.setAbout(
platform.getSelfId().getId(),
platform.getSelfId().id(),
"Stats Signing Demo v. 1.3\nThis writes statistics to a log file,"
+ " such as the number of transactions per second.");
((PlatformWithDeprecatedMethods) platform).setSleepAfterSync(syncDelay);

transactionPool = new TransactionPool(
platform.getSelfId().getId(),
platform.getSelfId().id(),
signedTransPoolSize,
bytesPerTrans,
true,
Expand All @@ -205,7 +205,7 @@ public void init(final Platform platform, final NodeId id) {
public void run() {
final Thread shutdownHook = new ThreadConfiguration(getStaticThreadManager())
.setDaemon(false)
.setNodeId(platform.getSelfId().getId())
.setNodeId(platform.getSelfId().id())
.setComponent("app")
.setThreadName("demo_log_time_pulse")
.setRunnable(() -> {
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class NoOpMetrics implements Metrics {

@Override
public NodeId getNodeId() {
return NodeId.createMain(42L);
return new NodeId(42L);
}

@Override
Expand Down
Expand Up @@ -109,7 +109,7 @@ public LegacyCsvWriter(final NodeId selfId, final Path folderPath, final Metrics
throwArgNull(folderPath, "folderPath");
this.metricsConfig = throwArgNull(metricsConfig, "metricsConfig");

final String fileName = String.format("%s%d.csv", metricsConfig.csvFileName(), selfId.getId());
final String fileName = String.format("%s%d.csv", metricsConfig.csvFileName(), selfId.id());
this.csvFilePath = folderPath.resolve(fileName);
}

Expand Down
Expand Up @@ -77,7 +77,7 @@ public void update(final Snapshot snapshot, final NodeId nodeId) {
gauge.set(newValue);
} else {
throwArgNull(nodeId, "nodeId");
final Gauge.Child child = gauge.labels(Long.toString(nodeId.getId()));
final Gauge.Child child = gauge.labels(Long.toString(nodeId.id()));
child.set(newValue);
}
}
Expand Down

0 comments on commit 074dd7c

Please sign in to comment.