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

06302 - turn NodeId into a record containing a long #6370

Merged
merged 36 commits into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a0cd679
06302 - remove `EventCreationRule` from NodeId class declaration
edward-swirldslabs May 2, 2023
1d4c747
06302 - incremental commit.
edward-swirldslabs May 2, 2023
e2d54d5
06304 - NodeId is now a record
edward-swirldslabs May 2, 2023
f9d7598
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 3, 2023
bb931da
06302 - commit after merging develop into branch
edward-swirldslabs May 3, 2023
8f8c375
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 4, 2023
7cb884b
06302 - removing mirror node NodeId unit test, no longer relevant.
edward-swirldslabs May 4, 2023
f0507af
06302 - merge develop and spotless apply
edward-swirldslabs May 4, 2023
3e12c23
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 4, 2023
81b5e02
06302 - Adding NodeId change used in the future.
edward-swirldslabs May 4, 2023
eec8eaa
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 4, 2023
9200f86
06302 - merge with accepting delete left husk of the file.
edward-swirldslabs May 4, 2023
fdc444b
06302 - fixing unit tests
edward-swirldslabs May 4, 2023
1a6c41c
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 4, 2023
65a08c2
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 4, 2023
64054e6
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 5, 2023
09cb931
06302 - Adding -1L NodeId as invalid marker.
edward-swirldslabs May 5, 2023
7fb933b
06302 - changing equals to matches on long values
edward-swirldslabs May 5, 2023
13b2fc4
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 5, 2023
7b1a617
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 8, 2023
92f3b29
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 8, 2023
d43a50e
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 8, 2023
63defad
06302 - updating names of FIRST_NODE_ID
edward-swirldslabs May 8, 2023
7fd0ca2
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 8, 2023
d03ae68
06302 - removing `matches(long)` method from NodeId.
edward-swirldslabs May 8, 2023
974a87b
06302 - removing use of negative node id in TopologyTest.java
edward-swirldslabs May 8, 2023
15e75d6
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 9, 2023
e82e2ef
06302 - merge conflicts with develop
edward-swirldslabs May 9, 2023
70e9f06
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 11, 2023
9ca8280
06302 - code review findings, removing use of concurrent hashmap.
edward-swirldslabs May 11, 2023
fd6e388
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 11, 2023
ccd173b
06302 - code review finding, removing create method from NodeId.java
edward-swirldslabs May 11, 2023
618a989
06302 - removing unused variable.
edward-swirldslabs May 11, 2023
2240a48
Merge branch 'develop' into 06302-Turn-NodeId-into-record-of-a-long
edward-swirldslabs May 12, 2023
7e6cb76
06302 - processing merge conflicts
edward-swirldslabs May 12, 2023
d8fa9c6
06302 - spotlessApply
edward-swirldslabs May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(NodeId.FIRST_NODE_ID)) {
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(NodeId.FIRST_NODE_ID)) {

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 Down Expand Up @@ -170,7 +171,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
&& platform.getSelfId().equals(NodeId.FIRST_NODE_ID)
edward-swirldslabs marked this conversation as resolved.
Show resolved Hide resolved
&& 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(NodeId.FIRST_NODE_ID);
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(NodeId.FIRST_NODE_ID);
}

@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(NodeId.create(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 NodeId.create(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
Expand Up @@ -78,7 +78,7 @@ public void update(final Snapshot snapshot, final NodeId nodeId) {
counter.inc(newValue - oldValue);
} else {
throwArgNull(nodeId, "nodeId");
final Counter.Child child = counter.labels(Long.toString(nodeId.getId()));
final Counter.Child child = counter.labels(Long.toString(nodeId.id()));
final double oldValue = child.get();
child.inc(newValue - oldValue);
}
Expand Down