Skip to content

Commit

Permalink
chore: Get protocolMagic from node.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Jun 2, 2024
1 parent 17e5677 commit 24e80c5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ zip:
RUN echo "tag=${tag}" >> /app/yaci-devkit-${tag}/config/version
RUN echo "revision=${EARTHLY_GIT_SHORT_HASH}" >> /app/yaci-devkit-${tag}/config/version
COPY config/env /app/yaci-devkit-${tag}/config/
COPY config/node.properties /app/yaci-devkit-${tag}/config/

COPY bin/devkit.sh /app/yaci-devkit-${tag}/bin/

Expand Down
2 changes: 1 addition & 1 deletion applications/cli/config/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.config.import=optional:file:./node.properties
spring.config.import=optional:file:./config/node.properties

server.port=10000
#topup_addresses=addr_test1qqxnp3khzm7kcj9t23hskehat7428ghsenk0pfew4rqy5v9frnmht7uwrl073q4jvq20z82kh4rksyns540azhndqexqpvhgqr:20000,\
Expand Down
1 change: 1 addition & 0 deletions applications/cli/config/node.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protocolMagic=42
2 changes: 1 addition & 1 deletion applications/cli/docker/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.config.import=optional:file:./node.properties
spring.config.import=optional:file:/app/config/node.properties

cardano.cli.path=/app/cardano-bin
yaci.store.folder=/app/store
Expand Down
2 changes: 1 addition & 1 deletion applications/cli/docker/store-application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server.port=8080

store.cardano.host=localhost
store.cardano.port=3001
store.cardano.protocol-magic=42
#store.cardano.protocol-magic=42

store.cardano.n2c-node-socket-path=/clusters/nodes/default/node/node.sock
store.cardano.submit-api-url=http://localhost:8090/api/submit/tx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bloxbean.cardano.yaci.core.protocol.localstate.api.Era;
import com.bloxbean.cardano.yacicli.commands.common.Groups;
import com.bloxbean.cardano.yacicli.commands.common.RootLogService;
import com.bloxbean.cardano.yacicli.commands.localcluster.config.GenesisConfig;
import com.bloxbean.cardano.yacicli.commands.localcluster.events.ClusterDeleted;
import com.bloxbean.cardano.yacicli.commands.localcluster.events.ClusterStarted;
import com.bloxbean.cardano.yacicli.commands.localcluster.events.ClusterStopped;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class ClusterCommands {
private final ShellHelper shellHelper;
private final ApplicationEventPublisher publisher;
private final ClusterPortInfoHelper clusterUrlPrinter;
private final GenesisConfig genesisConfig;

@ShellMethod(value = "List devnet nodes. Use `list-nodes`. Deprecated: `list-clusters`", key = {"list-nodes", "list-clusters"})
public void listLocalClusters() {
Expand Down Expand Up @@ -116,7 +118,7 @@ else if (era.equalsIgnoreCase("conway"))
return;
}

long protocolMagic = 42; //always 42 for now.
long protocolMagic = genesisConfig.getProtocolMagic();

//stop any cluster if running
localClusterService.stopCluster(msg -> writeLn(msg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public boolean addPeer(String adminUrl, String nodeName, int portShift, boolean
downloadFolder.delete();

updateRunScripts(clusterFolder, nodeName, peerNodePort);
updatePoolGenScript(clusterFolder);
updatePoolGenScript(clusterFolder, clusterInfo);

//Generate pool keys
if (isBlockProducer) {
Expand Down Expand Up @@ -347,9 +347,10 @@ private void updateRunScripts(Path clusterFolder, String nodeName, int port) thr
}
}

private void updatePoolGenScript(Path destPath) throws IOException {
private void updatePoolGenScript(Path destPath, ClusterInfo clusterInfo) throws IOException {
Map<String, String> values = new HashMap<>();
values.put("BIN_FOLDER", clusterConfig.getCLIBinFolder());
values.put("protocolMagic", String.valueOf(clusterInfo.getProtocolMagic()));

//Update submit api script
Path genPoolKeyScript = destPath.resolve("gen-pool-keys.sh");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void handleClusterStarted(ClusterStarted clusterStarted) {
return;

Era era = clusterInfo.getEra();
Process process = startStoreApp(clusterStarted.getClusterName(), era);
Process process = startStoreApp(clusterInfo, era);
if (process != null)
processes.add(process);
// Process viewerProcess = startViewerApp(clusterStarted.getClusterName());
Expand All @@ -87,7 +87,7 @@ private static boolean portAvailabilityCheck(ClusterInfo clusterInfo, Consumer<S
return true;
}

private Process startStoreApp(String cluster, Era era) throws IOException, InterruptedException, ExecutionException, TimeoutException {
private Process startStoreApp(ClusterInfo clusterInfo, Era era) throws IOException, InterruptedException, ExecutionException, TimeoutException {
ProcessBuilder builder = new ProcessBuilder();
builder.directory(new File(clusterConfig.getYaciStoreBinPath()));

Expand All @@ -98,9 +98,9 @@ private Process startStoreApp(String cluster, Era era) throws IOException, Inter
}

if (OSUtil.getOperatingSystem() == OSUtil.OS.WINDOWS) {
builder.command("java", "-Dstore.cardano.n2c-era=" + era.name(), "-jar", clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store.jar");
builder.command("java", "-Dstore.cardano.n2c-era=" + era.name(), "-Dstore.cardano.protocol-magic=" + clusterInfo.getProtocolMagic(), "-jar", clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store.jar");
} else {
builder.command("java", "-Dstore.cardano.n2c-era=" + era.name(), "-jar", clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store.jar");
builder.command("java", "-Dstore.cardano.n2c-era=" + era.name(), "-Dstore.cardano.protocol-magic=" + clusterInfo.getProtocolMagic(), "-jar", clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store.jar");
}

Process process = builder.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ ${BIN_FOLDER}/cardano-cli address build \
--payment-verification-key-file payment.vkey \
--stake-verification-key-file stake.vkey \
--out-file payment.addr \
--testnet-magic 42
--testnet-magic ${protocolMagic}

${BIN_FOLDER}/cardano-cli stake-address build \
--stake-verification-key-file stake.vkey \
--out-file stake.addr \
--testnet-magic 42
--testnet-magic ${protocolMagic}

echo "Pool owner payment address: " $(cat payment.addr)
echo "Pool owner stake address: " $(cat stake.addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ${BIN_FOLDER}/cardano-cli stake-pool registration-certificate \
--pool-margin $3 \
--pool-reward-account-verification-key-file stake.vkey \
--pool-owner-stake-verification-key-file stake.vkey \
--testnet-magic 42 \
--testnet-magic ${protocolMagic} \
--metadata-url $4 \
--metadata-hash $5 \
--pool-relay-ipv4 $6 \
Expand Down

0 comments on commit 24e80c5

Please sign in to comment.